Skip to content

Commit 2a49590

Browse files
Merge pull request #49 from EnsoBuild/fix-enso-receiver-signer
fix: use correct eth signed message on enso receiver
2 parents e1d0012 + 715a1ff commit 2a49590

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/delegate/EnsoReceiver.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { IERC4337CloneInitializer } from "../factory/interfaces/IERC4337CloneIni
77
import { IERC20, Withdrawable } from "../utils/Withdrawable.sol";
88
import { SIG_VALIDATION_FAILED, SIG_VALIDATION_SUCCESS } from "account-abstraction-v7/core/Helpers.sol";
99
import { IAccount, PackedUserOperation } from "account-abstraction-v7/interfaces/IAccount.sol";
10-
1110
import { Initializable } from "openzeppelin-contracts/proxy/utils/Initializable.sol";
1211
import { ReentrancyGuardTransient } from "openzeppelin-contracts/utils/ReentrancyGuardTransient.sol";
1312
import { ECDSA } from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";
13+
import { MessageHashUtils } from "openzeppelin-contracts/utils/cryptography/MessageHashUtils.sol";
1414
import { SignatureChecker } from "openzeppelin-contracts/utils/cryptography/SignatureChecker.sol";
1515

1616
contract EnsoReceiver is
@@ -105,7 +105,8 @@ contract EnsoReceiver is
105105
// First attempt ECDSA recovery to support EOAs and EIP-7702 accounts, which may have contract code but still
106106
// use standard ECDSA signatures.
107107
// If ECDSA recovery fails, fall back to ERC-1271 for traditional smart contract wallets.
108-
(address recovered, ECDSA.RecoverError errors,) = ECDSA.tryRecover(userOpHash, userOp.signature);
108+
bytes32 ethSignedMessageHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
109+
(address recovered, ECDSA.RecoverError errors,) = ECDSA.tryRecover(ethSignedMessageHash, userOp.signature);
109110
if (errors == ECDSA.RecoverError.NoError && recovered == signer) {
110111
return SIG_VALIDATION_SUCCESS;
111112
}

test/fork/enso-checkout/Checkout_EOA_EntryPointV7_Fork_Test.t.sol

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { ERC4337CloneFactory } from "../../../src/factory/ERC4337CloneFactory.so
77
import { SignaturePaymaster } from "../../../src/paymaster/SignaturePaymaster.sol";
88
import { Shortcut } from "../../shortcuts/ShortcutDataTypes.sol";
99
import { ShortcutsEthereum } from "../../shortcuts/ShortcutsEthereum.sol";
10-
1110
import { PackedUserOperationLib } from "../../utils/AccountAbstraction.sol";
12-
1311
import { TokenBalanceHelper } from "../../utils/TokenBalanceHelper.sol";
1412
import { EntryPoint } from "account-abstraction-v7/core/EntryPoint.sol";
1513
import { IEntryPoint, PackedUserOperation } from "account-abstraction-v7/interfaces/IEntryPoint.sol";
@@ -161,7 +159,8 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
161159

162160
// UserOp.signature - Sign the userOpHash with EOA_1's private key
163161
bytes32 userOpHash = s_entryPoint.getUserOpHash(userOp);
164-
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), userOpHash);
162+
bytes32 ethSignedUserOpHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
163+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), ethSignedUserOpHash);
165164
bytes memory signature = abi.encodePacked(r, s, v);
166165
userOp.signature = signature;
167166

@@ -257,13 +256,13 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
257256
assertBalanceDiff(
258257
balancePreEntryPointPaymaster,
259258
balancePostEntryPointPaymaster,
260-
-2_064_097_182_089_268,
259+
-2_064_454_742_903_391,
261260
"EntryPoint Paymaster balance (ETH)"
262261
);
263262
assertBalanceDiff(
264263
balancePreEntryPointTokenIn,
265264
balancePostEntryPointTokenIn,
266-
-2_064_097_182_089_268,
265+
-2_064_454_742_903_391,
267266
"EntryPoint TokenIn (ETH)"
268267
);
269268
assertBalanceDiff(balancePreEntryPointTokenOut, balancePostEntryPointTokenOut, 0, "EntryPoint TokenOut (WETH)");
@@ -345,7 +344,8 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
345344

346345
// UserOp.signature - Sign the userOpHash with EOA_1's private key
347346
bytes32 userOpHash = s_entryPoint.getUserOpHash(userOp);
348-
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), userOpHash);
347+
bytes32 ethSignedUserOpHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
348+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), ethSignedUserOpHash);
349349
bytes memory signature = abi.encodePacked(r, s, v);
350350
userOp.signature = signature;
351351

@@ -435,13 +435,13 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
435435
assertBalanceDiff(
436436
balancePreEntryPointPaymaster,
437437
balancePostEntryPointPaymaster,
438-
-1_820_822_410_271_403,
438+
-1_821_179_971_085_526,
439439
"EntryPoint Paymaster balance (ETH)"
440440
);
441441
assertBalanceDiff(
442442
balancePreEntryPointTokenIn,
443443
balancePostEntryPointTokenIn,
444-
-1_820_822_410_271_403,
444+
-1_821_179_971_085_526,
445445
"EntryPoint TokenIn (ETH)"
446446
);
447447
assertBalanceDiff(balancePreEntryPointTokenOut, balancePostEntryPointTokenOut, 0, "EntryPoint TokenOut (WETH)");
@@ -518,7 +518,8 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
518518

