Skip to content

Commit

Permalink
fix: code cleaning, move pvg logic to required_pre_verification_gas
Browse files Browse the repository at this point in the history
  • Loading branch information
andysim3d committed Dec 16, 2024
1 parent e1b1bed commit 7b78d7e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 47 deletions.
16 changes: 9 additions & 7 deletions crates/provider/src/alloy/entry_point/v0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,16 @@ where
block: BlockHashOrNumber,
gas_price: u128,
) -> ProviderResult<(u128, DAGasUOData, DAGasBlockData)> {
let data = self
let au = user_op.authorization_tuple();
let mut txn_request = self
.i_entry_point
.handleOps(vec![user_op.into()], Address::random())
.into_transaction_request()
.input
.into_input()
.unwrap();
.into_transaction_request();
if let Some(authorization) = au {
txn_request = txn_request.with_authorization_list(vec![authorization.into()]);
}

let data = txn_request.input.into_input().unwrap();

let bundle_data =
super::max_bundle_transaction_data(*self.i_entry_point.address(), data, gas_price);
Expand Down Expand Up @@ -444,9 +447,8 @@ where
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.unwrap_or(u64::MAX);
let authorization_tuple = op.authorization_tuple.clone();

if let Some(authorization) = authorization_tuple {
if let Some(authorization) = &op.authorization_tuple {
authorization_utils::apply_7702_overrides(
&mut state_override,
op.sender(),
Expand Down
35 changes: 18 additions & 17 deletions crates/provider/src/alloy/entry_point/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use rundler_contracts::v0_7::{
ENTRY_POINT_SIMULATIONS_V0_7_DEPLOYED_BYTECODE,
};
use rundler_types::{
authorization::Authorization,
chain::ChainSpec,
da::{DAGasBlockData, DAGasUOData},
v0_7::UserOperation,
Expand Down Expand Up @@ -312,7 +313,7 @@ where
block: BlockHashOrNumber,
gas_price: u128,
) -> ProviderResult<(u128, DAGasUOData, DAGasBlockData)> {
let au = user_op.authorization_tuple().clone();
let au = user_op.authorization_tuple();

let mut txn_req = self
.i_entry_point
Expand Down Expand Up @@ -354,14 +355,11 @@ where
let mut override_ep = StateOverride::default();
add_simulations_override(&mut override_ep, addr);

let authorization_tuple = user_op.authorization_tuple.clone();
if let Some(authorization) = authorization_tuple {
authorization_utils::apply_7702_overrides(
&mut override_ep,
user_op.sender(),
authorization.address,
);
}
add_authorization_tuple(
user_op.sender(),
&user_op.authorization_tuple,
&mut override_ep,
);

let ep_simulations =
IEntryPointSimulationsInstance::new(addr, self.i_entry_point.provider());
Expand Down Expand Up @@ -436,14 +434,7 @@ where

add_simulations_override(&mut state_override, *self.i_entry_point.address());

let authorization_tuple = op.authorization_tuple.clone();
if let Some(authorization) = authorization_tuple {
authorization_utils::apply_7702_overrides(
&mut state_override,
op.sender(),
authorization.address,
);
}
add_authorization_tuple(op.sender(), &op.authorization_tuple, &mut state_override);

let ep_simulations = IEntryPointSimulations::new(
*self.i_entry_point.address(),
Expand Down Expand Up @@ -604,3 +595,13 @@ impl TryFrom<ExecutionResultV0_7> for ExecutionResult {
})
}
}

fn add_authorization_tuple(
sender: Address,
authorization: &Option<Authorization>,
state_override: &mut StateOverride,
) {
if let Some(authorization) = &authorization {
authorization_utils::apply_7702_overrides(state_override, sender, authorization.address);
}
}
19 changes: 5 additions & 14 deletions crates/sim/src/estimation/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rundler_types::{
v0_7::{UserOperation, UserOperationBuilder, UserOperationOptionalGas},
GasEstimate, UserOperation as _,
};
use rundler_utils::{authorization_utils, math};
use rundler_utils::math;
use tokio::join;

use super::{estimate_verification_gas::GetOpWithLimitArgs, GasEstimationError, Settings};
Expand Down Expand Up @@ -71,14 +71,6 @@ where
) -> Result<GasEstimate, GasEstimationError> {
self.check_provided_limits(&op)?;

let mut local_override = state_override.clone();
let authorization_gas = if let Some(au) = &op.authorization_contract {
authorization_utils::apply_7702_overrides(&mut local_override, op.sender, *au);
alloy_eips::eip7702::constants::PER_AUTH_BASE_COST
+ alloy_eips::eip7702::constants::PER_EMPTY_ACCOUNT_COST
} else {
0
};
let Self {
provider, settings, ..
} = self;
Expand All @@ -88,8 +80,7 @@ where
.await
.map_err(anyhow::Error::from)?;

let pre_verification_gas = (self.estimate_pre_verification_gas(&op, block_hash).await?)
.saturating_add(authorization_gas as u128);
let pre_verification_gas = self.estimate_pre_verification_gas(&op, block_hash).await?;

let full_op = op
.clone()
Expand All @@ -103,16 +94,16 @@ where
.build();

let verification_gas_future =
self.estimate_verification_gas(&op, &full_op, block_hash, local_override.clone());
self.estimate_verification_gas(&op, &full_op, block_hash, state_override.clone());

let paymaster_verification_gas_future = self.estimate_paymaster_verification_gas(
&op,
&full_op,
block_hash,
local_override.clone(),
state_override.clone(),
);
let call_gas_future =
self.estimate_call_gas(&op, full_op.clone(), block_hash, local_override);
self.estimate_call_gas(&op, full_op.clone(), block_hash, state_override);

// Not try_join! because then the output is nondeterministic if multiple calls fail.
let timer = std::time::Instant::now();
Expand Down
9 changes: 0 additions & 9 deletions crates/sim/src/precheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,6 @@ 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 @@ -300,8 +293,6 @@ 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
7 changes: 7 additions & 0 deletions crates/types/src/user_operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,16 @@ pub trait UserOperation: Debug + Clone + Send + Sync + 'static {
bundle_size: usize,
da_gas: u128,
) -> u128 {
let authorization_gas = if self.authorization_tuple().is_some() {
alloy_eips::eip7702::constants::PER_AUTH_BASE_COST
+ alloy_eips::eip7702::constants::PER_EMPTY_ACCOUNT_COST
} else {
0
};
self.static_pre_verification_gas(chain_spec)
.saturating_add(bundle_per_uo_shared_gas(chain_spec, bundle_size))
.saturating_add(da_gas)
.saturating_add(authorization_gas as u128)
}

/// Returns true if the user operation has enough pre-verification gas to be included in a bundle
Expand Down

0 comments on commit 7b78d7e

Please sign in to comment.