diff --git a/.forge-snapshots/batchTransferFrom.snap b/.forge-snapshots/batchTransferFrom.snap index b6d31f54..31a61ef4 100644 --- a/.forge-snapshots/batchTransferFrom.snap +++ b/.forge-snapshots/batchTransferFrom.snap @@ -1 +1 @@ -62244 \ No newline at end of file +62268 \ No newline at end of file diff --git a/.forge-snapshots/batchTransferFromMultiToken.snap b/.forge-snapshots/batchTransferFromMultiToken.snap index fe3cb941..1b2f8533 100644 --- a/.forge-snapshots/batchTransferFromMultiToken.snap +++ b/.forge-snapshots/batchTransferFromMultiToken.snap @@ -1 +1 @@ -84076 \ No newline at end of file +84086 \ No newline at end of file diff --git a/.forge-snapshots/permit2 + transferFrom2 with a non EIP-2612 native token.snap b/.forge-snapshots/permit2 + transferFrom2 with a non EIP-2612 native token.snap index 8ec3ba45..5e30b82d 100644 --- a/.forge-snapshots/permit2 + transferFrom2 with a non EIP-2612 native token.snap +++ b/.forge-snapshots/permit2 + transferFrom2 with a non EIP-2612 native token.snap @@ -1 +1 @@ -60848 \ No newline at end of file +60864 \ No newline at end of file diff --git a/.forge-snapshots/permitBatchCleanWrite.snap b/.forge-snapshots/permitBatchCleanWrite.snap index b0fdcbe2..28017495 100644 --- a/.forge-snapshots/permitBatchCleanWrite.snap +++ b/.forge-snapshots/permitBatchCleanWrite.snap @@ -1 +1 @@ -91880 \ No newline at end of file +91885 \ No newline at end of file diff --git a/.forge-snapshots/permitBatchDirtyWrite.snap b/.forge-snapshots/permitBatchDirtyWrite.snap index 86c437f3..c01dd0d6 100644 --- a/.forge-snapshots/permitBatchDirtyWrite.snap +++ b/.forge-snapshots/permitBatchDirtyWrite.snap @@ -1 +1 @@ -57680 \ No newline at end of file +57685 \ No newline at end of file diff --git a/.forge-snapshots/permitBatchTransferFromMultipleTokens.snap b/.forge-snapshots/permitBatchTransferFromMultipleTokens.snap index 05f7c536..385d7c38 100644 --- a/.forge-snapshots/permitBatchTransferFromMultipleTokens.snap +++ b/.forge-snapshots/permitBatchTransferFromMultipleTokens.snap @@ -1 +1 @@ -143570 \ No newline at end of file +143590 \ No newline at end of file diff --git a/.forge-snapshots/permitBatchTransferFromSingleToken.snap b/.forge-snapshots/permitBatchTransferFromSingleToken.snap index 1c406119..f7fa1031 100644 --- a/.forge-snapshots/permitBatchTransferFromSingleToken.snap +++ b/.forge-snapshots/permitBatchTransferFromSingleToken.snap @@ -1 +1 @@ -88886 \ No newline at end of file +88896 \ No newline at end of file diff --git a/.forge-snapshots/permitCleanWrite.snap b/.forge-snapshots/permitCleanWrite.snap index b4c53d83..0956f181 100644 --- a/.forge-snapshots/permitCleanWrite.snap +++ b/.forge-snapshots/permitCleanWrite.snap @@ -1 +1 @@ -63133 \ No newline at end of file +63144 \ No newline at end of file diff --git a/.forge-snapshots/permitCompactSig.snap b/.forge-snapshots/permitCompactSig.snap index 062b7f42..2e52b388 100644 --- a/.forge-snapshots/permitCompactSig.snap +++ b/.forge-snapshots/permitCompactSig.snap @@ -1 +1 @@ -63081 \ No newline at end of file +63092 \ No newline at end of file diff --git a/.forge-snapshots/permitDirtyNonce.snap b/.forge-snapshots/permitDirtyNonce.snap index 669d90ea..1dd89bc1 100644 --- a/.forge-snapshots/permitDirtyNonce.snap +++ b/.forge-snapshots/permitDirtyNonce.snap @@ -1 +1 @@ -44028 \ No newline at end of file +44039 \ No newline at end of file diff --git a/.forge-snapshots/permitDirtyWrite.snap b/.forge-snapshots/permitDirtyWrite.snap index 6f85377a..a2bfb572 100644 --- a/.forge-snapshots/permitDirtyWrite.snap +++ b/.forge-snapshots/permitDirtyWrite.snap @@ -1 +1 @@ -46033 \ No newline at end of file +46044 \ No newline at end of file diff --git a/.forge-snapshots/permitInvalidSigner.snap b/.forge-snapshots/permitInvalidSigner.snap index c5c1dd82..740d6f2b 100644 --- a/.forge-snapshots/permitInvalidSigner.snap +++ b/.forge-snapshots/permitInvalidSigner.snap @@ -1 +1 @@ -40546 \ No newline at end of file +40557 \ No newline at end of file diff --git a/.forge-snapshots/permitSetMaxAllowanceCleanWrite.snap b/.forge-snapshots/permitSetMaxAllowanceCleanWrite.snap index 406d4c82..b6271785 100644 --- a/.forge-snapshots/permitSetMaxAllowanceCleanWrite.snap +++ b/.forge-snapshots/permitSetMaxAllowanceCleanWrite.snap @@ -1 +1 @@ -61128 \ No newline at end of file +61139 \ No newline at end of file diff --git a/.forge-snapshots/permitSetMaxAllowanceDirtyWrite.snap b/.forge-snapshots/permitSetMaxAllowanceDirtyWrite.snap index 669d90ea..1dd89bc1 100644 --- a/.forge-snapshots/permitSetMaxAllowanceDirtyWrite.snap +++ b/.forge-snapshots/permitSetMaxAllowanceDirtyWrite.snap @@ -1 +1 @@ -44028 \ No newline at end of file +44039 \ No newline at end of file diff --git a/.forge-snapshots/permitSignatureExpired.snap b/.forge-snapshots/permitSignatureExpired.snap index bc302f94..c991845e 100644 --- a/.forge-snapshots/permitSignatureExpired.snap +++ b/.forge-snapshots/permitSignatureExpired.snap @@ -1 +1 @@ -31354 \ No newline at end of file +31828 \ No newline at end of file diff --git a/.forge-snapshots/permitTransferFromBatchTypedWitness.snap b/.forge-snapshots/permitTransferFromBatchTypedWitness.snap index ffdcc2de..8c6dcce5 100644 --- a/.forge-snapshots/permitTransferFromBatchTypedWitness.snap +++ b/.forge-snapshots/permitTransferFromBatchTypedWitness.snap @@ -1 +1 @@ -120766 \ No newline at end of file +120781 \ No newline at end of file diff --git a/.forge-snapshots/permitTransferFromCompactSig.snap b/.forge-snapshots/permitTransferFromCompactSig.snap index a87188fc..597e2502 100644 --- a/.forge-snapshots/permitTransferFromCompactSig.snap +++ b/.forge-snapshots/permitTransferFromCompactSig.snap @@ -1 +1 @@ -88554 \ No newline at end of file +88573 \ No newline at end of file diff --git a/.forge-snapshots/permitTransferFromSingleToken.snap b/.forge-snapshots/permitTransferFromSingleToken.snap index ec60b725..3864b1f4 100644 --- a/.forge-snapshots/permitTransferFromSingleToken.snap +++ b/.forge-snapshots/permitTransferFromSingleToken.snap @@ -1 +1 @@ -88606 \ No newline at end of file +88625 \ No newline at end of file diff --git a/.forge-snapshots/permitTransferFromTypedWitness.snap b/.forge-snapshots/permitTransferFromTypedWitness.snap index ce761178..6dfadd01 100644 --- a/.forge-snapshots/permitTransferFromTypedWitness.snap +++ b/.forge-snapshots/permitTransferFromTypedWitness.snap @@ -1 +1 @@ -90427 \ No newline at end of file +90446 \ No newline at end of file diff --git a/.forge-snapshots/single recipient 2 tokens.snap b/.forge-snapshots/single recipient 2 tokens.snap index b4645763..f2c55abb 100644 --- a/.forge-snapshots/single recipient 2 tokens.snap +++ b/.forge-snapshots/single recipient 2 tokens.snap @@ -1 +1 @@ -118626 \ No newline at end of file +118641 \ No newline at end of file diff --git a/.forge-snapshots/single recipient many tokens.snap b/.forge-snapshots/single recipient many tokens.snap index f4deb7d4..cd40925e 100644 --- a/.forge-snapshots/single recipient many tokens.snap +++ b/.forge-snapshots/single recipient many tokens.snap @@ -1 +1 @@ -134304 \ No newline at end of file +134359 \ No newline at end of file diff --git a/.forge-snapshots/transferFrom with different owners.snap b/.forge-snapshots/transferFrom with different owners.snap index 5aeec884..6cf2e6fe 100644 --- a/.forge-snapshots/transferFrom with different owners.snap +++ b/.forge-snapshots/transferFrom with different owners.snap @@ -1 +1 @@ -62176 \ No newline at end of file +62186 \ No newline at end of file diff --git a/.forge-snapshots/transferFrom.snap b/.forge-snapshots/transferFrom.snap index a0952b25..93ea312f 100644 --- a/.forge-snapshots/transferFrom.snap +++ b/.forge-snapshots/transferFrom.snap @@ -1 +1 @@ -52354 \ No newline at end of file +52359 \ No newline at end of file diff --git a/.gas-snapshot b/.gas-snapshot index 05b7466c..42949d9a 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,87 +1,87 @@ AllowanceTransferTest:testApprove() (gas: 47747) -AllowanceTransferTest:testBatchTransferFrom() (gas: 159742) -AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235756) -AllowanceTransferTest:testBatchTransferFromMultiToken() (gas: 232008) -AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 160270) -AllowanceTransferTest:testExcessiveInvalidation() (gas: 64187) -AllowanceTransferTest:testInvalidateMultipleNonces() (gas: 83635) -AllowanceTransferTest:testInvalidateNonces() (gas: 63151) -AllowanceTransferTest:testInvalidateNoncesInvalid() (gas: 16308) -AllowanceTransferTest:testLockdown() (gas: 146051) -AllowanceTransferTest:testLockdownEvent() (gas: 117879) -AllowanceTransferTest:testMaxAllowance() (gas: 134990) -AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117579) -AllowanceTransferTest:testPartialAllowance() (gas: 105214) -AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69347) -AllowanceTransferTest:testSetAllowance() (gas: 89563) -AllowanceTransferTest:testSetAllowanceBatch() (gas: 133539) -AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118489) -AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99054) -AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 111671) -AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89496) -AllowanceTransferTest:testSetAllowanceDeadlinePassed() (gas: 56197) -AllowanceTransferTest:testSetAllowanceDirtyWrite() (gas: 72177) -AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29265) -AllowanceTransferTest:testSetAllowanceInvalidSignature() (gas: 64316) -AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103298) -AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97569) -AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 133141) -CompactSignature:testCompactSignature27() (gas: 231) +AllowanceTransferTest:testBatchTransferFrom() (gas: 159731) +AllowanceTransferTest:testBatchTransferFromDifferentOwners() (gas: 235810) +AllowanceTransferTest:testBatchTransferFromMultiToken() (gas: 232023) +AllowanceTransferTest:testBatchTransferFromWithGasSnapshot() (gas: 160281) +AllowanceTransferTest:testExcessiveInvalidation() (gas: 64220) +AllowanceTransferTest:testInvalidateMultipleNonces() (gas: 83657) +AllowanceTransferTest:testInvalidateNonces() (gas: 63184) +AllowanceTransferTest:testInvalidateNoncesInvalid() (gas: 16330) +AllowanceTransferTest:testLockdown() (gas: 146078) +AllowanceTransferTest:testLockdownEvent() (gas: 117884) +AllowanceTransferTest:testMaxAllowance() (gas: 135031) +AllowanceTransferTest:testMaxAllowanceDirtyWrite() (gas: 117620) +AllowanceTransferTest:testPartialAllowance() (gas: 105230) +AllowanceTransferTest:testReuseOrderedNonceInvalid() (gas: 69391) +AllowanceTransferTest:testSetAllowance() (gas: 89596) +AllowanceTransferTest:testSetAllowanceBatch() (gas: 133566) +AllowanceTransferTest:testSetAllowanceBatchDifferentNonces() (gas: 118533) +AllowanceTransferTest:testSetAllowanceBatchDirtyWrite() (gas: 99081) +AllowanceTransferTest:testSetAllowanceBatchEvent() (gas: 111698) +AllowanceTransferTest:testSetAllowanceCompactSig() (gas: 89529) +AllowanceTransferTest:testSetAllowanceDeadlinePassed() (gas: 56602) +AllowanceTransferTest:testSetAllowanceDirtyWrite() (gas: 72188) +AllowanceTransferTest:testSetAllowanceIncorrectSigLength() (gas: 29298) +AllowanceTransferTest:testSetAllowanceInvalidSignature() (gas: 64327) +AllowanceTransferTest:testSetAllowanceTransfer() (gas: 103336) +AllowanceTransferTest:testSetAllowanceTransferDirtyNonceDirtyTransfer() (gas: 97607) +AllowanceTransferTest:testTransferFromWithGasSnapshot() (gas: 133179) +CompactSignature:testCompactSignature27() (gas: 253) CompactSignature:testCompactSignature28() (gas: 141) -EIP712Test:testDomainSeparator() (gas: 5759) -EIP712Test:testDomainSeparatorAfterFork() (gas: 10696) -NonceBitmapTest:testHighNonces() (gas: 35936) -NonceBitmapTest:testInvalidateFullWord() (gas: 62827) +EIP712Test:testDomainSeparator() (gas: 5781) +EIP712Test:testDomainSeparatorAfterFork() (gas: 10718) +NonceBitmapTest:testHighNonces() (gas: 35958) +NonceBitmapTest:testInvalidateFullWord() (gas: 62849) NonceBitmapTest:testInvalidateNonzeroWord() (gas: 85329) -NonceBitmapTest:testLowNonces() (gas: 40649) -NonceBitmapTest:testNonceWordBoundary() (gas: 42024) -NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, μ: 49067, ~: 51501) -NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, μ: 21758, ~: 21780) -Permit2LibTest:testOZSafePermit() (gas: 24421) -Permit2LibTest:testOZSafePermitPlusOZSafeTransferFrom() (gas: 129137) -Permit2LibTest:testOZSafeTransferFrom() (gas: 38853) -Permit2LibTest:testPermit2() (gas: 22715) -Permit2LibTest:testPermit2DSLessToken() (gas: 6796) -Permit2LibTest:testPermit2DSMore32Token() (gas: 6883) -Permit2LibTest:testPermit2DSMoreToken() (gas: 6786) -Permit2LibTest:testPermit2Full() (gas: 42049) -Permit2LibTest:testPermit2InvalidAmount() (gas: 20423) -Permit2LibTest:testPermit2LargerDS() (gas: 51018) -Permit2LibTest:testPermit2LargerDSRevert() (gas: 32735) -Permit2LibTest:testPermit2NonPermitToken() (gas: 31858) -Permit2LibTest:testPermit2PlusTransferFrom2() (gas: 126838) -Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 147975) -Permit2LibTest:testPermit2SmallerDS() (gas: 77505) +NonceBitmapTest:testLowNonces() (gas: 40671) +NonceBitmapTest:testNonceWordBoundary() (gas: 42042) +NonceBitmapTest:testUseTwoRandomNonces(uint256,uint256) (runs: 256, μ: 48918, ~: 51523) +NonceBitmapTest:testUsingNonceTwiceFails(uint256) (runs: 256, μ: 21775, ~: 21798) +Permit2LibTest:testOZSafePermit() (gas: 24443) +Permit2LibTest:testOZSafePermitPlusOZSafeTransferFrom() (gas: 129153) +Permit2LibTest:testOZSafeTransferFrom() (gas: 38875) +Permit2LibTest:testPermit2() (gas: 22737) +Permit2LibTest:testPermit2DSLessToken() (gas: 6818) +Permit2LibTest:testPermit2DSMore32Token() (gas: 6905) +Permit2LibTest:testPermit2DSMoreToken() (gas: 6808) +Permit2LibTest:testPermit2Full() (gas: 42082) +Permit2LibTest:testPermit2InvalidAmount() (gas: 20445) +Permit2LibTest:testPermit2LargerDS() (gas: 51051) +Permit2LibTest:testPermit2LargerDSRevert() (gas: 32768) +Permit2LibTest:testPermit2NonPermitToken() (gas: 31891) +Permit2LibTest:testPermit2PlusTransferFrom2() (gas: 126854) +Permit2LibTest:testPermit2PlusTransferFrom2WithNonPermit() (gas: 148007) +Permit2LibTest:testPermit2SmallerDS() (gas: 77516) Permit2LibTest:testPermit2SmallerDSNoRevert() (gas: 59230) -Permit2LibTest:testStandardPermit() (gas: 22230) -Permit2LibTest:testStandardTransferFrom() (gas: 38055) -Permit2LibTest:testTransferFrom2() (gas: 38492) -Permit2LibTest:testTransferFrom2Full() (gas: 53349) +Permit2LibTest:testStandardPermit() (gas: 22252) +Permit2LibTest:testStandardTransferFrom() (gas: 38077) +Permit2LibTest:testTransferFrom2() (gas: 38514) +Permit2LibTest:testTransferFrom2Full() (gas: 53376) Permit2LibTest:testTransferFrom2InvalidAmount() (gas: 12666) -Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53195) +Permit2LibTest:testTransferFrom2NonPermitToken() (gas: 53222) SignatureTransferTest:testCorrectWitnessTypehashes() (gas: 3075) -SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 271080) -SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 186313) -SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 123961) -SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41180) -SignatureTransferTest:testPermitBatchMultiPermitSingleTransfer() (gas: 133684) -SignatureTransferTest:testPermitBatchTransferFrom() (gas: 162111) -SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 190398) -SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 240201) -SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84705) -SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86164) -SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 85907) -SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 43812) -SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160485) -SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 212581) -SignatureTransferTest:testPermitTransferFrom() (gas: 93052) -SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124010) -SignatureTransferTest:testPermitTransferFromIncorrectSigLength() (gas: 51305) -SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 73275) -SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, μ: 95708, ~: 96684) -SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93360) -SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125534) -SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 56077) -SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 56961) -SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, μ: 98021, ~: 99739) +SignatureTransferTest:testGasMultiplePermitBatchTransferFrom() (gas: 271122) +SignatureTransferTest:testGasSinglePermitBatchTransferFrom() (gas: 186345) +SignatureTransferTest:testGasSinglePermitTransferFrom() (gas: 124002) +SignatureTransferTest:testInvalidateUnorderedNonces() (gas: 41213) +SignatureTransferTest:testPermitBatchMultiPermitSingleTransfer() (gas: 133699) +SignatureTransferTest:testPermitBatchTransferFrom() (gas: 162126) +SignatureTransferTest:testPermitBatchTransferFromSingleRecipient() (gas: 190435) +SignatureTransferTest:testPermitBatchTransferFromTypedWitness() (gas: 240313) +SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidType() (gas: 84785) +SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidTypeHash() (gas: 86191) +SignatureTransferTest:testPermitBatchTransferFromTypedWitnessInvalidWitness() (gas: 86009) +SignatureTransferTest:testPermitBatchTransferInvalidAmountsLengthMismatch() (gas: 43839) +SignatureTransferTest:testPermitBatchTransferMultiAddr() (gas: 160522) +SignatureTransferTest:testPermitBatchTransferSingleRecipientManyTokens() (gas: 212658) +SignatureTransferTest:testPermitTransferFrom() (gas: 93071) +SignatureTransferTest:testPermitTransferFromCompactSig() (gas: 124051) +SignatureTransferTest:testPermitTransferFromIncorrectSigLength() (gas: 51324) +SignatureTransferTest:testPermitTransferFromInvalidNonce() (gas: 73335) +SignatureTransferTest:testPermitTransferFromRandomNonceAndAmount(uint256,uint128) (runs: 256, μ: 95749, ~: 96725) +SignatureTransferTest:testPermitTransferFromToSpender() (gas: 93401) +SignatureTransferTest:testPermitTransferFromTypedWitness() (gas: 125525) +SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidType() (gas: 56093) +SignatureTransferTest:testPermitTransferFromTypedWitnessInvalidTypehash() (gas: 57002) +SignatureTransferTest:testPermitTransferSpendLessThanFull(uint256,uint128) (runs: 256, μ: 98062, ~: 99780) MockPermit2Lib:testPermit2Code(address):(bool) (runs: 256, μ: 2911, ~: 2911) diff --git a/lib/forge-std b/lib/forge-std index e8e3dbfb..27e14b7f 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e8e3dbfb870c8457ca77343173509f6d899df63d +Subproject commit 27e14b7f2448e5f5ac32719f51fe652aa0b0733e diff --git a/src/AllowanceTransfer.sol b/src/AllowanceTransfer.sol index 7e16182a..8baebdde 100644 --- a/src/AllowanceTransfer.sol +++ b/src/AllowanceTransfer.sol @@ -31,7 +31,7 @@ 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(); + if (block.timestamp > permitSingle.sigDeadline) revert SignatureExpired(permitSingle.sigDeadline); // Verify the signer address from the signature. signature.verify(_hashTypedData(permitSingle.hash()), owner); @@ -41,7 +41,7 @@ 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(); + if (block.timestamp > permitBatch.sigDeadline) revert SignatureExpired(permitBatch.sigDeadline); // Verify the signer address from the signature. signature.verify(_hashTypedData(permitBatch.hash()), owner); @@ -76,12 +76,12 @@ contract AllowanceTransfer is IAllowanceTransfer, EIP712 { function _transfer(address token, address from, address to, uint160 amount) private { PackedAllowance storage allowed = allowance[from][token][msg.sender]; - if (block.timestamp > allowed.expiration) revert AllowanceExpired(); + if (block.timestamp > allowed.expiration) revert AllowanceExpired(allowed.expiration); uint256 maxAmount = allowed.amount; if (maxAmount != type(uint160).max) { if (amount > maxAmount) { - revert InsufficientAllowance(); + revert InsufficientAllowance(maxAmount); } else { unchecked { allowed.amount = uint160(maxAmount) - amount; diff --git a/src/PermitErrors.sol b/src/PermitErrors.sol index a165aab2..2c42e2d1 100644 --- a/src/PermitErrors.sol +++ b/src/PermitErrors.sol @@ -3,5 +3,9 @@ pragma solidity 0.8.17; /// @notice Shared errors between signature based transfers and allowance based transfers. -error SignatureExpired(); +/// @notice Thrown when validating an inputted signature that is stale +/// @param signatureDeadline The timestamp at which a signature is no longer valid +error SignatureExpired(uint256 signatureDeadline); + +/// @notice Thrown when validating that the inputted nonce has not been used error InvalidNonce(); diff --git a/src/SignatureTransfer.sol b/src/SignatureTransfer.sol index c8a55618..8d7d094c 100644 --- a/src/SignatureTransfer.sol +++ b/src/SignatureTransfer.sol @@ -60,8 +60,8 @@ contract SignatureTransfer is ISignatureTransfer, EIP712 { uint256 requestedAmount, bytes calldata signature ) internal { - if (block.timestamp > permit.deadline) revert SignatureExpired(); - if (requestedAmount > permit.permitted.amount) revert InvalidAmount(); + if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline); + if (requestedAmount > permit.permitted.amount) revert InvalidAmount(permit.permitted.amount); _useUnorderedNonce(owner, permit.nonce); signature.verify(_hashTypedData(dataHash), owner); @@ -108,7 +108,7 @@ contract SignatureTransfer is ISignatureTransfer, EIP712 { ) internal { uint256 numPermitted = permit.permitted.length; - if (block.timestamp > permit.deadline) revert SignatureExpired(); + if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline); if (numPermitted != transferDetails.length) revert LengthMismatch(); _useUnorderedNonce(owner, permit.nonce); @@ -119,7 +119,7 @@ contract SignatureTransfer is ISignatureTransfer, EIP712 { TokenPermissions memory permitted = permit.permitted[i]; uint256 requestedAmount = transferDetails[i].requestedAmount; - if (requestedAmount > permitted.amount) revert InvalidAmount(); + if (requestedAmount > permitted.amount) revert InvalidAmount(permitted.amount); if (requestedAmount != 0) { // allow spender to specify which of the permitted tokens should be transferred diff --git a/src/interfaces/IAllowanceTransfer.sol b/src/interfaces/IAllowanceTransfer.sol index a7967209..e129793a 100644 --- a/src/interfaces/IAllowanceTransfer.sol +++ b/src/interfaces/IAllowanceTransfer.sol @@ -5,8 +5,10 @@ pragma solidity ^0.8.17; /// @notice Handles ERC20 token transfers through signature based actions /// @dev Requires user's token approval on the Permit2 contract interface IAllowanceTransfer { - error AllowanceExpired(); - error InsufficientAllowance(); + /// @param deadline The timestamp at which the allowed amount is no longer valid + error AllowanceExpired(uint256 deadline); + /// @param amount The maximum amount allowed + error InsufficientAllowance(uint256 amount); error ExcessiveInvalidation(); /// @notice Emits an event when the owner successfully invalidates an ordered nonce. diff --git a/src/interfaces/ISignatureTransfer.sol b/src/interfaces/ISignatureTransfer.sol index 1f20a9a2..d4a318e9 100644 --- a/src/interfaces/ISignatureTransfer.sol +++ b/src/interfaces/ISignatureTransfer.sol @@ -5,8 +5,9 @@ pragma solidity ^0.8.17; /// @notice Handles ERC20 token transfers through signature based actions /// @dev Requires user's token approval on the Permit2 contract interface ISignatureTransfer { + /// @param maxAmount The maximum amount a spender can request to transfer + error InvalidAmount(uint256 maxAmount); error NotSpender(); - error InvalidAmount(); error LengthMismatch(); /// @notice Emits an event when the owner successfully invalidates an unordered nonce. diff --git a/src/libraries/SignatureVerification.sol b/src/libraries/SignatureVerification.sol index 811745e9..ea46f80e 100644 --- a/src/libraries/SignatureVerification.sol +++ b/src/libraries/SignatureVerification.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.17; import {IERC1271} from "../interfaces/IERC1271.sol"; library SignatureVerification { + error InvalidSignatureLength(); error InvalidSignature(); error InvalidSigner(); error InvalidContractSignature(); @@ -26,7 +27,7 @@ library SignatureVerification { s = vs & UPPER_BIT_MASK; v = uint8(uint256(vs >> 255)) + 27; } else { - revert InvalidSignature(); + revert InvalidSignatureLength(); } address signer = ecrecover(hash, v, r, s); if (signer == address(0)) revert InvalidSignature(); diff --git a/test/AllowanceTransferTest.t.sol b/test/AllowanceTransferTest.t.sol index 3eae9c09..fe8ad981 100644 --- a/test/AllowanceTransferTest.t.sol +++ b/test/AllowanceTransferTest.t.sol @@ -126,7 +126,7 @@ contract AllowanceTransferTest is Test, TokenProvider, PermitSignature, GasSnaps bytes memory sigExtra = bytes.concat(sig, bytes1(uint8(1))); assertEq(sigExtra.length, 66); - vm.expectRevert(SignatureVerification.InvalidSignature.selector); + vm.expectRevert(SignatureVerification.InvalidSignatureLength.selector); permit2.permit(from, permit, sigExtra); } @@ -351,9 +351,11 @@ contract AllowanceTransferTest is Test, TokenProvider, PermitSignature, GasSnaps defaultERC20PermitAllowance(address(token0), defaultAmount, defaultExpiration, defaultNonce); bytes memory sig = getPermitSignature(permit, fromPrivateKey, DOMAIN_SEPARATOR); + uint256 sigDeadline = block.timestamp + 100; + vm.warp(block.timestamp + 101); snapStart("permitSignatureExpired"); - vm.expectRevert(SignatureExpired.selector); + vm.expectRevert(abi.encodeWithSelector(SignatureExpired.selector, sigDeadline)); permit2.permit(from, permit, sig); snapEnd(); } @@ -472,20 +474,20 @@ contract AllowanceTransferTest is Test, TokenProvider, PermitSignature, GasSnaps // Valid permit, uses nonce 0. permit2.permit(from, permit, sig); - (,, uint48 nonce) = permit2.allowance(from, address(token0), address(this)); - assertEq(nonce, 1); + (,, uint48 nonce1) = permit2.allowance(from, address(token0), address(this)); + assertEq(nonce1, 1); - permit = defaultERC20PermitAllowance(address(token1), defaultAmount, defaultExpiration, nonce); + permit = defaultERC20PermitAllowance(address(token1), defaultAmount, defaultExpiration, nonce1); sig = getPermitSignature(permit, fromPrivateKey, DOMAIN_SEPARATOR); // Invalidates the 9 nonces by setting the new nonce to 33. vm.prank(from); vm.expectEmit(true, true, true, true); - emit NonceInvalidation(from, address(token0), address(this), 33, nonce); + emit NonceInvalidation(from, address(token0), address(this), 33, nonce1); permit2.invalidateNonces(address(token0), address(this), 33); - (,, nonce) = permit2.allowance(from, address(token0), address(this)); - assertEq(nonce, 33); + (,, uint48 nonce2) = permit2.allowance(from, address(token0), address(this)); + assertEq(nonce2, 33); vm.expectRevert(InvalidNonce.selector); permit2.permit(from, permit, sig); diff --git a/test/SignatureTransfer.t.sol b/test/SignatureTransfer.t.sol index 089e9022..f37f223a 100644 --- a/test/SignatureTransfer.t.sol +++ b/test/SignatureTransfer.t.sol @@ -123,7 +123,7 @@ contract SignatureTransferTest is Test, PermitSignature, TokenProvider, GasSnaps bytes memory sigExtra = bytes.concat(sig, bytes1(uint8(0))); assertEq(sigExtra.length, 66); - vm.expectRevert(SignatureVerification.InvalidSignature.selector); + vm.expectRevert(SignatureVerification.InvalidSignatureLength.selector); permit2.permitTransferFrom(permit, from, address2, defaultAmount, sigExtra); }