519519
// UserOp.signature - Sign the userOpHash with EOA_1's private key
520520
bytes32 userOpHash = s_entryPoint.getUserOpHash(userOp);
521-
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), userOpHash);
521+
bytes32 ethSignedUserOpHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
522+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), ethSignedUserOpHash);
522523
bytes memory signature = abi.encodePacked(r, s, v);
523524
userOp.signature = signature;
524525

@@ -602,7 +603,8 @@ contract Checkout_EOA_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
602603

603604
// UserOp.signature - Sign the userOpHash with EOA_1's private key
604605
bytes32 userOpHash = s_entryPoint.getUserOpHash(userOp);
605-
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), userOpHash);
606+
bytes32 ethSignedUserOpHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
607+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(EOA_1_PK), ethSignedUserOpHash);
606608
bytes memory signature = abi.encodePacked(r, s, v);
607609
userOp.signature = signature;
608610

test/fork/enso-checkout/Checkout_SmartWallet_EntryPointV7_Fork_Test.t.sol

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ERC4337CloneFactory } from "../../../src/factory/ERC4337CloneFactory.so
77
import { SignaturePaymaster } from "../../../src/paymaster/SignaturePaymaster.sol";
88
import { Shortcut } from "../../shortcuts/ShortcutDataTypes.sol";
99
import { ShortcutsEthereum } from "../../shortcuts/ShortcutsEthereum.sol";
10-
10+
import { PackedUserOperationLib } from "../../utils/AccountAbstraction.sol";
1111
import { TokenBalanceHelper } from "../../utils/TokenBalanceHelper.sol";
1212
import { EntryPoint } from "account-abstraction-v7/core/EntryPoint.sol";
1313
import { IEntryPoint, PackedUserOperation } from "account-abstraction-v7/interfaces/IEntryPoint.sol";
@@ -17,13 +17,10 @@ import { MessageHashUtils } from "openzeppelin-contracts/utils/cryptography/Mess
1717
import { Safe } from "safe-smart-account-1.5.0/Safe.sol";
1818
import { ExtensibleFallbackHandler } from "safe-smart-account-1.5.0/handler/ExtensibleFallbackHandler.sol";
1919
import { ERC1271 } from "safe-smart-account-1.5.0/handler/extensible/SignatureVerifierMuxer.sol";
20-
2120
import { SignMessageLib } from "safe-smart-account-1.5.0/libraries/SignMessageLib.sol";
2221
import { SafeProxy } from "safe-smart-account-1.5.0/proxies/SafeProxy.sol";
2322
import { SafeProxyFactory } from "safe-smart-account-1.5.0/proxies/SafeProxyFactory.sol";
2423

25-
import { PackedUserOperationLib } from "../../utils/AccountAbstraction.sol";
26-
2724
contract Checkout_SmartWallet_EntryPointV7_Fork_Test is Test, TokenBalanceHelper {
2825
using SafeERC20 for IERC20;
2926

@@ -344,13 +341,13 @@ contract Checkout_SmartWallet_EntryPointV7_Fork_Test is Test, TokenBalanceHelper
344341
assertBalanceDiff(
345342
balancePreEntryPointPaymaster,
346343
balancePostEntryPointPaymaster,
347-
-2_136_959_537_241_825,
344+
-2_137_317_098_055_948,
348345
"EntryPoint Paymaster balance (ETH)"
349346
);
350347
assertBalanceDiff(
351348
balancePreEntryPointTokenIn,
352349
balancePostEntryPointTokenIn,
353-
-2_136_959_537_241_825,
350+
-2_137_317_098_055_948,
354351
"EntryPoint TokenIn (ETH)"
355352
);
356353
assertBalanceDiff(balancePreEntryPointTokenOut, balancePostEntryPointTokenOut, 0, "EntryPoint TokenOut (WETH)");

test/unit/concrete/delegate/ensoReceiver/validateUserOp.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SIG_VALIDATION_FAILED, SIG_VALIDATION_SUCCESS } from "account-abstracti
88
import { PackedUserOperation } from "account-abstraction-v7/interfaces/IEntryPoint.sol";
99
import { console2 } from "forge-std-1.9.7/Test.sol";
1010
import { Ownable } from "openzeppelin-contracts/access/Ownable2Step.sol";
11+
import { MessageHashUtils } from "openzeppelin-contracts/utils/cryptography/MessageHashUtils.sol";
1112

1213
contract MinimalERC1271 {
1314
bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;
@@ -162,8 +163,8 @@ contract EnsoReceiver_ValidateUserOp_Unit_Concrete_Test is EnsoReceiver_Unit_Con
162163
userOp.nonce = isUnorderedNonce ? type(uint64).max : 0;
163164

164165
bytes32 userOpHash = s_entryPoint.getUserOpHash(userOp);
165-
166-
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(signerPk), userOpHash);
166+
bytes32 ethSignedUserOpHash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
167+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(uint256(signerPk), ethSignedUserOpHash);
167168
bytes memory signature = abi.encodePacked(r, s, v);
168169
userOp.signature = signature;
169170

0 commit comments

Comments
 (0)