Skip to content

Commit c97ff51

Browse files
C4 S-106 IntentAlreadyUsed validation will never fail (#68)
* S-106 Remove IntentAlreadyUsed validation that will never be hit * Remove usedIntents entirely * Update snapshot * Update gas snapshot for TrailsIntentEntrypoint tests with new gas usage metrics and adjustments to ensure accuracy. * Remove unused error 'IntentAlreadyUsed' from TrailsIntentEntrypoint contract --------- Co-authored-by: Shun Kakinoki <39187513+shunkakinoki@users.noreply.github.com> Co-authored-by: Shun Kakinoki <shunkakinoki@gmail.com>
1 parent 08226ab commit c97ff51

File tree

5 files changed

+41
-104
lines changed

5 files changed

+41
-104
lines changed

.gas-snapshot

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,47 @@ DelegatecallGuardTest:test_direct_call_reverts_NotDelegateCall() (gas: 8420)
66
DelegatecallGuardTest:test_multiple_delegatecall_guards() (gas: 298825)
77
DelegatecallGuardTest:test_onlyDelegatecall_modifier_usage() (gas: 98867)
88
DelegatecallGuardTest:test_self_address_immutable() (gas: 2877)
9-
TrailsIntentEntrypointDeploymentTest:test_DeployIntentEntrypoint_SameAddress() (gas: 886036)
10-
TrailsIntentEntrypointDeploymentTest:test_DeployIntentEntrypoint_Success() (gas: 878447)
11-
TrailsIntentEntrypointDeploymentTest:test_DeployedIntentEntrypoint_HasCorrectConfiguration() (gas: 884342)
12-
TrailsIntentEntrypointTest:testAssemblyCodeExecution() (gas: 112699)
13-
TrailsIntentEntrypointTest:testConstructor() (gas: 3309)
14-
TrailsIntentEntrypointTest:testConstructorAndDomainSeparator() (gas: 7706)
15-
TrailsIntentEntrypointTest:testDepositToIntentAlreadyUsed() (gas: 136588)
16-
TrailsIntentEntrypointTest:testDepositToIntentCannotReuseDigest() (gas: 117228)
17-
TrailsIntentEntrypointTest:testDepositToIntentExpiredDeadline() (gas: 56096)
18-
TrailsIntentEntrypointTest:testDepositToIntentReentrancyProtection() (gas: 136566)
19-
TrailsIntentEntrypointTest:testDepositToIntentRequiresNonZeroAmount() (gas: 27416)
20-
TrailsIntentEntrypointTest:testDepositToIntentRequiresValidToken() (gas: 30799)
21-
TrailsIntentEntrypointTest:testDepositToIntentTransferFromFails() (gas: 80879)
22-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitAlreadyUsed() (gas: 155215)
23-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitExpiredDeadline() (gas: 36526)
24-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitReentrancyProtection() (gas: 146586)
25-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresNonZeroAmount() (gas: 35240)
26-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresPermitAmount() (gas: 83234)
27-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresValidToken() (gas: 35966)
28-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitTransferFromFails() (gas: 82463)
29-
TrailsIntentEntrypointTest:testDepositToIntentWithPermitWrongSigner() (gas: 40524)
30-
TrailsIntentEntrypointTest:testDepositToIntentWithoutPermit_RequiresIntentAddress() (gas: 31508)
31-
TrailsIntentEntrypointTest:testDepositToIntentWrongSigner() (gas: 57349)
32-
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20AndFee_Success() (gas: 831960)
33-
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_InsufficientAllowance_Reverts() (gas: 794757)
34-
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_InsufficientBalance_Reverts() (gas: 794716)
35-
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_Success() (gas: 802824)
36-
TrailsIntentEntrypointTest:testExactApprovalFlow() (gas: 192796)
37-
TrailsIntentEntrypointTest:testExecuteIntentWithFee() (gas: 176076)
38-
TrailsIntentEntrypointTest:testExecuteIntentWithPermit() (gas: 145698)
39-
TrailsIntentEntrypointTest:testExecuteIntentWithPermitExpired() (gas: 36445)
40-
TrailsIntentEntrypointTest:testExecuteIntentWithPermitInvalidSignature() (gas: 37768)
41-
TrailsIntentEntrypointTest:testFeeCollectorReceivesFees() (gas: 170228)
42-
TrailsIntentEntrypointTest:testFeeCollectorReceivesFeesWithoutPermit() (gas: 139856)
43-
TrailsIntentEntrypointTest:testInfiniteApprovalFlow() (gas: 185611)
44-
TrailsIntentEntrypointTest:testIntentTypehashConstant() (gas: 5707)
45-
TrailsIntentEntrypointTest:testInvalidNonceReverts() (gas: 54701)
46-
TrailsIntentEntrypointTest:testNonceIncrementsOnDeposit() (gas: 112900)
47-
TrailsIntentEntrypointTest:testPermitAmountExcessiveWithFee() (gas: 83027)
48-
TrailsIntentEntrypointTest:testPermitAmountInsufficientWithFee() (gas: 82059)
49-
TrailsIntentEntrypointTest:testUsedIntentsMapping() (gas: 113770)
50-
TrailsIntentEntrypointTest:testVersionConstant() (gas: 10381)
9+
TrailsIntentEntrypointDeploymentTest:test_DeployIntentEntrypoint_SameAddress() (gas: 839567)
10+
TrailsIntentEntrypointDeploymentTest:test_DeployIntentEntrypoint_Success() (gas: 832067)
11+
TrailsIntentEntrypointDeploymentTest:test_DeployedIntentEntrypoint_HasCorrectConfiguration() (gas: 834866)
12+
TrailsIntentEntrypointTest:testAssemblyCodeExecution() (gas: 89228)
13+
TrailsIntentEntrypointTest:testConstructor() (gas: 3287)
14+
TrailsIntentEntrypointTest:testConstructorAndDomainSeparator() (gas: 7684)
15+
TrailsIntentEntrypointTest:testDepositToIntentAlreadyUsed() (gas: 114117)
16+
TrailsIntentEntrypointTest:testDepositToIntentCannotReuseDigest() (gas: 94757)
17+
TrailsIntentEntrypointTest:testDepositToIntentExpiredDeadline() (gas: 56029)
18+
TrailsIntentEntrypointTest:testDepositToIntentReentrancyProtection() (gas: 114095)
19+
TrailsIntentEntrypointTest:testDepositToIntentRequiresNonZeroAmount() (gas: 27371)
20+
TrailsIntentEntrypointTest:testDepositToIntentRequiresValidToken() (gas: 30754)
21+
TrailsIntentEntrypointTest:testDepositToIntentTransferFromFails() (gas: 58387)
22+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitAlreadyUsed() (gas: 132693)
23+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitExpiredDeadline() (gas: 36459)
24+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitReentrancyProtection() (gas: 124115)
25+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresNonZeroAmount() (gas: 35173)
26+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresPermitAmount() (gas: 60742)
27+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitRequiresValidToken() (gas: 35899)
28+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitTransferFromFails() (gas: 59993)
29+
TrailsIntentEntrypointTest:testDepositToIntentWithPermitWrongSigner() (gas: 40450)
30+
TrailsIntentEntrypointTest:testDepositToIntentWithoutPermit_RequiresIntentAddress() (gas: 31441)
31+
TrailsIntentEntrypointTest:testDepositToIntentWrongSigner() (gas: 57297)
32+
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20AndFee_Success() (gas: 809490)
33+
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_InsufficientAllowance_Reverts() (gas: 772287)
34+
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_InsufficientBalance_Reverts() (gas: 772224)
35+
TrailsIntentEntrypointTest:testDepositToIntent_WithNonStandardERC20_Success() (gas: 780332)
36+
TrailsIntentEntrypointTest:testExactApprovalFlow() (gas: 150375)
37+
TrailsIntentEntrypointTest:testExecuteIntentWithFee() (gas: 153584)
38+
TrailsIntentEntrypointTest:testExecuteIntentWithPermit() (gas: 123206)
39+
TrailsIntentEntrypointTest:testExecuteIntentWithPermitExpired() (gas: 36378)
40+
TrailsIntentEntrypointTest:testExecuteIntentWithPermitInvalidSignature() (gas: 37716)
41+
TrailsIntentEntrypointTest:testFeeCollectorReceivesFees() (gas: 147736)
42+
TrailsIntentEntrypointTest:testFeeCollectorReceivesFeesWithoutPermit() (gas: 117386)
43+
TrailsIntentEntrypointTest:testInfiniteApprovalFlow() (gas: 144644)
44+
TrailsIntentEntrypointTest:testIntentTypehashConstant() (gas: 5685)
45+
TrailsIntentEntrypointTest:testInvalidNonceReverts() (gas: 54678)
46+
TrailsIntentEntrypointTest:testNonceIncrementsOnDeposit() (gas: 90407)
47+
TrailsIntentEntrypointTest:testPermitAmountExcessiveWithFee() (gas: 60535)
48+
TrailsIntentEntrypointTest:testPermitAmountInsufficientWithFee() (gas: 59589)
49+
TrailsIntentEntrypointTest:testVersionConstant() (gas: 10337)
5150
TrailsRouterDeploymentTest:test_DeployTrailsRouter_SameAddress() (gas: 1722289)
5251
TrailsRouterDeploymentTest:test_DeployTrailsRouter_Success() (gas: 1712948)
5352
TrailsRouterDeploymentTest:test_DeployedRouter_HasCorrectConfiguration() (gas: 1712744)

src/TrailsIntentEntrypoint.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ contract TrailsIntentEntrypoint is ReentrancyGuard, ITrailsIntentEntrypoint {
3636
error InvalidIntentAddress();
3737
error IntentExpired();
3838
error InvalidIntentSignature();
39-
error IntentAlreadyUsed();
4039
error InvalidNonce();
4140
error PermitAmountMismatch();
4241

@@ -51,9 +50,6 @@ contract TrailsIntentEntrypoint is ReentrancyGuard, ITrailsIntentEntrypoint {
5150
// State Variables
5251
// -------------------------------------------------------------------------
5352

54-
/// @notice Tracks whether an intent digest has been consumed to prevent replays.
55-
mapping(bytes32 => bool) public usedIntents;
56-
5753
/// @notice Tracks nonce for each user to prevent replay attacks.
5854
mapping(address => uint256) public nonces;
5955

@@ -203,9 +199,6 @@ contract TrailsIntentEntrypoint is ReentrancyGuard, ITrailsIntentEntrypoint {
203199
address recovered = ECDSA.recover(digest, sigV, sigR, sigS);
204200
if (recovered != user) revert InvalidIntentSignature();
205201

206-
if (usedIntents[digest]) revert IntentAlreadyUsed();
207-
usedIntents[digest] = true;
208-
209202
// Increment nonce for the user
210203
nonces[user]++;
211204
}

src/interfaces/ITrailsIntentEntrypoint.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ interface ITrailsIntentEntrypoint {
3737
/// forge-lint: disable-next-line(mixed-case-function)
3838
function VERSION() external view returns (string memory);
3939

40-
/// @notice Returns whether an intent digest has already been consumed.
41-
/// @param digest The EIP-712 digest of the intent message.
42-
function usedIntents(bytes32 digest) external view returns (bool);
43-
4440
/// @notice Returns the current nonce for a given user.
4541
/// @param user The user address to query.
4642
function nonces(address user) external view returns (uint256);

test/TrailsIntentEntrypoint.t.sol

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,49 +1655,6 @@ contract TrailsIntentEntrypointTest is Test {
16551655
vm.stopPrank();
16561656
}
16571657

1658-
function testUsedIntentsMapping() public {
1659-
vm.startPrank(user);
1660-
1661-
address intentAddress = address(0x5678);
1662-
uint256 amount = 50 * 10 ** token.decimals();
1663-
uint256 deadline = block.timestamp + 3600;
1664-
uint256 nonce = entrypoint.nonces(user);
1665-
1666-
bytes32 intentHash = keccak256(
1667-
abi.encode(
1668-
entrypoint.TRAILS_INTENT_TYPEHASH(),
1669-
user,
1670-
address(token),
1671-
amount,
1672-
intentAddress,
1673-
deadline,
1674-
block.chainid,
1675-
nonce,
1676-
0, // feeAmount
1677-
address(0) // feeCollector
1678-
)
1679-
);
1680-
1681-
bytes32 intentDigest = keccak256(abi.encodePacked("\x19\x01", entrypoint.DOMAIN_SEPARATOR(), intentHash));
1682-
1683-
(uint8 sigV, bytes32 sigR, bytes32 sigS) = vm.sign(userPrivateKey, intentDigest);
1684-
1685-
token.approve(address(entrypoint), amount);
1686-
1687-
// Check that intent is not used initially
1688-
assertFalse(entrypoint.usedIntents(intentDigest));
1689-
1690-
// Execute intent
1691-
entrypoint.depositToIntent(
1692-
user, address(token), amount, intentAddress, deadline, nonce, 0, address(0), sigV, sigR, sigS
1693-
);
1694-
1695-
// Check that intent is now marked as used
1696-
assertTrue(entrypoint.usedIntents(intentDigest));
1697-
1698-
vm.stopPrank();
1699-
}
1700-
17011658
function testAssemblyCodeExecution() public {
17021659
vm.startPrank(user);
17031660

@@ -1732,9 +1689,6 @@ contract TrailsIntentEntrypointTest is Test {
17321689
user, address(token), amount, intentAddress, deadline, nonce, 0, address(0), sigV, sigR, sigS
17331690
);
17341691

1735-
// Verify the intent was processed correctly
1736-
assertTrue(entrypoint.usedIntents(intentDigest));
1737-
17381692
vm.stopPrank();
17391693
}
17401694

test/script/TrailsIntentEntrypoint.s.t.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,5 @@ contract TrailsIntentEntrypointDeploymentTest is Test {
108108
// Verify constants are set correctly
109109
assertEq(entrypoint.VERSION(), "1", "Version should be 1");
110110
assertTrue(entrypoint.TRAILS_INTENT_TYPEHASH() != bytes32(0), "Intent typehash should be set");
111-
112-
// Verify contract has expected storage layout by checking usedIntents mapping
113-
// This is a smoke test that the contract is properly initialized
114-
bytes32 testIntentHash = keccak256("test");
115-
assertEq(entrypoint.usedIntents(testIntentHash), false, "usedIntents should be false for unused intent");
116111
}
117112
}

0 commit comments

Comments
 (0)