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

Skip timestamp check when deadline/expiration is set to maximum amount #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .forge-snapshots/batchTransferFrom.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61797
61935
2 changes: 1 addition & 1 deletion .forge-snapshots/batchTransferFromMultiToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
81786
81878
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60346
60413
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65533
65600
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60811
60878
2 changes: 1 addition & 1 deletion .forge-snapshots/permitBatchCleanWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
91924
91967
2 changes: 1 addition & 1 deletion .forge-snapshots/permitBatchDirtyWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57724
57767
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143387
143430
2 changes: 1 addition & 1 deletion .forge-snapshots/permitBatchTransferFromSingleToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
88867
88910
2 changes: 1 addition & 1 deletion .forge-snapshots/permitCleanWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
63119
63162
2 changes: 1 addition & 1 deletion .forge-snapshots/permitCompactSig.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
63094
63137
2 changes: 1 addition & 1 deletion .forge-snapshots/permitDirtyNonce.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44014
44057
2 changes: 1 addition & 1 deletion .forge-snapshots/permitDirtyWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46019
46062
2 changes: 1 addition & 1 deletion .forge-snapshots/permitInvalidSigner.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
40301
40344
2 changes: 1 addition & 1 deletion .forge-snapshots/permitSetMaxAllowanceCleanWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61114
61157
2 changes: 1 addition & 1 deletion .forge-snapshots/permitSetMaxAllowanceDirtyWrite.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44014
44057
2 changes: 1 addition & 1 deletion .forge-snapshots/permitSignatureExpired.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31700
31743
2 changes: 1 addition & 1 deletion .forge-snapshots/permitTransferFromBatchTypedWitness.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120325
120368
2 changes: 1 addition & 1 deletion .forge-snapshots/permitTransferFromCompactSig.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
86066
86109
2 changes: 1 addition & 1 deletion .forge-snapshots/permitTransferFromSingleToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
86092
86135
2 changes: 1 addition & 1 deletion .forge-snapshots/permitTransferFromTypedWitness.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
87817
87860
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60811
60878
2 changes: 1 addition & 1 deletion .forge-snapshots/single recipient 2 tokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118525
118568
2 changes: 1 addition & 1 deletion .forge-snapshots/single recipient many tokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133544
133587
2 changes: 1 addition & 1 deletion .forge-snapshots/transferFrom with different owners.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61886
61978
2 changes: 1 addition & 1 deletion .forge-snapshots/transferFrom.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52197
52243
146 changes: 73 additions & 73 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,108 +1,108 @@
AllowanceTransferInvariants:invariant_balanceEqualsSpent() (runs: 256, calls: 3840, reverts: 879)
AllowanceTransferInvariants:invariant_permit2NeverHoldsBalance() (runs: 256, calls: 3840, reverts: 878)
AllowanceTransferInvariants:invariant_spendNeverExceedsPermit() (runs: 256, calls: 3840, reverts: 881)
AllowanceTransferInvariants:invariant_balanceEqualsSpent() (runs: 256, calls: 3840, reverts: 900)
AllowanceTransferInvariants:invariant_permit2NeverHoldsBalance() (runs: 256, calls: 3840, reverts: 913)
AllowanceTransferInvariants:invariant_spendNeverExceedsPermit() (runs: 256, calls: 3840, reverts: 906)
AllowanceTransferTest:testApprove() (gas: 47570)
AllowanceTransferTest:testBatchTransferFrom() (gas: 159197)
AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235094)
AllowanceTransferTest:testBatchTransferFromMultiToken() (gas: 231841)
AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 159857)
AllowanceTransferTest:testExcessiveInvalidation() (gas: 64205)
AllowanceTransferTest:testInvalidateMultipleNonces() (gas: 83150)
AllowanceTransferTest:testInvalidateNonces() (gas: 62847)
AllowanceTransferTest:testBatchTransferFrom() (gas: 159378)
AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235272)
AllowanceTransferTest:testBatchTransferFromMultiToken() (gas: 231976)
AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 160038)
AllowanceTransferTest:testExcessiveInvalidation() (gas: 64248)
AllowanceTransferTest:testInvalidateMultipleNonces() (gas: 83236)
AllowanceTransferTest:testInvalidateNonces() (gas: 62890)
AllowanceTransferTest:testInvalidateNoncesInvalid() (gas: 16327)
AllowanceTransferTest:testLockdown() (gas: 145984)
AllowanceTransferTest:testLockdownEvent() (gas: 117749)
AllowanceTransferTest:testMaxAllowance() (gas: 134888)
AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117455)
AllowanceTransferTest:testPartialAllowance() (gas: 105140)
AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69154)
AllowanceTransferTest:testSetAllowance() (gas: 89627)
AllowanceTransferTest:testSetAllowanceBatch() (gas: 133740)
AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118603)
AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99210)
AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 116049)
AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89587)
AllowanceTransferTest:testSetAllowanceDeadlinePassed() (gas: 56512)
AllowanceTransferTest:testSetAllowanceDirtyWrite() (gas: 72175)
AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29198)
AllowanceTransferTest:testSetAllowanceInvalidSignature() (gas: 64065)
AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103115)
AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97194)
AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 132867)
AllowanceTransferTest:testLockdown() (gas: 146027)
AllowanceTransferTest:testLockdownEvent() (gas: 117792)
AllowanceTransferTest:testMaxAllowance() (gas: 134977)
AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117544)
AllowanceTransferTest:testPartialAllowance() (gas: 105229)
AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69240)
AllowanceTransferTest:testSetAllowance() (gas: 89670)
AllowanceTransferTest:testSetAllowanceBatch() (gas: 133783)
AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118689)
AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99253)
AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 116092)
AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89630)
AllowanceTransferTest:testSetAllowanceDeadlinePassed() (gas: 56547)
AllowanceTransferTest:testSetAllowanceDirtyWrite() (gas: 72218)
AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29241)
AllowanceTransferTest:testSetAllowanceInvalidSignature() (gas: 64108)
AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103204)
AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97283)
AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 132956)
AllowanceUnitTest:testPackAndUnpack(uint160,uint48,uint48) (runs: 256, μ: 39025, ~: 39103)
AllowanceUnitTest:testUpdateAllRandomly(uint160,uint48,uint48) (runs: 256, μ: 40243, ~: 40244)
AllowanceUnitTest:testUpdateAmountExpirationRandomly(uint160,uint48) (runs: 256, μ: 39169, ~: 39170)
CompactSignature:testCompactSignature27() (gas: 300)
CompactSignature:testCompactSignature28() (gas: 144)
DeployPermit2Test:testAllowanceTransferSanityCheck() (gas: 101876)
DeployPermit2Test:testDeployPermit2() (gas: 4337527)
DeployPermit2Test:testSignatureTransferSanityCheck() (gas: 92792)
DeployPermit2Test:testAllowanceTransferSanityCheck() (gas: 101965)
DeployPermit2Test:testDeployPermit2() (gas: 4435732)
DeployPermit2Test:testSignatureTransferSanityCheck() (gas: 92835)
EIP712Test:testDomainSeparator() (gas: 5881)
EIP712Test:testDomainSeparatorAfterFork() (gas: 10830)
MockPermit2Lib:testPermit2Code(address):(bool) (runs: 256, μ: 3003, ~: 3016)
MockPermit2Lib:testPermit2Code(address) (runs: 256, μ: 3029, ~: 3016)
NonceBitmapTest:testHighNonces() (gas: 36305)
NonceBitmapTest:testInvalidateFullWord() (gas: 63061)
NonceBitmapTest:testInvalidateNoncesRandomly(uint248,uint256) (runs: 256, μ: 30439, ~: 31139)
NonceBitmapTest:testInvalidateNonzeroWord() (gas: 85642)
NonceBitmapTest:testInvalidateTwoNoncesRandomly(uint248,uint256,uint256) (runs: 256, μ: 39182, ~: 39182)
NonceBitmapTest:testLowNonces() (gas: 41041)
NonceBitmapTest:testNonceWordBoundary() (gas: 42284)
NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, μ: 49190, ~: 51625)
NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, μ: 21935, ~: 21960)
NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, μ: 49105, ~: 51625)
NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, μ: 21932, ~: 21951)
Permit2LibTest:testOZSafePermit() (gas: 24682)
Permit2LibTest:testOZSafePermitPlusOZSafeTransferFrom() (gas: 129329)
Permit2LibTest:testOZSafeTransferFrom() (gas: 39007)
Permit2LibTest:testPermit2() (gas: 22941)
Permit2LibTest:testPermit2DSLessToken() (gas: 7143)
Permit2LibTest:testPermit2DSMore32Token() (gas: 7252)
Permit2LibTest:testPermit2DSMoreToken() (gas: 7023)
Permit2LibTest:testPermit2Full() (gas: 42356)
Permit2LibTest:testPermit2Full() (gas: 42399)
Permit2LibTest:testPermit2InvalidAmount() (gas: 21011)
Permit2LibTest:testPermit2LargerDS() (gas: 51464)
Permit2LibTest:testPermit2LargerDSRevert() (gas: 32841)
Permit2LibTest:testPermit2NonPermitFallback() (gas: 37245)
Permit2LibTest:testPermit2NonPermitToken() (gas: 32164)
Permit2LibTest:testPermit2LargerDS() (gas: 51507)
Permit2LibTest:testPermit2LargerDSRevert() (gas: 32884)
Permit2LibTest:testPermit2NonPermitFallback() (gas: 37288)
Permit2LibTest:testPermit2NonPermitToken() (gas: 32207)
Permit2LibTest:testPermit2PlusTransferFrom2() (gas: 126995)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 148221)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermitFallback() (gas: 174749)
Permit2LibTest:testPermit2PlusTransferFrom2WithWETH9Mainnet() (gas: 147934)
Permit2LibTest:testPermit2SmallerDS() (gas: 77688)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 148288)
Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermitFallback() (gas: 174816)
Permit2LibTest:testPermit2PlusTransferFrom2WithWETH9Mainnet() (gas: 148001)
Permit2LibTest:testPermit2SmallerDS() (gas: 77731)
Permit2LibTest:testPermit2SmallerDSNoRevert() (gas: 59324)
Permit2LibTest:testPermit2WETH9Mainnet() (gas: 28774)
Permit2LibTest:testSimplePermit2() (gas: 29117)
Permit2LibTest:testPermit2WETH9Mainnet() (gas: 28817)
Permit2LibTest:testSimplePermit2() (gas: 29160)
Permit2LibTest:testSimplePermit2InvalidAmount() (gas: 16944)
Permit2LibTest:testSimplePermit2PlusTransferFrom2WithNonPermit() (gas: 148463)
Permit2LibTest:testSimplePermit2PlusTransferFrom2WithNonPermit() (gas: 148530)
Permit2LibTest:testStandardPermit() (gas: 22535)
Permit2LibTest:testStandardTransferFrom() (gas: 38143)
Permit2LibTest:testTransferFrom2() (gas: 38734)
Permit2LibTest:testTransferFrom2Full() (gas: 53368)
Permit2LibTest:testTransferFrom2Full() (gas: 53392)
Permit2LibTest:testTransferFrom2InvalidAmount() (gas: 12732)
Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53170)
Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53194)
SignatureTransferTest:testCorrectWitnessTypehashes() (gas: 3091)
SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 270972)
SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 183860)
SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 123854)
SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41396)
SignatureTransferTest:testPermitBatchMultiPermitSingleTransfer() (gas: 133675)
SignatureTransferTest:testPermitBatchTransferFrom() (gas: 162019)
SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 187957)
SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 239926)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84489)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86007)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 85751)
SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 41574)
SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160547)
SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 209422)
SignatureTransferTest:testPermitTransferFrom() (gas: 92909)
SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124059)
SignatureTransferTest:testPermitTransferFromIncorrectSigLength() (gas: 51346)
SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 72928)
SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, μ: 95752, ~: 96728)
SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93283)
SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125159)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 55947)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 56879)
SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, μ: 97604, ~: 99733)
SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 271015)
SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 183903)
SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 123897)
SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41430)
SignatureTransferTest:testPermitBatchMultiPermitSingleTransfer() (gas: 133718)
SignatureTransferTest:testPermitBatchTransferFrom() (gas: 162062)
SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 188000)
SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 240053)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84546)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86050)
SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 85878)
SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 41617)
SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160590)
SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 209465)
SignatureTransferTest:testPermitTransferFrom() (gas: 92952)
SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124102)
SignatureTransferTest:testPermitTransferFromIncorrectSigLength() (gas: 51389)
SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 73014)
SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, μ: 95618, ~: 96771)
SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93326)
SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125139)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 55927)
SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 56922)
SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, μ: 97881, ~: 99776)
TypehashGeneration:testPermitBatch() (gas: 40473)
TypehashGeneration:testPermitBatchTransferFrom() (gas: 49837)
TypehashGeneration:testPermitBatchTransferFromWithWitness() (gas: 56621)
Expand Down
12 changes: 9 additions & 3 deletions src/AllowanceTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ contract AllowanceTransfer is IAllowanceTransfer, EIP712 {

/// @inheritdoc IAllowanceTransfer
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external {
if (block.timestamp > permitSingle.sigDeadline) revert SignatureExpired(permitSingle.sigDeadline);
if (permitSingle.sigDeadline != type(uint256).max && block.timestamp > permitSingle.sigDeadline) {
revert SignatureExpired(permitSingle.sigDeadline);
}

// Verify the signer address from the signature.
signature.verify(_hashTypedData(permitSingle.hash()), owner);
Expand All @@ -41,7 +43,9 @@ contract AllowanceTransfer is IAllowanceTransfer, EIP712 {

/// @inheritdoc IAllowanceTransfer
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external {
if (block.timestamp > permitBatch.sigDeadline) revert SignatureExpired(permitBatch.sigDeadline);
if (permitBatch.sigDeadline != type(uint256).max && block.timestamp > permitBatch.sigDeadline) {
revert SignatureExpired(permitBatch.sigDeadline);
}

// Verify the signer address from the signature.
signature.verify(_hashTypedData(permitBatch.hash()), owner);
Expand Down Expand Up @@ -76,7 +80,9 @@ contract AllowanceTransfer is IAllowanceTransfer, EIP712 {
function _transfer(address from, address to, uint160 amount, address token) private {
PackedAllowance storage allowed = allowance[from][token][msg.sender];

if (block.timestamp > allowed.expiration) revert AllowanceExpired(allowed.expiration);
if (allowed.expiration != type(uint48).max && block.timestamp > allowed.expiration) {
revert AllowanceExpired(allowed.expiration);
}

uint256 maxAmount = allowed.amount;
if (maxAmount != type(uint160).max) {
Expand Down
8 changes: 6 additions & 2 deletions src/SignatureTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ contract SignatureTransfer is ISignatureTransfer, EIP712 {
) private {
uint256 requestedAmount = transferDetails.requestedAmount;

if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline);
if (permit.deadline != type(uint256).max && block.timestamp > permit.deadline) {
revert SignatureExpired(permit.deadline);
}
if (requestedAmount > permit.permitted.amount) revert InvalidAmount(permit.permitted.amount);

_useUnorderedNonce(owner, permit.nonce);
Expand Down Expand Up @@ -105,7 +107,9 @@ contract SignatureTransfer is ISignatureTransfer, EIP712 {
) private {
uint256 numPermitted = permit.permitted.length;

if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline);
if (permit.deadline != type(uint256).max && block.timestamp > permit.deadline) {
revert SignatureExpired(permit.deadline);
}
if (numPermitted != transferDetails.length) revert LengthMismatch();

_useUnorderedNonce(owner, permit.nonce);
Expand Down
2 changes: 1 addition & 1 deletion test/utils/DeployPermit2.sol

Large diffs are not rendered by default.