Skip to content

Commit b3afedc

Browse files
override paymaster deposit with max value for gas estimation
1 parent 8993562 commit b3afedc

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

voltaire_bundler/gas/gas_manager.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import logging
44
import math
55
from typing import Generic, Any
6+
from functools import cache
7+
68
from eth_abi import encode, decode
9+
from eth_utils import keccak
710

811
from voltaire_bundler.user_operation.models import UserOperationType
912
from voltaire_bundler.bundle.exceptions import \
@@ -299,3 +302,15 @@ async def calc_l1_gas_estimate_arbitrum(
299302
@abstractmethod
300303
def calc_base_preverification_gas(self, user_operation: UserOperationType) -> int:
301304
pass
305+
306+
307+
@cache
308+
def calculate_deposit_slot_index(address: str) -> str:
309+
# same deposit value slot for all entrypoints(for ep 0.6 this slot also has
310+
# the staked and stake values)
311+
return "0x" + keccak(
312+
encode(
313+
["uint256", "uint256"],
314+
[int(address, 16), 0] # slot = 0
315+
)
316+
).hex()

voltaire_bundler/gas/gas_manager_v6.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from voltaire_bundler.bundle.exceptions import ExecutionException, \
88
ExecutionExceptionCode, ValidationException, ValidationExceptionCode
9-
from voltaire_bundler.gas.gas_manager import GasManager
9+
from voltaire_bundler.gas.gas_manager import GasManager, calculate_deposit_slot_index
1010
from voltaire_bundler.user_operation.models import FailedOp
1111
from voltaire_bundler.user_operation.user_operation_handler import \
1212
decode_failed_op_event
@@ -197,11 +197,21 @@ async def simulate_handle_op_mod(
197197
call_data = function_selector + call_data_params.hex()
198198
# if there is no paymaster, override the sender's balance for gas estimation
199199
if len(user_operation.paymaster_and_data) == 0:
200-
# if the target is zero, simulate_handle_op is called to estimate
201-
# gas limits override the sender balance with the high value of 10^15 eth
202200
default_state_overrides[user_operation.sender_address] = {
201+
# override the sender balance with the high value of 10^15 eth
202+
# not needed as gas prices can be set to zero, but keeping as
203+
# is for ep 0.6 only as changing it might be a breaking change
203204
"balance": "0x314dc6448d9338c15b0a00000000"
204205
}
206+
else:
207+
slot_index = calculate_deposit_slot_index(
208+
user_operation.paymaster_address_lowercase)
209+
default_state_overrides[entrypoint]["stateDiff"] = {
210+
# override paymaster deposit with max value as verificationgas
211+
# is set to max value for estimation, this will override staked
212+
# and stake values as well
213+
slot_index: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
214+
}
205215

206216
params: list[Any] = [
207217
{

voltaire_bundler/gas/gas_manager_v7v8.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from voltaire_bundler.bundle.exceptions import \
99
(ExecutionException, ExecutionExceptionCode,
1010
ValidationException, ValidationExceptionCode)
11-
from voltaire_bundler.gas.gas_manager import GasManager
11+
from voltaire_bundler.gas.gas_manager import GasManager, calculate_deposit_slot_index
1212
from voltaire_bundler.user_operation.models import FailedOp, FailedOpWithRevert
1313
from voltaire_bundler.user_operation.user_operation_handler import \
1414
decode_failed_op_event, decode_failed_op_with_revert_event
@@ -201,16 +201,18 @@ async def simulate_handle_op_mod(
201201
}
202202
eip7702_auth = user_operation.eip7702_auth
203203

204-
if eip7702_auth is not None or user_operation.paymaster is not None:
205-
default_state_overrides[user_operation.sender_address] = {}
206-
if eip7702_auth is not None:
207-
default_state_overrides[user_operation.sender_address][
208-
"code"] = "0xef0100" + eip7702_auth["address"][2:]
209-
210-
if user_operation.paymaster is not None:
211-
default_state_overrides[user_operation.sender_address][
212-
"balance"] = "0x314dc6448d9338c15b0a00000000"
213-
204+
if eip7702_auth is not None:
205+
default_state_overrides[user_operation.sender_address][
206+
"code"] = "0xef0100" + eip7702_auth["address"][2:]
207+
208+
if user_operation.paymaster is not None:
209+
slot_index = calculate_deposit_slot_index(
210+
user_operation.paymaster_address_lowercase)
211+
default_state_overrides[entrypoint]["stateDiff"] = {
212+
# override paymaster deposit with max value as verificationgas
213+
# is set to max value for estimation
214+
slot_index: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
215+
}
214216
call_data = function_selector + call_data_params.hex()
215217
params: list[Any] = [
216218
{

0 commit comments

Comments
 (0)