Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tx expiration #1123

Merged
merged 58 commits into from
Apr 13, 2023
Merged

Tx expiration #1123

merged 58 commits into from
Apr 13, 2023

Conversation

grarco
Copy link
Contributor

@grarco grarco commented Feb 7, 2023

Closes #1009

Based on #1106

Adds an optional expiration field to struct Tx to prevent transactions from being applied indefinitely.

  • Adds expiration field to struct Tx
  • Adds mempool_validate check against last committed block time
  • Adds process_proposal check against the proposed block time or, if missing, the last committed block time
  • Adds prepare_proposal check against the proposed block time (if missing accept txs as assumed to have been checked by mempool_validate)
  • Unit tests
  • Updates client to allow for a new expiration optional arg

@grarco
Copy link
Contributor Author

grarco commented Feb 7, 2023

pls update wasm

grarco added a commit that referenced this pull request Feb 7, 2023
grarco added a commit that referenced this pull request Feb 8, 2023
@grarco grarco mentioned this pull request Feb 8, 2023
3 tasks
@grarco grarco marked this pull request as ready for review February 8, 2023 14:39
@grarco grarco requested a review from tzemanovic March 1, 2023 18:38
tzemanovic
tzemanovic previously approved these changes Mar 7, 2023
@batconjurer batconjurer self-requested a review March 8, 2023 08:49
@@ -129,6 +132,11 @@ pub enum ErrorCodes {
InvalidOrder = 4,
ExtraTxs = 5,
Undecryptable = 6,
ReplayTx = 7,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunately not documented in main, but the idea of these numbers is that past a certain threshold, we reject the block. In this branch, those are error codes >=4. However, we can't reject an entire block if we get the InvalidDecryptedChainId error since we have to include all decrypted txs in order. So its number should be lowered below the critical threshold

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the same is also true of ExpiredDecryptedTx

status: if tx_results.iter().any(|res| res.code > 3) {
ProposalStatus::Reject as i32
} else {
status: if tx_results.iter().all(|res| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah here. If the ordering of the errors is fixed, we just need to change the 3 to a 5 in the old code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing something, what do you mean when you say "in the old code"?

Copy link
Member

@batconjurer batconjurer Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: if tx_results.iter().any(|res| res.code > 3) {
                ProposalStatus::Reject as i32
 } else {
            ```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I see what you mean. I've changed that code to use the enum variants because I was struggling to keep track of the error codes and thought that using the variants was more readable. Would you prefer to revert to using the codes instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on it heaving in eth-bridge-integration, so I thinks it's easier for you to make this change than us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also document it a lot better and add helper functions, so it's not such a secret design choice anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, in this PR I've also changed process_proposal to reject the block in more cases: in particular to reject a block even in case of an InvalidTx or InvalidSig which we were not doing before. Does this look ok to you? In theory, the block proposer should be able to verify these at block construction time. So in essence the threshold could stay at 3 like before if I reorder the variants correctly in the enum

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sounds good

code: ErrorCodes::ExpiredDecryptedTx
.into(),
info: format!(
"Dercrypted tx expired at {:#?}, block time: {:#?}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god. What did fmt do here??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Dercrypted. 😆

grarco added a commit that referenced this pull request Mar 9, 2023
grarco added a commit that referenced this pull request Mar 9, 2023
grarco added a commit that referenced this pull request Mar 9, 2023
@grarco grarco mentioned this pull request Mar 22, 2023
grarco added a commit that referenced this pull request Mar 23, 2023
grarco added a commit that referenced this pull request Mar 31, 2023
tzemanovic added a commit that referenced this pull request Apr 7, 2023
* grarco/tx-lifetime:
  changelog: add #1123
  [ci] wasm checksums update
  Misc adjustments
  Refactors `prepare_proposal` tx validation
  Refactors block time retrieval
  Clippy + fmt
  Tx expiration check in `prepare_proposal`. Unit test
  Improves tx expiration checks. Adds unit tests
  Tx expiration validation
  Updates client for tx expiration
  Adds `expiration` field to `Tx`
  Wrapper `epoch` in replay protection specs
@tzemanovic tzemanovic mentioned this pull request Apr 7, 2023
tzemanovic added a commit that referenced this pull request Apr 11, 2023
@juped juped merged commit 403071e into main Apr 13, 2023
@juped juped deleted the grarco/tx-lifetime branch April 13, 2023 06:07
bengtlofgren pushed a commit that referenced this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replay protection
4 participants