Vectorized / solady

Optimized Solidity snippets.
MIT License
2.6k stars 348 forks source link

⚡️ Optimize SignatureCheckerLib #1153

Closed Vectorized closed 3 weeks ago

Vectorized commented 3 weeks ago

Description

⚡️

Checklist

Ensure you completed all of the steps below before submitting your pull request:

Pull requests with an incomplete checklist will be thrown out.

github-actions[bot] commented 3 weeks ago

Gas Snapshot Comparison Report

Generated at commit : fc9857602689ea90d4e678c7e875bc4adfd69713, Compared to commit : f479f475e387ffcbf02f3c80eee61e92365e501c

Contract Name Test Name Main Gas PR Gas Diff
ECDSATest testBytesToEthSignedMessageHash() 11582453 11582252 -201
testBytesToEthSignedMessageHashExceedsMaxLengthReverts() 615885 615401 -484
testCanonicalHashCalldataWith64bytesSignature() 1232939 1231595 -1344
testCanonicalHashCalldataWithRegularSignature() 1232433 1231838 -595
testCanonicalHashWith64bytesSignature() 614272 613875 -397
testCanonicalHashWithRegularSignature() 612711 612227 -484
testEmptyCalldataHelpers() 3268 588 -2680
testRecoverWithInvalidLongSignatureReverts() 7395 4743 -2652
testRecoverWithInvalidShortSignatureReturnsZero() 7231 4579 -2652
testRecoverWithInvalidSignatureReverts() 8018 8025 7
testRecoverWithV0SignatureWithShortEIP2098FormatAsCalldata() 8731 8744 13
testRecoverWithV0SignatureWithVersion00Reverts() 7983 7990 7
testRecoverWithV0SignatureWithVersion27() 8875 8861 -14
testRecoverWithV0SignatureWithWrongVersionReverts() 7983 7990 7
testRecoverWithV1SignatureWithShortEIP2098FormatAsCalldata() 8707 8720 13
testRecoverWithV1SignatureWithVersion01Reverts() 7928 7935 7
testRecoverWithV1SignatureWithVersion28() 8920 8906 -14
testRecoverWithV1SignatureWithWrongVersionReverts() 7984 7991 7
testRecoverWithValidSignature() 9001 8987 -14
testRecoverWithWrongSigner() 8892 8878 -14
testTryRecoverWithInvalidLongSignatureReturnsZero() 5241 2399 -2842
testTryRecoverWithInvalidShortSignatureReturnsZero() 5112 2270 -2842
testTryRecoverWithInvalidSignature() 8965 8943 -22
testTryRecoverWithV0SignatureWithShortEIP2098FormatAsCalldata() 8776 8781 5
testTryRecoverWithV0SignatureWithVersion00ReturnsZero() 8850 8828 -22
testTryRecoverWithV0SignatureWithVersion27() 8828 8806 -22
testTryRecoverWithV0SignatureWithWrongVersionReturnsZero() 8895 8873 -22
testTryRecoverWithV1SignatureWithShortEIP2098FormatAsCalldata() 8798 8803 5
testTryRecoverWithV1SignatureWithVersion01ReturnsZero() 8852 8830 -22
testTryRecoverWithV1SignatureWithVersion28() 8829 8807 -22
testTryRecoverWithV1SignatureWithWrongVersionReturnsZero() 8872 8850 -22
testTryRecoverWithValidSignature() 8899 8877 -22
testTryRecoverWithWrongSigner() 8890 8868 -22
test__codesize() 18231 18224 -7
ERC1271Test testIsValidSignature() 3059605 3059687 82
test__codesize() 30943 30867 -76
ERC4337FactoryTest test__codesize() 13105 13067 -38
ERC4337Test testDisableInitializerForImplementation() 1346051 1338438 -7613
testIsValidSignature() 119103 119112 9
testIsValidSignatureWrapped() 490043 490244 201
testOwnerRecovery() 479629 479627 -2
testValidateUserOp() 484758 484764 6
test__codesize() 55991 55954 -37
ERC6551Test test__codesize() 50933 50857 -76
SignatureCheckerLibTest testERC6492AllowSideEffectsOnECDSA() 34031 - -
testERC6492AllowSideEffectsPostDeploy() 491567 492230 663
testERC6492AllowSideEffectsPreDeploy() 504353 504682 329
testERC6492OnECDSA() 33978 - -
testERC6492PostDeploy() 543011 543687 676
testERC6492PreDeploy() 1368735 1369498 763
testERC6492WithoutRevertingVerifier() 73709 74389 680
testEmptyCalldataHelpers() 3943 3918 -25
testEtchERC6492RevertingVerifier() 56427 56449 22
testSignatureCheckerOnEOAWithInvalidSignature() 21317 21362 45
testSignatureCheckerOnEOAWithInvalidSigner() 30795 30862 67
testSignatureCheckerOnEOAWithMatchingSignerAndSignature() 17781 17760 -21
testSignatureCheckerOnEOAWithWrongSignedMessageHash() 21296 21386 90
testSignatureCheckerOnMaliciousWallet() 31908 31953 45
testSignatureCheckerOnWalletWithInvalidSignature() 78934 78992 58
testSignatureCheckerOnWalletWithInvalidSigner() 26028 26095 67
testSignatureCheckerOnWalletWithMatchingSignerAndSignature() 66084 66073 -11
testSignatureCheckerOnWalletWithWrongSignedMessageHash() 66182 66127 -55
testSignatureCheckerOnWalletWithZeroAddressSigner() 12486 12451 -35
test__codesize() 17551 18465 914
testERC6492AllowSideEffectsOnEOA() - 38554 -
testERC6492OnEOA() - 34988 -
shuhuiluo commented 3 weeks ago

I believe a review is warranted given the amount of dependents.

Vectorized commented 3 weeks ago

2 ETH bug bounty up for SignatureCheckerLib and ECDSA at this commit.

I'm 100% confident.