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

Nonce Cancel by New Op #213

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Sep 11, 2024

This patch adds the ability to cancel an outstanding nonce by sending a new operation. Previously, it was required that the wallet had access to the nonce chain of the previous operation to cancel that operation. We now allow the wallet to craft a brand new operation that simply calls cancel on a different nonce chain. This could also be used in a bulk-cancelation script. Generally the process is safe as the new code (a) depends on msg.sender and a properly executed script, and (b) only works in the direction of cancelation.

This patch adds the ability to cancel an outstanding nonce by sending a new operation. Previously, it was required that the wallet had access to the nonce chain of the previous operation to cancel that operation. We now allow the wallet to craft a brand new operation that simply calls cancel on a different nonce chain. This could also be used in a bulk-cancelation script. Generally the process is safe as the new code (a) depends on `msg.sender` and a properly executed script, and (b) only works in the direction of cancelation.
test/lib/CancelOtherScript.sol Outdated Show resolved Hide resolved
test/quark-core/QuarkNonceManager.t.sol Show resolved Hide resolved
Comment on lines +431 to +434
// nonce 1 can be set manually
vm.prank(address(0x123));
nonceManager.submit(nonce, false, nonce);
assertEq(nonceManager.submissions(address(0x123), nonce), nonceManager.EXHAUSTED());
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we already have this and I didn't see it -- but is there also a case for manually doing nonceManager.submit(nonce, true, nonce)? That is, making it replayable before you ever actually execute an op with that nonce.

one weird case would be:

  1. manually nonceManager.submit(nonce, true, nonce)
  2. submit an op that has isReplayable=false

if chain length is 1, you're in a weird spot: it'll revert the first time you try to submit an op with that nonce. So you can never execute a script with that nonce (except if you find a preimage). You can clean it up by doing cancel(nonce) from a new op, but otherwise it's kind of a weird edge case. Convoluted, but perhaps worth documenting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting-- I guess i'm thinking "if a script sends a weird message to nonce manager is it that important?" as a rule of thumb. Totally smoething to consider, but can't a script also call like submit(nonce, true, 5) or whatever that's also weird?

Copy link
Collaborator

@kevincheng96 kevincheng96 left a comment

Choose a reason for hiding this comment

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

LGTM

src/quark-core/src/QuarkWallet.sol Outdated Show resolved Hide resolved
test/quark-core/Noncer.t.sol Outdated Show resolved Hide resolved
test/quark-core/QuarkNonceManager.t.sol Outdated Show resolved Hide resolved
test/quark-core/QuarkNonceManager.t.sol Outdated Show resolved Hide resolved
test/quark-core/QuarkNonceManager.t.sol Show resolved Hide resolved
This patch bumps us up to 0.8.27 and cancun and starts using `tstore`
and `tload` for transient reads and writes. Note: we still clear values
mostly to ensure that post-nested calls the script will see 0 instead of
the nested's own value.

Note: I have not taken a stab at understanding `ALLOW_CALLBACKS` and how
that should function.
@hayesgm hayesgm merged commit 42e554e into hayesgm/test-multi-quark-replays Sep 12, 2024
1 of 4 checks passed
@hayesgm hayesgm deleted the hayesgm/cancel-by-new-op branch September 12, 2024 23:01
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.

3 participants