Skip to content

Commit 33ea111

Browse files
Amxxernestognw
andauthored
Avoid validating ECDSA signatures for addresses with code in SignatureChecker (#4951)
Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent 6b4ec6c commit 33ea111

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.changeset/yellow-moles-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`SignatureChecker`: refactor `isValidSignatureNow` to avoid validating ECDSA signatures if there is code deployed at the signer's address.

contracts/utils/cryptography/SignatureChecker.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ library SignatureChecker {
2020
* change through time. It could return true at block N and false at block N+1 (or the opposite).
2121
*/
2222
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
23-
(address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
24-
return
25-
(error == ECDSA.RecoverError.NoError && recovered == signer) ||
26-
isValidERC1271SignatureNow(signer, hash, signature);
23+
if (signer.code.length == 0) {
24+
(address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(hash, signature);
25+
return err == ECDSA.RecoverError.NoError && recovered == signer;
26+
} else {
27+
return isValidERC1271SignatureNow(signer, hash, signature);
28+
}
2729
}
2830

2931
/**

0 commit comments

Comments
 (0)