Skip to content

Commit 2523cb7

Browse files
authored
Merge pull request #7 from base-org/amie/fix-isValidSignature
Remove unnecessary selector check from `isValidSignature`
2 parents cbfe0c0 + 2f25c50 commit 2523cb7

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

src/EIP7702Proxy.sol

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,44 +72,38 @@ contract EIP7702Proxy is Proxy {
7272
bytes32 hash,
7373
bytes calldata signature
7474
) external returns (bytes4) {
75-
if (msg.sig == ERC1271_ISVALIDSIGNATURE_SELECTOR) {
76-
(bytes32 hash, bytes memory signature) = abi.decode(
77-
msg.data[4:],
78-
(bytes32, bytes)
79-
);
80-
81-
// First try delegatecall to implementation
82-
(bool success, bytes memory result) = _implementation()
83-
.delegatecall(msg.data);
84-
85-
// If delegatecall succeeded and returned magic value, return that
86-
if (
87-
success &&
88-
result.length == 32 &&
89-
abi.decode(result, (bytes4)) == ERC1271_MAGIC_VALUE
90-
) {
75+
// First try delegatecall to implementation
76+
(bool success, bytes memory result) = _implementation().delegatecall(
77+
msg.data
78+
);
79+
80+
// If delegatecall succeeded and returned magic value, return that
81+
if (
82+
success &&
83+
result.length == 32 &&
84+
abi.decode(result, (bytes4)) == ERC1271_MAGIC_VALUE
85+
) {
86+
assembly {
87+
mstore(0, ERC1271_MAGIC_VALUE)
88+
return(0, 32)
89+
}
90+
}
91+
92+
// Only try ECDSA if signature is the right length (65 bytes)
93+
if (signature.length == 65) {
94+
address recovered = ECDSA.recover(hash, signature);
95+
if (recovered == address(this)) {
9196
assembly {
9297
mstore(0, ERC1271_MAGIC_VALUE)
9398
return(0, 32)
9499
}
95100
}
101+
}
96102

97-
// Only try ECDSA if signature is the right length (65 bytes)
98-
if (signature.length == 65) {
99-
address recovered = ECDSA.recover(hash, signature);
100-
if (recovered == address(this)) {
101-
assembly {
102-
mstore(0, ERC1271_MAGIC_VALUE)
103-
return(0, 32)
104-
}
105-
}
106-
}
107-
108-
// If all checks fail, return failure value
109-
assembly {
110-
mstore(0, ERC1271_FAIL_VALUE)
111-
return(0, 32)
112-
}
103+
// If all checks fail, return failure value
104+
assembly {
105+
mstore(0, ERC1271_FAIL_VALUE)
106+
return(0, 32)
113107
}
114108
}
115109

0 commit comments

Comments
 (0)