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

[CHAIN-50] use try/catch for EIP-1271 signature verification #14

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Changes from 4 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
16 changes: 10 additions & 6 deletions smart-wallets/src/extensions/SignedOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.25;

import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";

Expand Down Expand Up @@ -196,14 +195,19 @@ contract SignedOperations is EIP712, WalletUtils, ISignedOperations {
abi.encode(SIGNED_OPERATIONS_TYPEHASH, targets, calls, values, nonce, nonceDependency, expiresAt)
);
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != address(this)) {
bytes memory signature = abi.encodePacked(r, s, v);
if (IERC1271(msg.sender).isValidSignature(hash, signature) != MAGICVALUE) {

try IERC1271(msg.sender).isValidSignature(hash, abi.encodePacked(r, s, v)) returns (bytes4 magicValue) {
if (magicValue != MAGICVALUE) {
revert InvalidSigner(nonce, msg.sender);
}
$.nonces[nonce] = 1;
} catch {
address signer = ECDSA.recover(hash, v, r, s);
if (signer != address(this)) {
revert InvalidSigner(nonce, signer);
}
$.nonces[nonce] = 1;
}
$.nonces[nonce] = 1;
}

for (uint256 i = 0; i < length; i++) {
Expand Down