diff --git a/src/factory/KernelFactory.sol b/src/factory/KernelFactory.sol index 2957eb18..a88dd775 100644 --- a/src/factory/KernelFactory.sol +++ b/src/factory/KernelFactory.sol @@ -6,8 +6,14 @@ import {IEntryPoint} from "I4337/interfaces/IEntryPoint.sol"; import {Ownable} from "solady/auth/Ownable.sol"; contract KernelFactory is AdminLessERC1967Factory, Ownable { + /// Error throwned when an implementation isn't allowed + error ImplementationNotAllowed(); + + /// @dev The entry point contract. IEntryPoint public entryPoint; - mapping(address => bool) public isAllowedImplementation; + + /// @dev Check if an implementation is allowed. + mapping(address implementation => bool isAllowed) public isAllowedImplementation; constructor(address _owner, IEntryPoint _entryPoint) { _initializeOwner(_owner); @@ -27,8 +33,11 @@ contract KernelFactory is AdminLessERC1967Factory, Ownable { payable returns (address proxy) { - require(isAllowedImplementation[_implementation], "KernelFactory: implementation not allowed"); + // Ensure that the implementation contract is allowed + if (!isAllowedImplementation[_implementation]) revert ImplementationNotAllowed(); + // Create the salt for the account bytes32 salt = bytes32(uint256(keccak256(abi.encodePacked(_data, _index))) & type(uint96).max); + // Deploy the proxy and return it's address proxy = deployDeterministicAndCall(_implementation, salt, _data); } diff --git a/src/lite/KernelLiteECDSA.sol b/src/lite/KernelLiteECDSA.sol index a483d63d..4f3a1a6f 100644 --- a/src/lite/KernelLiteECDSA.sol +++ b/src/lite/KernelLiteECDSA.sol @@ -19,6 +19,7 @@ struct KernelLiteECDSAStorage { /// @dev A lite version of the Kernel contract which only uses ECDSA signatures for validation contract KernelLiteECDSA is Kernel { error InvalidAccess(); + error InvalidValidator(); address public immutable KERNEL_ECDSA_VALIDATOR; @@ -45,8 +46,11 @@ contract KernelLiteECDSA is Kernel { /// @dev Set the initial data for this kernel (setup ecdsa signer address) function _setInitialData(IKernelValidator _validator, bytes calldata _data) internal override { - require(address(_validator) == KERNEL_ECDSA_VALIDATOR, "KernelLiteECDSA: invalid validator"); - require(getKernelLiteECDSAStorage().owner == address(0), "KernelLiteECDSA: already initialized"); + // Ensure the validator is valid + if (address(_validator) != KERNEL_ECDSA_VALIDATOR) revert InvalidValidator(); + // Ensure the account isn't already initialized + if (getKernelLiteECDSAStorage().owner != address(0)) revert AlreadyInitialized(); + address owner = address(bytes20(_data[0:20])); getKernelLiteECDSAStorage().owner = owner; }