Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/factory/KernelFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
8 changes: 6 additions & 2 deletions src/lite/KernelLiteECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down