Skip to content

Commit

Permalink
✅ Fix test to fail from old deadline not arithmetic underflow (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyskylark authored Nov 4, 2022
1 parent f2833c7 commit 8d910d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ ERC1155Test:testSafeTransferFromToEOA(uint256,uint256,bytes,uint256,address,byte
ERC1155Test:testSafeTransferFromToERC1155Recipient() (gas: 739583)
ERC1155Test:testSafeTransferFromToERC1155Recipient(uint256,uint256,bytes,uint256,bytes) (runs: 256, μ: 769591, ~: 765729)
ERC20Invariants:invariantBalanceSum() (runs: 256, calls: 3840, reverts: 2388)
ERC20Test:invariantMetadata() (runs: 256, calls: 3840, reverts: 2606)
ERC20Test:invariantMetadata() (runs: 256, calls: 3840, reverts: 2583)
ERC20Test:testApprove() (gas: 31058)
ERC20Test:testApprove(address,uint256) (runs: 256, μ: 30424, ~: 31280)
ERC20Test:testBurn() (gas: 56970)
ERC20Test:testBurn(address,uint256,uint256) (runs: 256, μ: 56678, ~: 59645)
ERC20Test:testFailBurnInsufficientBalance(address,uint256,uint256) (runs: 256, μ: 51897, ~: 55492)
ERC20Test:testFailPermitBadDeadline() (gas: 36924)
ERC20Test:testFailPermitBadDeadline() (gas: 36935)
ERC20Test:testFailPermitBadDeadline(uint256,address,uint256,uint256) (runs: 256, μ: 32148, ~: 37218)
ERC20Test:testFailPermitBadNonce() (gas: 36874)
ERC20Test:testFailPermitBadNonce(uint256,address,uint256,uint256,uint256) (runs: 256, μ: 31628, ~: 37187)
ERC20Test:testFailPermitPastDeadline() (gas: 10938)
ERC20Test:testFailPermitPastDeadline() (gas: 11191)
ERC20Test:testFailPermitPastDeadline(uint256,address,uint256,uint256) (runs: 256, μ: 12037, ~: 13101)
ERC20Test:testFailPermitReplay() (gas: 66285)
ERC20Test:testFailPermitReplay() (gas: 66274)
ERC20Test:testFailPermitReplay(uint256,address,uint256,uint256) (runs: 256, μ: 57071, ~: 66592)
ERC20Test:testFailTransferFromInsufficientAllowance() (gas: 80882)
ERC20Test:testFailTransferFromInsufficientAllowance(address,uint256,uint256) (runs: 256, μ: 79858, ~: 83393)
Expand All @@ -137,15 +137,15 @@ ERC20Test:testFailTransferFromInsufficientBalance(address,uint256,uint256) (runs
ERC20Test:testFailTransferInsufficientBalance() (gas: 52806)
ERC20Test:testFailTransferInsufficientBalance(address,uint256,uint256) (runs: 256, μ: 51720, ~: 55310)
ERC20Test:testInfiniteApproveTransferFrom() (gas: 89793)
ERC20Test:testMetadata(string,string,uint8) (runs: 256, μ: 870618, ~: 863277)
ERC20Test:testMetadata(string,string,uint8) (runs: 256, μ: 869914, ~: 863277)
ERC20Test:testMint() (gas: 53746)
ERC20Test:testMint(address,uint256) (runs: 256, μ: 52214, ~: 53925)
ERC20Test:testPermit() (gas: 63193)
ERC20Test:testPermit(uint248,address,uint256,uint256) (runs: 256, μ: 62584, ~: 63517)
ERC20Test:testTransfer() (gas: 60272)
ERC20Test:testTransfer(address,uint256) (runs: 256, μ: 58773, ~: 60484)
ERC20Test:testTransferFrom() (gas: 83777)
ERC20Test:testTransferFrom(address,uint256,uint256) (runs: 256, μ: 86464, ~: 92841)
ERC20Test:testTransferFrom(address,uint256,uint256) (runs: 256, μ: 86308, ~: 92841)
ERC4626Test:invariantMetadata() (runs: 256, calls: 3840, reverts: 2885)
ERC4626Test:testFailDepositWithNoApproval() (gas: 13357)
ERC4626Test:testFailDepositWithNotEnoughApproval() (gas: 86993)
Expand Down
6 changes: 4 additions & 2 deletions src/test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ contract ERC20Test is DSTestPlus {
}

function testFailPermitPastDeadline() public {
uint256 oldTimestamp = block.timestamp;
uint256 privateKey = 0xBEEF;
address owner = hevm.addr(privateKey);

Expand All @@ -181,12 +182,13 @@ contract ERC20Test is DSTestPlus {
abi.encodePacked(
"\x19\x01",
token.DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner, address(0xCAFE), 1e18, 0, block.timestamp - 1))
keccak256(abi.encode(PERMIT_TYPEHASH, owner, address(0xCAFE), 1e18, 0, oldTimestamp))
)
)
);

token.permit(owner, address(0xCAFE), 1e18, block.timestamp - 1, v, r, s);
hevm.warp(block.timestamp + 1);
token.permit(owner, address(0xCAFE), 1e18, oldTimestamp, v, r, s);
}

function testFailPermitReplay() public {
Expand Down

0 comments on commit 8d910d8

Please sign in to comment.