From 9b45ccb7193300fe726386dd2869a1506a5aaa10 Mon Sep 17 00:00:00 2001 From: leekt Date: Thu, 8 Feb 2024 16:51:24 +0900 Subject: [PATCH] changed test to use standard message hash --- src/Kernel.sol | 5 +++-- src/utils/KernelTestBase.sol | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Kernel.sol b/src/Kernel.sol index 25a94b18..890214c1 100644 --- a/src/Kernel.sol +++ b/src/Kernel.sol @@ -28,6 +28,8 @@ import {ValidationData, ValidAfter, ValidUntil, parseValidationData, packValidat contract Kernel is EIP712, Compatibility, KernelStorage { /// @dev Selector of the `DisabledMode()` error, to be used in assembly, 'bytes4(keccak256(bytes("DisabledMode()")))', same as DisabledMode.selector() uint256 private constant _DISABLED_MODE_SELECTOR = 0xfc2f51c5; + bytes32 internal constant EIP712_DOMAIN_TYPEHASH = + 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; /// @dev Current kernel name and version, todo: Need to expose getter for this variables? string public constant name = KERNEL_NAME; @@ -288,8 +290,7 @@ contract Kernel is EIP712, Compatibility, KernelStorage { address proxyAddress = address(this); // Construct the domain separator with name, version, chainId, and proxy address. - bytes32 typeHash = - keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); + bytes32 typeHash = EIP712_DOMAIN_TYPEHASH; return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, proxyAddress)); } diff --git a/src/utils/KernelTestBase.sol b/src/utils/KernelTestBase.sol index b7357b2b..8411c6bc 100644 --- a/src/utils/KernelTestBase.sol +++ b/src/utils/KernelTestBase.sol @@ -15,6 +15,7 @@ import {IKernelValidator} from "../interfaces/IKernelValidator.sol"; import {Call, ExecutionDetail} from "../common/Structs.sol"; import {ValidationData, ValidUntil, ValidAfter} from "../common/Types.sol"; import {KERNEL_VERSION, KERNEL_NAME} from "../common/Constants.sol"; +import {ECDSA} from "solady/utils/ECDSA.sol"; import {ERC4337Utils} from "./ERC4337Utils.sol"; import {Test} from "forge-std/Test.sol"; @@ -196,7 +197,8 @@ abstract contract KernelTestBase is Test { function test_validate_signature() external virtual { Kernel kernel2 = Kernel(payable(factory.createAccount(address(kernelImpl), getInitializeData(), 3))); - bytes32 hash = keccak256(abi.encodePacked("hello world")); + string memory message = "hello world"; + bytes32 hash = ECDSA.toEthSignedMessageHash(bytes(message)); bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), hash