Skip to content

Commit

Permalink
fix: amend gas estimation.
Browse files Browse the repository at this point in the history
  • Loading branch information
andysim3d committed Dec 14, 2024
1 parent 54af9bb commit e1b1bed
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
7 changes: 3 additions & 4 deletions crates/provider/src/alloy/entry_point/v0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,17 @@ where
target: Address,
target_call_data: Bytes,
block_id: BlockId,
state_override: StateOverride,
mut state_override: StateOverride,
) -> ProviderResult<Result<ExecutionResult, ValidationRevert>> {
let da_gas: u64 = op
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.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,
);
Expand All @@ -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()
Expand Down
15 changes: 8 additions & 7 deletions crates/provider/src/alloy/entry_point/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions crates/sim/src/precheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions crates/task/src/grpc/protos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/spec-tests/v0_6/bundler-spec-tests
2 changes: 1 addition & 1 deletion test/spec-tests/v0_7/bundler-spec-tests

0 comments on commit e1b1bed

Please sign in to comment.