From e1b1bed752c6a6acff2fa7450f986639e09f0beb Mon Sep 17 00:00:00 2001 From: "Pengfei(Andy) Zhang" Date: Fri, 13 Dec 2024 20:12:14 -0500 Subject: [PATCH] fix: amend gas estimation. --- crates/provider/src/alloy/entry_point/v0_6.rs | 7 +++---- crates/provider/src/alloy/entry_point/v0_7.rs | 15 ++++++++------- crates/sim/src/precheck.rs | 9 +++++++++ crates/task/src/grpc/protos.rs | 1 + test/spec-tests/v0_6/bundler-spec-tests | 2 +- test/spec-tests/v0_7/bundler-spec-tests | 2 +- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/provider/src/alloy/entry_point/v0_6.rs b/crates/provider/src/alloy/entry_point/v0_6.rs index ece153872..43b2a562e 100644 --- a/crates/provider/src/alloy/entry_point/v0_6.rs +++ b/crates/provider/src/alloy/entry_point/v0_6.rs @@ -438,7 +438,7 @@ where target: Address, target_call_data: Bytes, block_id: BlockId, - state_override: StateOverride, + mut state_override: StateOverride, ) -> ProviderResult> { let da_gas: u64 = op .pre_verification_da_gas_limit(&self.chain_spec, Some(1)) @@ -446,10 +446,9 @@ where .unwrap_or(u64::MAX); let authorization_tuple = op.authorization_tuple.clone(); - let mut local_state = state_override.clone(); if let Some(authorization) = authorization_tuple { authorization_utils::apply_7702_overrides( - &mut local_state, + &mut state_override, op.sender(), authorization.address, ); @@ -460,7 +459,7 @@ where .simulateHandleOp(op.into(), target, target_call_data) .block(block_id) .gas(self.max_simulate_handle_op_gas.saturating_add(da_gas)) - .state(local_state) + .state(state_override) .call() .await .err() diff --git a/crates/provider/src/alloy/entry_point/v0_7.rs b/crates/provider/src/alloy/entry_point/v0_7.rs index 0298d8165..82be9e65e 100644 --- a/crates/provider/src/alloy/entry_point/v0_7.rs +++ b/crates/provider/src/alloy/entry_point/v0_7.rs @@ -11,8 +11,6 @@ // You should have received a copy of the GNU General Public License along with Rundler. // If not, see https://www.gnu.org/licenses/. -use std::vec; - use alloy_contract::Error as ContractError; use alloy_eips::eip7702::SignedAuthorization; use alloy_json_rpc::ErrorPayload; @@ -314,14 +312,17 @@ where block: BlockHashOrNumber, gas_price: u128, ) -> ProviderResult<(u128, DAGasUOData, DAGasBlockData)> { - let data = self + let au = user_op.authorization_tuple().clone(); + + let mut txn_req = self .i_entry_point .handleOps(vec![user_op.pack()], Address::random()) - .into_transaction_request() - .input - .into_input() - .unwrap(); + .into_transaction_request(); + if let Some(authorization_tuple) = au { + txn_req = txn_req.with_authorization_list(vec![authorization_tuple.into()]); + } + let data = txn_req.input.into_input().unwrap(); let bundle_data = super::max_bundle_transaction_data(*self.i_entry_point.address(), data, gas_price); diff --git a/crates/sim/src/precheck.rs b/crates/sim/src/precheck.rs index b9bf601d1..5d6fe7352 100644 --- a/crates/sim/src/precheck.rs +++ b/crates/sim/src/precheck.rs @@ -267,6 +267,13 @@ where .. } = *async_data; + let authorization_gas = if op.authorization_tuple().is_some() { + alloy_eips::eip7702::constants::PER_AUTH_BASE_COST + + alloy_eips::eip7702::constants::PER_EMPTY_ACCOUNT_COST + } else { + 0 + }; + let mut violations = ArrayVec::new(); if op.verification_gas_limit() > max_verification_gas { violations.push(PrecheckViolation::VerificationGasLimitTooHigh( @@ -293,6 +300,8 @@ where self.settings.pre_verification_gas_accept_percent, ); } + min_pre_verification_gas = + min_pre_verification_gas.saturating_add(authorization_gas as u128); if op.pre_verification_gas() < min_pre_verification_gas { violations.push(PrecheckViolation::PreVerificationGasTooLow( op.pre_verification_gas(), diff --git a/crates/task/src/grpc/protos.rs b/crates/task/src/grpc/protos.rs index fbc47f494..f3b209447 100644 --- a/crates/task/src/grpc/protos.rs +++ b/crates/task/src/grpc/protos.rs @@ -107,6 +107,7 @@ impl FromFixedLengthProtoBytes for u128 { u128::from_le_bytes(int_bytes.try_into().unwrap()) } } + /// Trait for a type that can be converted to protobuf bytes. pub trait ToProtoBytes { /// Convert to protobuf bytes. diff --git a/test/spec-tests/v0_6/bundler-spec-tests b/test/spec-tests/v0_6/bundler-spec-tests index 939ae009a..bbae0cad2 160000 --- a/test/spec-tests/v0_6/bundler-spec-tests +++ b/test/spec-tests/v0_6/bundler-spec-tests @@ -1 +1 @@ -Subproject commit 939ae009a26820a43547071ded9f866a8704ede8 +Subproject commit bbae0cad201fc7c4c270012c597f28fbe8b037d8 diff --git a/test/spec-tests/v0_7/bundler-spec-tests b/test/spec-tests/v0_7/bundler-spec-tests index 996cbf9ac..b7ae47dfe 160000 --- a/test/spec-tests/v0_7/bundler-spec-tests +++ b/test/spec-tests/v0_7/bundler-spec-tests @@ -1 +1 @@ -Subproject commit 996cbf9ac1a5e766943511194fc4e90e3261f208 +Subproject commit b7ae47dfe670a6ee5596e3b3a10e69a548b2b324