Skip to content

Commit 11be832

Browse files
committed
Add setCallerSafe functions
1 parent 4e5ba50 commit 11be832

10 files changed

+37
-21
lines changed

snapshots/ERC7914Test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"approveNative": "45972",
33
"approveNativeTransient": "24024",
4-
"transferFromNative": "31978"
4+
"transferFromNative": "32000"
55
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"hanldeOps_BATCHED_CALL_singleCall_P256": "209177",
3-
"hanldeOps_BATCHED_CALL_singleCall_eoaSigner": "184203"
2+
"hanldeOps_BATCHED_CALL_singleCall_P256": "209199",
3+
"hanldeOps_BATCHED_CALL_singleCall_eoaSigner": "184225"
44
}
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"execute_BATCHED_CALL_SUPPORTS_OPDATA_singleCall": "92976",
3-
"execute_BATCHED_CALL_SUPPORTS_OPDATA_twoCalls": "129584",
4-
"execute_BATCHED_CALL_opData_P256_singleCall": "118288",
5-
"execute_BATCHED_CALL_opData_singleCall": "92976",
6-
"execute_BATCHED_CALL_opData_singleCall_native": "93806",
7-
"execute_BATCHED_CALL_opData_twoCalls": "129584",
8-
"execute_BATCHED_CALL_singleCall": "59622",
9-
"execute_BATCHED_CALL_singleCall_native": "59701",
10-
"execute_BATCHED_CALL_twoCalls": "95416",
11-
"execute_invalidMode_reverts": "23019",
12-
"multicall": "178542"
2+
"execute_BATCHED_CALL_SUPPORTS_OPDATA_singleCall": "92998",
3+
"execute_BATCHED_CALL_SUPPORTS_OPDATA_twoCalls": "129606",
4+
"execute_BATCHED_CALL_opData_P256_singleCall": "118310",
5+
"execute_BATCHED_CALL_opData_singleCall": "92998",
6+
"execute_BATCHED_CALL_opData_singleCall_native": "93828",
7+
"execute_BATCHED_CALL_opData_twoCalls": "129606",
8+
"execute_BATCHED_CALL_singleCall": "59644",
9+
"execute_BATCHED_CALL_singleCall_native": "59723",
10+
"execute_BATCHED_CALL_twoCalls": "95438",
11+
"execute_invalidMode_reverts": "23041",
12+
"multicall": "178608"
1313
}

snapshots/MinimalDelegationTest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"minimalDelegationEntry bytecode size": "20885",
2+
"minimalDelegationEntry bytecode size": "20997",
33
"register": "184758",
4-
"revoke": "54560",
4+
"revoke": "54578",
55
"validateUserOp_missingAccountFunds": "64567",
66
"validateUserOp_no_missingAccountFunds": "33929"
77
}

snapshots/NonceManagerTest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"invalidateNonce": "45378"
2+
"invalidateNonce": "45400"
33
}

src/ERC1271.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract contract ERC1271 is IERC1271, BaseAuthorization {
1616

1717
/// @dev Returns whether the caller is considered safe, such
1818
/// that we don't need to use the nested EIP-712 workflow as defined by ERC-7739
19-
function _isSafeERC1271Caller(address caller) internal view virtual returns (bool) {
19+
function isSafeERC1271Caller(address caller) public view virtual returns (bool) {
2020
return _erc1271CallerIsSafe[caller];
2121
}
2222

src/MinimalDelegation.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ contract MinimalDelegation is
201201
// Must be branched because we do abi decoding in memory which will throw since the encoding schemes are different
202202
// ECDSA signatures are 65 bytes while P256 signatures are 64 bytes
203203
if (signature.length == 64 || signature.length == 65) {
204-
if (_isSafeERC1271Caller(msg.sender)) {
204+
if (isSafeERC1271Caller(msg.sender)) {
205205
// If the caller is safe we can simply verify the key's signature over `data`
206206
// Data is already hashed with the app's domain separator so we don't rehash
207207
isValid = key.verify(data, signature);

src/interfaces/IERC1271.sol

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ interface IERC1271 {
66
/// @notice Sets whether the caller is considered safe to skip the nested EIP-712 workflow
77
function setERC1271CallerIsSafe(address caller, bool isSafe) external;
88

9+
/// @notice Returns whether the caller is considered safe to skip the nested EIP-712 workflow
10+
function isSafeERC1271Caller(address caller) external view returns (bool);
11+
912
/// @notice Validates the `signature` against the given `hash`.
1013
/// @dev Wraps the given `hash` in a EIP-712 compliant struct along with the domain separator to be replay safe. Then validates the signature against it.
1114
/// @return result `0x1626ba7e` if validation succeeded, else `0xffffffff`.

src/libraries/ERC7739Utils.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ library ERC7739Utils {
1919
/// @param hash The hashed message, calculated offchain
2020
/// @param domainSeparator This account's domain separator
2121
/// @return The PersonalSign nested EIP-712 hash of the message
22-
function toPersonalSignTypedDataHash(bytes32 hash, bytes32 domainSeparator) internal view returns (bytes32) {
22+
function toPersonalSignTypedDataHash(bytes32 hash, bytes32 domainSeparator) internal pure returns (bytes32) {
2323
return MessageHashUtils.toTypedDataHash(domainSeparator, PersonalSignLib.hash(hash));
2424
}
2525

@@ -36,7 +36,7 @@ library ERC7739Utils {
3636
bytes32 appSeparator,
3737
string memory contentsName,
3838
string memory contentsType
39-
) internal view returns (bytes32) {
39+
) internal pure returns (bytes32) {
4040
bytes32 typedDataSignHash = TypedDataSignLib.hash(contentsName, contentsType, contentsHash, domainBytes);
4141
return MessageHashUtils.toTypedDataHash(appSeparator, typedDataSignHash);
4242
}

test/MinimalDelegation.t.sol

+13
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,19 @@ contract MinimalDelegationTest is DelegationHandler, HookHandler {
242242
assertEq(address(keySettings.hook()), address(0));
243243
}
244244

245+
function test_setERC1271CallerIsSafe() public {
246+
address caller = makeAddr("caller");
247+
vm.prank(address(signerAccount));
248+
signerAccount.setERC1271CallerIsSafe(caller, true);
249+
assertEq(signerAccount.isSafeERC1271Caller(caller), true);
250+
}
251+
252+
function test_setERC1271CallerIsSafe_revertsWithUnauthorized() public {
253+
address caller = makeAddr("caller");
254+
vm.expectRevert(BaseAuthorization.Unauthorized.selector);
255+
signerAccount.setERC1271CallerIsSafe(caller, true);
256+
}
257+
245258
function test_entryPoint_defaultValue() public view {
246259
assertEq(signerAccount.ENTRY_POINT(), Constants.ENTRY_POINT_V_0_8);
247260
}

0 commit comments

Comments
 (0)