Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d5691b

Browse files
committed
EIP712 signature for isValidSignature
1 parent 76d5e39 commit 3d5691b

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

contracts/prebuilts/account/non-upgradeable/Account.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
7272
bytes32 _hash,
7373
bytes memory _signature
7474
) public view virtual override returns (bytes4 magicValue) {
75-
bytes32 typedDataHash = keccak256(abi.encode(MSG_TYPEHASH, _hash));
76-
bytes32 targetDigest = keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), typedDataHash));
77-
75+
bytes32 targetDigest = getMessageHash(_hash);
7876
address signer = targetDigest.recover(_signature);
7977

8078
if (isAdmin(signer)) {
@@ -96,11 +94,11 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
9694

9795
/**
9896
* @notice Returns the hash of message that should be signed for EIP1271 verification.
99-
* @param _message The raw abi encoded data to hash and sign i.e. `abi.encode(data)`
100-
* @return Hashed message
97+
* @param _hash The message hash to sign for the EIP-1271 origin verifying contract.
98+
* @return messageHash The digest to sign for EIP-1271 verification.
10199
*/
102-
function getMessageHash(bytes memory _message) public view returns (bytes32) {
103-
bytes32 messageHash = keccak256(_message);
100+
function getMessageHash(bytes32 _hash) public view returns (bytes32) {
101+
bytes32 messageHash = keccak256(abi.encode(_hash));
104102
bytes32 typedDataHash = keccak256(abi.encode(MSG_TYPEHASH, messageHash));
105103
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), typedDataHash));
106104
}

contracts/prebuilts/account/utils/AccountExtension.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ contract AccountExtension is ContractMetadata, ERC1271, AccountPermissions, ERC7
7474
bytes32 _hash,
7575
bytes memory _signature
7676
) public view virtual override returns (bytes4 magicValue) {
77-
bytes32 typedDataHash = keccak256(abi.encode(MSG_TYPEHASH, _hash));
78-
bytes32 targetDigest = keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), typedDataHash));
79-
77+
bytes32 targetDigest = getMessageHash(_hash);
8078
address signer = targetDigest.recover(_signature);
8179

8280
if (isAdmin(signer)) {
@@ -98,11 +96,11 @@ contract AccountExtension is ContractMetadata, ERC1271, AccountPermissions, ERC7
9896

9997
/**
10098
* @notice Returns the hash of message that should be signed for EIP1271 verification.
101-
* @param _message The raw abi encoded data to hash and sign i.e. `abi.encode(data)`
102-
* @return Hashed message
99+
* @param _hash The message hash to sign for the EIP-1271 origin verifying contract.
100+
* @return messageHash The digest to sign for EIP-1271 verification.
103101
*/
104-
function getMessageHash(bytes memory _message) public view returns (bytes32) {
105-
bytes32 messageHash = keccak256(_message);
102+
function getMessageHash(bytes32 _hash) public view returns (bytes32) {
103+
bytes32 messageHash = keccak256(abi.encode(_hash));
106104
bytes32 typedDataHash = keccak256(abi.encode(MSG_TYPEHASH, messageHash));
107105
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), typedDataHash));
108106
}

src/test/smart-wallet/AccountVulnPOC.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ contract SimpleAccountVulnPOCTest is BaseTest {
278278

279279
// However they can bypass this by using signature verification on number contract instead
280280
vm.prank(accountSigner);
281-
bytes memory data = abi.encode(42);
282-
bytes32 toSign = SimpleAccount(payable(account)).getMessageHash(data);
281+
bytes32 digest = keccak256(abi.encode(42));
282+
bytes32 toSign = SimpleAccount(payable(account)).getMessageHash(digest);
283283
(uint8 v, bytes32 r, bytes32 s) = vm.sign(accountSignerPKey, toSign);
284284
bytes memory signature = abi.encodePacked(r, s, v);
285285

0 commit comments

Comments
 (0)