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

Add Replayables with Token #204

Merged
merged 4 commits into from
Sep 14, 2024
Merged

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Aug 26, 2024

This code leads out the core changes for replayables with token. This was meant to be a WIP that just showed off the core features (it still is), but to get it to compile, I ended up converting most of the current tests to the new framework (e.g. mostly converting them to pick a semi-random nonce versus nextNonce, and checking getNonceToken as opposed to getNextNonce). Overall, the changes to the non-test code are very straight-forward. Most notable should be the changes to QuarkStateManager (adding new nonce and replay token code), and adding a new function to QuarkWallet verifySigAndExecuteReplayableQuarkOperation.

Note: I didn't spend much time working on the outer interface for this, and I need to consider how this works best with multi-quark operations, but I wanted to get the outline first so we could discuss. There are also failing test cases and absent test cases, but again, more of a discussion point than a final product here.

@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch 2 times, most recently from 353e187 to 5c5bd45 Compare August 27, 2024 00:35
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.

The current approach looks good 👍

src/quark-core/src/QuarkStateManager.sol Outdated Show resolved Hide resolved
src/quark-core/src/QuarkStateManager.sol Outdated Show resolved Hide resolved
@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch from 16d4a98 to 5c5bd45 Compare August 27, 2024 23:17
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.

Overall this looks good to me 👍

Already noted, but we will want to spend some time thinking a little more thoroughly about testing.

src/quark-core/src/QuarkStateManager.sol Outdated Show resolved Hide resolved
test/lib/QuarkOperationHelper.sol Outdated Show resolved Hide resolved
test/lib/QuarkOperationHelper.sol Outdated Show resolved Hide resolved
@hayesgm hayesgm marked this pull request as ready for review September 12, 2024 23:31
@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch from 9c58f8c to d1e8420 Compare September 12, 2024 23:33
Base automatically changed from kevin/remove-isolated-storage to kevin/quark-v2 September 12, 2024 23:36
This code leads out the core changes for replayables with token. This was meant to be a WIP that just showed off the core features (it still is), but to get it to compile, I ended up converting most of the current tests to the new framework (e.g. mostly converting them to pick a semi-random nonce versus `nextNonce`, and checking `getNonceToken` as opposed to `getNextNonce`). Overall, the changes to the non-test code are very straight-forward. Most notable should be the changes to `QuarkStateManager` (adding new nonce and replay token code), and adding a new function to QuarkWallet `verifySigAndExecuteReplayableQuarkOperation`.

Note: I didn't spend much time working on the outer interface for this, and I need to consider how this works best with multi-quark operations, but I wanted to get the outline first so we could discuss. There are also failing test cases and absent test cases, but again, more of a discussion point than a final product here.

Patches:
  * Fix current tests
This patch mostly renames `QuarkStateManager` to `QuarkNonceManager`.
Additionally, we start to use the term `submissionToken`, since it can
cover first plays or replays both as "submissions". We choose the term
`FREE` for the 0-token and `EXHAUSTED` for non-replayable tokens.
Overall, this should provide a clearer and more consistent naming
throughout the changeset.
@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch from d1e8420 to 2940fe0 Compare September 13, 2024 00:49
@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch from 2940fe0 to fbc1a3b Compare September 13, 2024 01:46
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
@hayesgm hayesgm force-pushed the hayesgm/replayable-by-nonce branch from fbc1a3b to b00f3f6 Compare September 13, 2024 01:59
We now cache the old transient slot values (e.g. for `activeNonce`,
`callback`, etc) in order to restore them after calling the Quark
script.

This also adds a new test to test batched submission for a contract with
callbacks to check its behavior.

---------

Co-authored-by: kevincheng96 <[email protected]>
@kevincheng96
Copy link
Collaborator

Merging this into the kevin/quark-v2 feature branch now.

@kevincheng96 kevincheng96 merged commit 755cbc5 into kevin/quark-v2 Sep 14, 2024
3 of 4 checks passed
@kevincheng96 kevincheng96 deleted the hayesgm/replayable-by-nonce branch September 14, 2024 05:32
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