-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. --------- Co-authored-by: kevincheng96 <[email protected]>
- Loading branch information
1 parent
6fc9ac4
commit 755cbc5
Showing
97 changed files
with
3,429 additions
and
1,396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.23; | ||
pragma solidity 0.8.27; | ||
|
||
/** | ||
* @title Code Jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.27; | ||
|
||
import {IQuarkWallet} from "quark-core/src/QuarkWallet.sol"; | ||
import {QuarkNonceManager} from "quark-core/src/QuarkNonceManager.sol"; | ||
|
||
/** | ||
* @title Cancel Core Script | ||
* @notice Core transaction script that can be used to cancel quark operations. | ||
* @author Legend Labs, Inc. | ||
*/ | ||
contract Cancel { | ||
/** | ||
* @notice May cancel a script by being run as a no-op (no operation). | ||
*/ | ||
function nop() external pure {} | ||
|
||
/** | ||
* @notice Cancels a script by calling into nonce manager to cancel the script's nonce. | ||
* @param nonce The nonce of the quark operation to cancel (exhaust) | ||
*/ | ||
function cancel(bytes32 nonce) external { | ||
nonceManager().cancel(nonce); | ||
} | ||
|
||
/** | ||
* @notice Cancels many scripts by calling into nonce manager to cancel each script's nonce. | ||
* @param nonces A list of nonces of the quark operations to cancel (exhaust) | ||
*/ | ||
function cancelMany(bytes32[] calldata nonces) external { | ||
QuarkNonceManager manager = nonceManager(); | ||
for (uint256 i = 0; i < nonces.length; ++i) { | ||
bytes32 nonce = nonces[i]; | ||
manager.cancel(nonce); | ||
} | ||
} | ||
|
||
function nonceManager() internal view returns (QuarkNonceManager) { | ||
return QuarkNonceManager(IQuarkWallet(address(this)).nonceManager()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/quark-core-scripts/src/vendor/uniswap_v3_periphery/PoolAddress.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.27; | ||
|
||
import {IQuarkWallet} from "quark-core/src/interfaces/IQuarkWallet.sol"; | ||
|
||
library QuarkNonceManagerMetadata { | ||
/// @notice Represents the unclaimed bytes32 value. | ||
bytes32 internal constant FREE = bytes32(uint256(0)); | ||
|
||
/// @notice A token that implies a Quark Operation is no longer replayable. | ||
bytes32 internal constant EXHAUSTED = bytes32(type(uint256).max); | ||
} | ||
|
||
/** | ||
* @title Quark Nonce Manager | ||
* @notice Contract for managing nonces for Quark wallets | ||
* @author Compound Labs, Inc. | ||
*/ | ||
contract QuarkNonceManager { | ||
error NonReplayableNonce(address wallet, bytes32 nonce, bytes32 submissionToken, bool exhausted); | ||
error InvalidNonce(address wallet, bytes32 nonce); | ||
error InvalidSubmissionToken(address wallet, bytes32 nonce, bytes32 submissionToken); | ||
|
||
event NonceSubmitted(address wallet, bytes32 nonce, bytes32 submissionToken); | ||
event NonceCanceled(address wallet, bytes32 nonce); | ||
|
||
/// @notice Represents the unclaimed bytes32 value. | ||
bytes32 public constant FREE = QuarkNonceManagerMetadata.FREE; | ||
|
||
/// @notice A token that implies a Quark Operation is no longer replayable. | ||
bytes32 public constant EXHAUSTED = QuarkNonceManagerMetadata.EXHAUSTED; | ||
|
||
/// @notice Mapping from nonces to last used submission token. | ||
mapping(address wallet => mapping(bytes32 nonce => bytes32 lastToken)) public submissions; | ||
|
||
/** | ||
* @notice Ensures a given nonce is canceled for sender. An un-used nonce will not be usable in the future, and a replayable nonce will no longer be replayable. This is a no-op for already canceled operations. | ||
* @param nonce The nonce of the chain to cancel. | ||
*/ | ||
function cancel(bytes32 nonce) external { | ||
submissions[msg.sender][nonce] = EXHAUSTED; | ||
emit NonceCanceled(msg.sender, nonce); | ||
} | ||
|
||
/** | ||
* @notice Attempts a first or subsequent submission of a given nonce from a wallet. | ||
* @param nonce The nonce of the chain to submit. | ||
* @param isReplayable True only if the operation has been marked as replayable. Otherwise, submission token must be the EXHAUSTED value. | ||
* @param submissionToken The token for this submission. For single-use operations, set `submissionToken` to `uint256(-1)`. For first-use replayable operations, set `submissionToken` = `nonce`. Otherwise, the next submission token from the nonce-chain. | ||
*/ | ||
function submit(bytes32 nonce, bool isReplayable, bytes32 submissionToken) external { | ||
bytes32 lastTokenSubmission = submissions[msg.sender][nonce]; | ||
if (lastTokenSubmission == EXHAUSTED) { | ||
revert NonReplayableNonce(msg.sender, nonce, submissionToken, true); | ||
} | ||
// Defense-in-depth check for `nonce != FREE` and `nonce != EXHAUSTED` | ||
if (nonce == FREE || nonce == EXHAUSTED) { | ||
revert InvalidNonce(msg.sender, nonce); | ||
} | ||
// Defense-in-depth check for `submissionToken != FREE` and `submissionToken != EXHAUSTED` | ||
if (submissionToken == FREE || submissionToken == EXHAUSTED) { | ||
revert InvalidSubmissionToken(msg.sender, nonce, submissionToken); | ||
} | ||
|
||
bool validFirstPlay = lastTokenSubmission == FREE && submissionToken == nonce; | ||
|
||
/* let validFirstPlayOrReplay = validFirstPlay or validReplay [with short-circuiting] */ | ||
bool validFirstPlayOrReplay = | ||
validFirstPlay || keccak256(abi.encodePacked(submissionToken)) == lastTokenSubmission; | ||
|
||
if (!validFirstPlayOrReplay) { | ||
revert InvalidSubmissionToken(msg.sender, nonce, submissionToken); | ||
} | ||
|
||
// Note: even with a valid submission token, we always set non-replayables to exhausted (e.g. for cancellations) | ||
submissions[msg.sender][nonce] = isReplayable ? submissionToken : EXHAUSTED; | ||
emit NonceSubmitted(msg.sender, nonce, submissionToken); | ||
} | ||
} |
Oops, something went wrong.