etherspot / skandha

A modular typescript implementation of ERC4337 (Account Abstraction) bundler client.
https://etherspot.io
MIT License
554 stars 49 forks source link

[FEATURE] Use smart contract-based binary search to find userop gas limits #211

Open 0xSulpiride opened 2 weeks ago

0xSulpiride commented 2 weeks ago

Is your feature request related to a problem? Please describe. Skandha started to misestimate gas limits of userops that use EntryPoint v0.7.0. We need to switch to smart-contract based binary search algorithm for better estimation of gas limits.

Describe the solution you'd like We should implement the same approach that Rundler does. They use this contract: https://github.com/alchemyplatform/rundler/blob/307e8c2cbeab80518a56a2f309e994de3b1631f0/crates/types/contracts/src/v0_7/CallGasEstimationProxy.sol

nikhilkumar1612 commented 2 weeks ago

I'm taking a look into this.

ch4r10t33r commented 2 weeks ago

Thank you @nikhilkumar1612

Do give us a shout if you have any questions.

nikhilkumar1612 commented 2 weeks ago

hey i have a few questions:

  1. If a eth_call is made to entrypoint contract's address after overriding its state to CallGasEstimateProxy's bytecode, how will the call even reach simulateHandleOps ? because both contracts are not meant for deployment. I understand that this proxy based approach is done to satisfy the require(address(this) == msg.sender) inside estimateCallGas() but since the deployed instance of an entrypoint will not have both the functionalities how will this work ?
  2. IMPLEMENTATION_ADDRESS_MARKER - constant in CallGasEstimationProxyTypes is this address entrypoint ?
  3. what exactly does this line mean - L32.
0xSulpiride commented 2 weeks ago

Hi @nikhilkumar1612 thanks for picking up this issue!

  1. CallGasEstimationProxy is a proxy that delegates all calls to the _implementation() contract (if no function from it's body matches the selector). So we need 2 overrides in eth_call. One that overrides EntryPoint's address to CallGasEstimationProxy's code and another to override PROXY_IMPLEMENTATION_ADDRESS_MARKER to EntryPoint's code. This way when we call simulateHandleOps on CallGasEstimationProxy, proxy will delegatecall it to EntryPoint
  2. It's just a random address
  3. Explained in 1.

Let me know if you have more questions!

nikhilkumar1612 commented 2 weeks ago

thanks @0xSulpiride . I have completed the changes needed for the types, are these changes relavant to v6 as well ? or is this enhancement only relavant to v7 ?

0xSulpiride commented 2 weeks ago

@nikhilkumar1612 this is only relevant to v7

ch4r10t33r commented 2 weeks ago

thanks @0xSulpiride . I have completed the changes needed for the types, are these changes relavant to v6 as well ? or is this enhancement only relavant to v7 ?

Thank you @nikhilkumar1612 Please create a PR when ready.

nikhilkumar1612 commented 1 week ago

hi guys please find my PR and let me know the changes. @0xSulpiride @ch4r10t33r