zerodevapp / kernel

https://docs.zerodev.app/
MIT License
172 stars 61 forks source link

Gas saving: Expose another `initialize` method without hook #97

Open KONFeature opened 4 months ago

KONFeature commented 4 months ago

When a hook isn't wanted during the init of a Kernel, we still have to send an 0 address + empty array of bytes https://github.com/zerodevapp/kernel/blob/b8442f2b138b7832b2353b564bcdebb269446a46/src/Kernel.sol#L102

Having another initialize method without this data could save up a bit of gas on L2, since less calldata sent (and this data is required to be sent during the contract creation, on arbitrum, it's approx 24k ArbGas that could be saved), smth like that:

function initialize(ValidationId _rootValidator, bytes calldata _validatorData) external {
  // ... Same as before
  // Hook setup would be: 
  ValidationConfig memory config = ValidationConfig({nonce: uint32(1), hook: address(0) });
  _installValidationWithoutNonceIncremental(_rootValidator, config, _validatorData, 0x);
}

Ooh and btw, the ValidationConfig fit on 32 bytes, so similarly to the custom ValidationId or ExecMode, type ValidationConfig could be a custom type on top of bytes32, saving up a bit on computation cost on L1 / alt L1

leekt commented 4 months ago

nice idea :), we are adding some initialization flow on kernel v3.1, i think this can be added while doing that