Skip to content

Commit 8514b2f

Browse files
authored
Add EIP 1271 support to smart accounts. (#385)
* Add ERC-1271 * Add EIP 1271 support to smart accounts
1 parent 4252c37 commit 8514b2f

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

contracts/eip/ERC1271.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache 2.0
2+
pragma solidity ^0.8.0;
3+
4+
abstract contract ERC1271 {
5+
// bytes4(keccak256("isValidSignature(bytes32,bytes)")
6+
bytes4 internal constant MAGICVALUE = 0x1626ba7e;
7+
8+
/**
9+
* @dev Should return whether the signature provided is valid for the provided hash
10+
* @param _hash Hash of the data to be signed
11+
* @param _signature Signature byte array associated with _hash
12+
*
13+
* MUST return the bytes4 magic value 0x1626ba7e when function passes.
14+
* MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)
15+
* MUST allow external calls
16+
*/
17+
function isValidSignature(bytes32 _hash, bytes memory _signature) public view virtual returns (bytes4 magicValue);
18+
}

contracts/smart-wallet/non-upgradeable/Account.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import "../../dynamic-contracts/extension/PermissionsEnumerable.sol";
1515
import "../../dynamic-contracts/extension/ContractMetadata.sol";
1616
import "../../openzeppelin-presets/token/ERC721/utils/ERC721Holder.sol";
1717
import "../../openzeppelin-presets/token/ERC1155/utils/ERC1155Holder.sol";
18+
import "../../eip/ERC1271.sol";
1819

1920
// Utils
2021
import "../../openzeppelin-presets/utils/cryptography/ECDSA.sol";
@@ -31,6 +32,7 @@ import "./AccountFactory.sol";
3132

3233
contract Account is
3334
Initializable,
35+
ERC1271,
3436
Multicall,
3537
BaseAccount,
3638
ContractMetadata,
@@ -106,6 +108,20 @@ contract Account is
106108
return hasRole(SIGNER_ROLE, _signer) || hasRole(DEFAULT_ADMIN_ROLE, _signer);
107109
}
108110

111+
/// @notice See EIP-1271
112+
function isValidSignature(bytes32 _hash, bytes memory _signature)
113+
public
114+
view
115+
virtual
116+
override
117+
returns (bytes4 magicValue)
118+
{
119+
address signer = _hash.recover(_signature);
120+
if (isValidSigner(signer)) {
121+
magicValue = MAGICVALUE;
122+
}
123+
}
124+
109125
/*///////////////////////////////////////////////////////////////
110126
External functions
111127
//////////////////////////////////////////////////////////////*/

contracts/smart-wallet/utils/AccountCore.sol

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "./../utils/BaseAccount.sol";
1111
// Fixed Extensions
1212
import "../../extension/Multicall.sol";
1313
import "../../dynamic-contracts/extension/Initializable.sol";
14+
import "../../eip/ERC1271.sol";
1415

1516
// Utils
1617
import "../../openzeppelin-presets/utils/cryptography/ECDSA.sol";
@@ -25,7 +26,7 @@ import "../../dynamic-contracts/extension/PermissionsEnumerable.sol";
2526
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
2627
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
2728

28-
contract AccountCore is Initializable, Multicall, BaseAccount {
29+
contract AccountCore is Initializable, Multicall, BaseAccount, ERC1271 {
2930
using ECDSA for bytes32;
3031

3132
/*///////////////////////////////////////////////////////////////
@@ -73,6 +74,20 @@ contract AccountCore is Initializable, Multicall, BaseAccount {
7374
return _hasRole(SIGNER_ROLE, _signer) || _hasRole(DEFAULT_ADMIN_ROLE, _signer);
7475
}
7576

77+
/// @notice See EIP-1271
78+
function isValidSignature(bytes32 _hash, bytes memory _signature)
79+
public
80+
view
81+
virtual
82+
override
83+
returns (bytes4 magicValue)
84+
{
85+
address signer = _hash.recover(_signature);
86+
if (isValidSigner(signer)) {
87+
magicValue = MAGICVALUE;
88+
}
89+
}
90+
7691
/*///////////////////////////////////////////////////////////////
7792
External functions
7893
//////////////////////////////////////////////////////////////*/

0 commit comments

Comments
 (0)