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

⚡️ Optimize ERC6492 workflow #1163

Merged
merged 3 commits into from
Nov 9, 2024
Merged
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
23 changes: 12 additions & 11 deletions src/utils/SignatureCheckerLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,16 @@ library SignatureCheckerLib {
_isValid := staticcall(gas(), signer_, m_, add(returndatasize(), 0x44), d_, 0x20)
_isValid := and(eq(mload(d_), f_), _isValid)
}
let noCode := iszero(extcodesize(signer))
let n := mload(signature)
for {} 1 {} {
if iszero(eq(mload(add(signature, n)), mul(0x6492, div(not(isValid), 0xffff)))) {
isValid := callIsValidSignature(signer, hash, signature)
if iszero(noCode) { isValid := callIsValidSignature(signer, hash, signature) }
break
}
let o := add(signature, 0x20) // Signature bytes.
let d := add(o, mload(add(o, 0x20))) // Factory calldata.
if iszero(extcodesize(signer)) {
if noCode {
if iszero(call(gas(), mload(o), 0, add(d, 0x20), mload(d), codesize(), 0x00)) {
break
}
Expand All @@ -339,14 +340,14 @@ library SignatureCheckerLib {
isValid := callIsValidSignature(signer, hash, s)
if iszero(isValid) {
if call(gas(), mload(o), 0, add(d, 0x20), mload(d), codesize(), 0x00) {
isValid := callIsValidSignature(signer, hash, s)
noCode := iszero(extcodesize(signer))
if iszero(noCode) { isValid := callIsValidSignature(signer, hash, s) }
}
}
break
}
// `ecrecover` fallback.
for {} iszero(isValid) {} {
if extcodesize(signer) { break } // Skip if `signer` is a contract.
// Do `ecrecover` fallback if `noCode && !isValid`.
for {} gt(noCode, isValid) {} {
switch n
case 64 {
let vs := mload(add(signature, 0x40))
Expand Down Expand Up @@ -396,13 +397,14 @@ library SignatureCheckerLib {
_isValid := staticcall(gas(), signer_, m_, add(returndatasize(), 0x44), d_, 0x20)
_isValid := and(eq(mload(d_), f_), _isValid)
}
let noCode := iszero(extcodesize(signer))
let n := mload(signature)
for {} 1 {} {
if iszero(eq(mload(add(signature, n)), mul(0x6492, div(not(isValid), 0xffff)))) {
isValid := callIsValidSignature(signer, hash, signature)
if iszero(noCode) { isValid := callIsValidSignature(signer, hash, signature) }
break
}
if extcodesize(signer) {
if iszero(noCode) {
let o := add(signature, 0x20) // Signature bytes.
isValid := callIsValidSignature(signer, hash, add(o, mload(add(o, 0x40))))
if isValid { break }
Expand All @@ -423,9 +425,8 @@ library SignatureCheckerLib {
isValid := gt(returndatasize(), willBeZeroIfRevertingVerifierExists)
break
}
// `ecrecover` fallback.
for {} iszero(isValid) {} {
if extcodesize(signer) { break } // Skip if `signer` is a contract.
// Do `ecrecover` fallback if `noCode && !isValid`.
for {} gt(noCode, isValid) {} {
switch n
case 64 {
let vs := mload(add(signature, 0x40))
Expand Down