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

Remove exhausted from NonReplayableNonce error #218

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/quark-core/src/QuarkNonceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library QuarkNonceManagerMetadata {
* @author Compound Labs, Inc.
*/
contract QuarkNonceManager {
error NonReplayableNonce(address wallet, bytes32 nonce, bytes32 submissionToken, bool exhausted);
error NonReplayableNonce(address wallet, bytes32 nonce, bytes32 submissionToken);
error InvalidNonce(address wallet, bytes32 nonce);
error InvalidSubmissionToken(address wallet, bytes32 nonce, bytes32 submissionToken);

Expand Down Expand Up @@ -51,7 +51,7 @@ contract QuarkNonceManager {
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);
revert NonReplayableNonce(msg.sender, nonce, submissionToken);
}
// Defense-in-depth check for `nonce != FREE` and `nonce != EXHAUSTED`
if (nonce == FREE || nonce == EXHAUSTED) {
Expand Down
4 changes: 2 additions & 2 deletions test/ReplayableTransactions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ contract ReplayableTransactionsTest is Test {
vm.warp(block.timestamp + purchaseInterval);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1], true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1]
)
);
aliceWallet.executeQuarkOperationWithSubmissionToken(op, submissionTokens[1], v1, r1, s1);

vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[2], true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[2]
)
);
aliceWallet.executeQuarkOperationWithSubmissionToken(op, submissionTokens[2], v1, r1, s1);
Expand Down
4 changes: 1 addition & 3 deletions test/quark-core/EIP712.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ contract EIP712Test is Test {

// submitter tries to reuse the same signature twice, for a non-replayable operation
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(wallet), op.nonce, op.nonce, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(wallet), op.nonce, op.nonce)
);
wallet.executeQuarkOperation(op, v, r, s);
}
Expand Down
42 changes: 13 additions & 29 deletions test/quark-core/QuarkNonceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ contract QuarkNonceManagerTest is Test {
for (uint256 i = 1; i <= 20; i++) {
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector,
address(this),
bytes32(i),
bytes32(type(uint256).max),
true
QuarkNonceManager.NonReplayableNonce.selector, address(this), bytes32(i), bytes32(type(uint256).max)
)
);
nonceManager.submit(bytes32(i), false, EXHAUSTED_TOKEN);
Expand All @@ -85,12 +81,12 @@ contract QuarkNonceManagerTest is Test {
nonceManager.submit(nonce, false, nonce);

vm.expectRevert(
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonce, true)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonce)
);
nonceManager.submit(nonce, false, nonce);

vm.expectRevert(
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED, true)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED)
);
nonceManager.submit(nonce, false, EXHAUSTED);
}
Expand Down Expand Up @@ -130,9 +126,7 @@ contract QuarkNonceManagerTest is Test {
assertEq(nonceManager.submissions(address(this), nonce), EXHAUSTED_TOKEN);

vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonceSecret, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonceSecret)
);
nonceManager.submit(nonce, true, nonceSecret);
}
Expand Down Expand Up @@ -178,15 +172,11 @@ contract QuarkNonceManagerTest is Test {
assertEq(nonceManager.submissions(address(this), nonce), EXHAUSTED_TOKEN);

vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, FREE_TOKEN, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, FREE_TOKEN)
);
nonceManager.submit(nonce, false, FREE_TOKEN);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED_TOKEN, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED_TOKEN)
);
nonceManager.submit(nonce, false, EXHAUSTED_TOKEN);
}
Expand Down Expand Up @@ -368,38 +358,32 @@ contract QuarkNonceManagerTest is Test {
assertEq(nonceManager.submissions(address(this), nonce), EXHAUSTED_TOKEN);

vm.expectRevert(
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonce, true)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonce)
);
nonceManager.submit(nonce, true, nonce);

vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, submissionToken2, true
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, submissionToken2
)
);
nonceManager.submit(nonce, true, submissionToken2);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, submissionToken1, true
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, submissionToken1
)
);
nonceManager.submit(nonce, true, submissionToken1);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonceSecret, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, nonceSecret)
);
nonceManager.submit(nonce, true, nonceSecret);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED_TOKEN, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, EXHAUSTED_TOKEN)
);
nonceManager.submit(nonce, true, EXHAUSTED_TOKEN);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, FREE_TOKEN, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(this), nonce, FREE_TOKEN)
);
nonceManager.submit(nonce, true, FREE_TOKEN);
}
Expand All @@ -416,7 +400,7 @@ contract QuarkNonceManagerTest is Test {
// nonce 1 can be set manually
vm.prank(address(0x123));
vm.expectRevert(
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(0x123), nonce, nonce, true)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, address(0x123), nonce, nonce)
);
nonceManager.submit(nonce, false, nonce);
assertEq(nonceManager.submissions(address(0x123), nonce), nonceManager.EXHAUSTED());
Expand Down
16 changes: 7 additions & 9 deletions test/quark-core/QuarkWallet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ contract QuarkWalletTest is Test {
// Not sure why this revert isn't showing up-- it's reverting, nonetheless.
// vm.expectRevert(
// abi.encodeWithSelector(
// QuarkNonceManager.NonReplayableNonce.selector, address(aliceWalletExecutable), nonce, nonce, true
// QuarkNonceManager.NonReplayableNonce.selector, address(aliceWalletExecutable), nonce, nonce
// )
// );
aliceWalletExecutable.executeScript(nonce, scriptAddress, call, scriptSources);
Expand Down Expand Up @@ -331,7 +331,7 @@ contract QuarkWalletTest is Test {
// Check it is no longer runnable
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, op.nonce, true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, op.nonce
)
);
aliceWallet.executeQuarkOperationWithSubmissionToken(op, op.nonce, v, r, s);
Expand Down Expand Up @@ -619,7 +619,7 @@ contract QuarkWalletTest is Test {
// and now you can no longer replay
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1], true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1]
)
);
aliceWallet.executeQuarkOperationWithSubmissionToken(op, submissionTokens[1], v, r, s);
Expand Down Expand Up @@ -667,7 +667,7 @@ contract QuarkWalletTest is Test {
// and now you can no longer replay
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1], true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op.nonce, submissionTokens[1]
)
);
aliceWallet.executeQuarkOperationWithSubmissionToken(op, submissionTokens[1], v, r, s);
Expand Down Expand Up @@ -937,7 +937,7 @@ contract QuarkWalletTest is Test {
// call again using the same operation
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op1.nonce, op1.nonce, true
QuarkNonceManager.NonReplayableNonce.selector, address(aliceWallet), op1.nonce, op1.nonce
)
);
aliceWallet.executeMultiQuarkOperation(op1, opDigests, v, r, s);
Expand Down Expand Up @@ -1110,14 +1110,12 @@ contract QuarkWalletTest is Test {
// test all tokens do not replay now for op1, which is non-replayable
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, aliceWallet, op1.nonce, EXHAUSTED_TOKEN, true
QuarkNonceManager.NonReplayableNonce.selector, aliceWallet, op1.nonce, EXHAUSTED_TOKEN
)
);
aliceWallet.executeMultiQuarkOperationWithSubmissionToken(op1, EXHAUSTED_TOKEN, opDigests, v, r, s);
vm.expectRevert(
abi.encodeWithSelector(
QuarkNonceManager.NonReplayableNonce.selector, aliceWallet, op1.nonce, op1.nonce, true
)
abi.encodeWithSelector(QuarkNonceManager.NonReplayableNonce.selector, aliceWallet, op1.nonce, op1.nonce)
);
aliceWallet.executeMultiQuarkOperationWithSubmissionToken(op1, op1.nonce, opDigests, v, r, s);

Expand Down
Loading