diff --git a/src/utils/ERC4337Utils.sol b/src/utils/ERC4337Utils.sol index e1a69cac..f140f6fd 100644 --- a/src/utils/ERC4337Utils.sol +++ b/src/utils/ERC4337Utils.sol @@ -71,13 +71,9 @@ library ERC4337Utils { } /// @dev Returns the EIP-712 domain separator for the given kernel account. - function getDomainSeparator(Kernel kernel) - internal - view - returns (bytes32 domainSeparator) - { + function getDomainSeparator(Kernel kernel) internal view returns (bytes32 domainSeparator) { // Extract a few infos from the kernel - (,string memory name, string memory version,,,,) = kernel.eip712Domain(); + (, string memory name, string memory version,,,,) = kernel.eip712Domain(); // Build the domain separator domainSeparator = _buildDomainSeparator(name, version, address(kernel)); } diff --git a/src/utils/KernelTestBase.sol b/src/utils/KernelTestBase.sol index 1a669ced..7516a3c5 100644 --- a/src/utils/KernelTestBase.sol +++ b/src/utils/KernelTestBase.sol @@ -25,6 +25,7 @@ import {TestERC721} from "../mock/TestERC721.sol"; import {TestERC1155} from "../mock/TestERC1155.sol"; using ERC4337Utils for IEntryPoint; +using ERC4337Utils for Kernel; abstract contract KernelTestBase is Test { // to support 0.8.19 @@ -197,11 +198,7 @@ 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")); - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), hash - ) - ); + bytes32 digest = keccak256(abi.encodePacked("\x19\x01", kernel.getDomainSeparator(), hash)); bytes memory sig = signHash(digest); assertEq(kernel.isValidSignature(hash, sig), Kernel.isValidSignature.selector); assertEq(kernel2.isValidSignature(hash, sig), bytes4(0xffffffff)); @@ -453,7 +450,7 @@ abstract contract KernelTestBase is Test { return keccak256( abi.encodePacked( "\x19\x01", - ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), + kernel.getDomainSeparator(), ERC4337Utils.getStructHash(sig, validUntil, validAfter, validator, executor, enableData) ) ); diff --git a/test/benchmark/BaseValidatorBenchmark.t.sol b/test/benchmark/BaseValidatorBenchmark.t.sol index 6945817a..a8431b3d 100644 --- a/test/benchmark/BaseValidatorBenchmark.t.sol +++ b/test/benchmark/BaseValidatorBenchmark.t.sol @@ -134,7 +134,7 @@ abstract contract BaseValidatorBenchmark is Test { _addToGlobalJson("signature"); // Write the json output - if(_isWriteEnabled) { + if (_isWriteEnabled) { string memory fileName = string.concat("./benchmarks/validator/", validatorName, ".json"); vm.writeJson(_jsonOutput, fileName); } @@ -219,11 +219,7 @@ abstract contract BaseValidatorBenchmark is Test { // Get a few data for the domain separator bytes32 domainSeparator = _kernel.getDomainSeparator(); // Should create a digest of the hash - bytes32 _digest = keccak256( - abi.encodePacked( - "\x19\x01", domainSeparator, _hash - ) - ); + bytes32 _digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, _hash)); bytes memory signature = _generateHashSignature(_digest); // Perform the validator signature check directly diff --git a/test/foundry/validator/WebAuthnFclValidator.t.sol b/test/foundry/validator/WebAuthnFclValidator.t.sol index 8cd95139..509c2f05 100644 --- a/test/foundry/validator/WebAuthnFclValidator.t.sol +++ b/test/foundry/validator/WebAuthnFclValidator.t.sol @@ -16,6 +16,7 @@ import {Base64Url} from "FreshCryptoLib/utils/Base64Url.sol"; import {IKernel} from "src/interfaces/IKernel.sol"; using ERC4337Utils for IEntryPoint; +using ERC4337Utils for Kernel; contract WebAuthnFclValidatorTest is KernelTestBase { WebAuthnFclValidator private webAuthNValidator; @@ -127,11 +128,7 @@ contract WebAuthnFclValidatorTest is KernelTestBase { function test_validate_signature() external override { bytes32 _hash = keccak256(abi.encodePacked("hello world")); - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), _hash - ) - ); + bytes32 digest = keccak256(abi.encodePacked("\x19\x01", kernel.getDomainSeparator(), _hash)); bytes memory signature = signHash(digest); @@ -141,11 +138,7 @@ contract WebAuthnFclValidatorTest is KernelTestBase { function test_fail_validate_wrongsignature() external override { // Prepare the hash to sign bytes32 _hash = keccak256(abi.encodePacked("hello world")); - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), _hash - ) - ); + bytes32 digest = keccak256(abi.encodePacked("\x19\x01", kernel.getDomainSeparator(), _hash)); // Sign it (via a wrong signer) bytes memory sig = getWrongSignature(digest); @@ -155,11 +148,7 @@ contract WebAuthnFclValidatorTest is KernelTestBase { function test_fail_validate_InvalidWebAuthnData() external { // Prepare the data to sign bytes32 _hash = keccak256(abi.encodePacked("hello world")); - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", ERC4337Utils._buildDomainSeparator(KERNEL_NAME, KERNEL_VERSION, address(kernel)), _hash - ) - ); + bytes32 digest = keccak256(abi.encodePacked("\x19\x01", kernel.getDomainSeparator(), _hash)); bytes32 _wrongHash = keccak256(abi.encodePacked("bye world"));