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

Switch to isReplayable #205

Merged
merged 8 commits into from
Sep 12, 2024
Merged

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Aug 27, 2024

This patch fixes some items in regards to a user signing isReplayable. Specifically, when a user signs an operation, they need to specify if the quark operation is replayable or not. When not, the state manager nonce must be bytes32(uint256(-1)), but when it is replayable, the first play must be op.nonce. If the user doesn't sign isReplayable, then we'd need to enforce that the first play is replayToken = op.nonce, which is bad since it that script could (if a bad nonce is chosen) end up replayable, which is an attack vector for a semi-bad client decision. Thus, we add this check to the user's signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a complete implementation.

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/QuarkStateManager.sol Outdated Show resolved Hide resolved
src/quark-core/src/QuarkWallet.sol Outdated Show resolved Hide resolved
test/quark-core/Nonce.t.sol Outdated Show resolved Hide resolved
Copy link
Collaborator

@fluffywaffles fluffywaffles left a comment

Choose a reason for hiding this comment

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

I think we already discussed isReplayable in #quark, and I'm in favor. I do see the compelling case that we need it in the signature to give users control over whether replays are allowed. I like it as a boolean; I think there was some discussion about using maxReplays and it doubling as an extra(neous) stop condition for computing the current replay count, and I don't care for that idea, but I also wouldn't want to die on that hill.

This patch fixes some items in regards to a user signing `isReplayable`. Specifically, when a user signs an operation, they need to specify if the quark operation is replayable or not. When not, the state manager nonce _must be_ `bytes32(uint256(-1))`, but when it is replayable, the first play _must be_ `op.nonce`. If the user doesn't sign `isReplayable`, then we'd need to enforce that the first play is `replayToken = op.nonce`, which is bad since it that script could (if a bad nonce is chosen) end up replayable, which is an attack vector for a semi-bad client decision. Thus, we add this check to the user's signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a complete implementation.
@hayesgm hayesgm force-pushed the hayesgm/is-replayable branch from 16d4a98 to 4f02f25 Compare September 9, 2024 20:21
@hayesgm hayesgm marked this pull request as ready for review September 10, 2024 00:12
Copy link
Collaborator

@fluffywaffles fluffywaffles left a comment

Choose a reason for hiding this comment

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

looks good, just a few notes

test/lib/AllowCallbacks.sol Outdated Show resolved Hide resolved
test/lib/RecurringPurchase.sol Outdated Show resolved Hide resolved
src/quark-core/src/QuarkNonceManager.sol Outdated Show resolved Hide resolved
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.

Look great overall! No blocking issues, other than to re-run the formatter and generate a new gas snapshot.

EDIT: Well, actually, this comment I think is worth discussing.

README.md Outdated Show resolved Hide resolved
src/quark-core/src/QuarkNonceManager.sol Outdated Show resolved Hide resolved
src/quark-core/src/QuarkNonceManager.sol Outdated Show resolved Hide resolved
src/quark-core/src/QuarkNonceManager.sol Show resolved Hide resolved
test/quark-core/QuarkWallet.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
test/lib/AllowCallbacks.sol Outdated Show resolved Hide resolved
hayesgm added a commit that referenced this pull request Sep 11, 2024
Previously in `QuarkNonceManager`, we used `submissionToken=EXHAUSTED` for non-replayable submissions and `submissionToken=nonce` for the first play of replayable submissions. Overall, this behavior was inconsistent (though otherwise fine) and generally unobservable. With the addition of `getActiveSubmissionToken`, this behavior became obervable and showed its inconsistencies. This patch changes the defined behavior making it where we submit `submissionToken=nonce` for the first play or a single-use or replayable quark operation, but still retain the behavior that `submissions[nonce]=EXHAUSTED` for non-replayables. This ends up as a reduction in the overall code complexity.

The only true behavior this changes is that we must (and should) ban `nonce=bytes32(0)` (and for the sake of consistency also `nonce=bytes32(uint_max)`). This is because we would be submitting with `submissionToken=FREE` for that nonce and overall it isn't worth the risk of allowing that (since it wouldn't, but _could_ lead to unlimited replays if other code isn't implemented correctly).

Overall, I think this change is a net benefit in reduction of code complexity and better understandability from the end-user's perspective.

Patches:
  * Add a test where we check what values a user can submit for submission tokens
  * Addressed some #205 comments
hayesgm added a commit that referenced this pull request Sep 11, 2024
Previously in `QuarkNonceManager`, we used `submissionToken=EXHAUSTED` for non-replayable submissions and `submissionToken=nonce` for the first play of replayable submissions. Overall, this behavior was inconsistent (though otherwise fine) and generally unobservable. With the addition of `getActiveSubmissionToken`, this behavior became obervable and showed its inconsistencies. This patch changes the defined behavior making it where we submit `submissionToken=nonce` for the first play or a single-use or replayable quark operation, but still retain the behavior that `submissions[nonce]=EXHAUSTED` for non-replayables. This ends up as a reduction in the overall code complexity.

The only true behavior this changes is that we must (and should) ban `nonce=bytes32(0)` (and for the sake of consistency also `nonce=bytes32(uint_max)`). This is because we would be submitting with `submissionToken=FREE` for that nonce and overall it isn't worth the risk of allowing that (since it wouldn't, but _could_ lead to unlimited replays if other code isn't implemented correctly).

Overall, I think this change is a net benefit in reduction of code complexity and better understandability from the end-user's perspective.

Patches:
  * Add a test where we check what values a user can submit for submission tokens
  * Addressed some #205 comments
hayesgm added a commit that referenced this pull request Sep 11, 2024
Previously in `QuarkNonceManager`, we used `submissionToken=EXHAUSTED` for non-replayable submissions and `submissionToken=nonce` for the first play of replayable submissions. Overall, this behavior was inconsistent (though otherwise fine) and generally unobservable. With the addition of `getActiveSubmissionToken`, this behavior became obervable and showed its inconsistencies. This patch changes the defined behavior making it where we submit `submissionToken=nonce` for the first play or a single-use or replayable quark operation, but still retain the behavior that `submissions[nonce]=EXHAUSTED` for non-replayables. This ends up as a reduction in the overall code complexity.

The only true behavior this changes is that we must (and should) ban `nonce=bytes32(0)` (and for the sake of consistency also `nonce=bytes32(uint_max)`). This is because we would be submitting with `submissionToken=FREE` for that nonce and overall it isn't worth the risk of allowing that (since it wouldn't, but _could_ lead to unlimited replays if other code isn't implemented correctly).

Overall, I think this change is a net benefit in reduction of code complexity and better understandability from the end-user's perspective.

Patches:
  * Add a test where we check what values a user can submit for submission tokens
  * Addressed some #205 comments
hayesgm added a commit that referenced this pull request Sep 11, 2024
Previously in `QuarkNonceManager`, we used `submissionToken=EXHAUSTED` for non-replayable submissions and `submissionToken=nonce` for the first play of replayable submissions. Overall, this behavior was inconsistent (though otherwise fine) and generally unobservable. With the addition of `getActiveSubmissionToken`, this behavior became obervable and showed its inconsistencies. This patch changes the defined behavior making it where we submit `submissionToken=nonce` for the first play or a single-use or replayable quark operation, but still retain the behavior that `submissions[nonce]=EXHAUSTED` for non-replayables. This ends up as a reduction in the overall code complexity.

The only true behavior this changes is that we must (and should) ban `nonce=bytes32(0)` (and for the sake of consistency also `nonce=bytes32(uint_max)`). This is because we would be submitting with `submissionToken=FREE` for that nonce and overall it isn't worth the risk of allowing that (since it wouldn't, but _could_ lead to unlimited replays if other code isn't implemented correctly).

Overall, I think this change is a net benefit in reduction of code complexity and better understandability from the end-user's perspective.

Patches:
  * Add a test where we check what values a user can submit for submission tokens
  * Addressed some #205 comments
This patch adds support for setting the active nonce and submission
token in temporary storage so scripts can read it and get the current
nonce, submission token, and if they so choose, N. This is useful for
certain scripts.
@hayesgm hayesgm merged commit e1e7e31 into hayesgm/replayable-by-nonce Sep 12, 2024
2 of 4 checks passed
@hayesgm hayesgm deleted the hayesgm/is-replayable branch September 12, 2024 23:24
hayesgm added a commit that referenced this pull request Sep 12, 2024
This patch fixes some items in regards to a user signing `isReplayable`.
Specifically, when a user signs an operation, they need to specify if
the quark operation is replayable or not. When not, the state manager
nonce _must be_ `bytes32(uint256(-1))`, but when it is replayable, the
first play _must be_ `op.nonce`. If the user doesn't sign
`isReplayable`, then we'd need to enforce that the first play is
`replayToken = op.nonce`, which is bad since it that script could (if a
bad nonce is chosen) end up replayable, which is an attack vector for a
semi-bad client decision. Thus, we add this check to the user's
signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a
complete implementation.

Whitespace changes for fmt check
hayesgm added a commit that referenced this pull request Sep 13, 2024
This patch fixes some items in regards to a user signing `isReplayable`.
Specifically, when a user signs an operation, they need to specify if
the quark operation is replayable or not. When not, the state manager
nonce _must be_ `bytes32(uint256(-1))`, but when it is replayable, the
first play _must be_ `op.nonce`. If the user doesn't sign
`isReplayable`, then we'd need to enforce that the first play is
`replayToken = op.nonce`, which is bad since it that script could (if a
bad nonce is chosen) end up replayable, which is an attack vector for a
semi-bad client decision. Thus, we add this check to the user's
signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a
complete implementation.

Whitespace changes for fmt check
hayesgm added a commit that referenced this pull request Sep 13, 2024
This patch fixes some items in regards to a user signing `isReplayable`.
Specifically, when a user signs an operation, they need to specify if
the quark operation is replayable or not. When not, the state manager
nonce _must be_ `bytes32(uint256(-1))`, but when it is replayable, the
first play _must be_ `op.nonce`. If the user doesn't sign
`isReplayable`, then we'd need to enforce that the first play is
`replayToken = op.nonce`, which is bad since it that script could (if a
bad nonce is chosen) end up replayable, which is an attack vector for a
semi-bad client decision. Thus, we add this check to the user's
signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a
complete implementation.

Whitespace changes for fmt check

Fix two minor comments
hayesgm added a commit that referenced this pull request Sep 13, 2024
This patch fixes some items in regards to a user signing `isReplayable`.
Specifically, when a user signs an operation, they need to specify if
the quark operation is replayable or not. When not, the state manager
nonce _must be_ `bytes32(uint256(-1))`, but when it is replayable, the
first play _must be_ `op.nonce`. If the user doesn't sign
`isReplayable`, then we'd need to enforce that the first play is
`replayToken = op.nonce`, which is bad since it that script could (if a
bad nonce is chosen) end up replayable, which is an attack vector for a
semi-bad client decision. Thus, we add this check to the user's
signature and all things should be good in the world.

Also, we start to fix a bit of verbiage to make things a bit nicer.

Techncially, while it's missing about 200 new tests, this should be a
complete implementation.

Whitespace changes for fmt check

Fix two minor comments

Minor gas improvements
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