Skip to content

Commit

Permalink
feat: unsafe mode for EP v0.6 (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs authored Mar 29, 2024
1 parent 046ece3 commit f893854
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 47 deletions.
1 change: 1 addition & 0 deletions bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl BuilderArgs {
mempool_configs,
}],
chain_spec,
unsafe_mode: common.unsafe_mode,
rpc_url,
private_key: self.private_key.clone(),
aws_kms_key_ids: self.aws_kms_key_ids.clone(),
Expand Down
4 changes: 4 additions & 0 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub struct CommonArgs {
)]
node_http: Option<String>,

/// Flag for turning unsafe bundling mode on
#[arg(long = "unsafe", env = "UNSAFE", global = true)]
unsafe_mode: bool,

#[arg(
long = "max_verification_gas",
name = "max_verification_gas",
Expand Down
1 change: 1 addition & 0 deletions bin/rundler/src/cli/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl PoolArgs {

Ok(PoolTaskArgs {
chain_spec,
unsafe_mode: common.unsafe_mode,
http_url: common
.node_http
.clone()
Expand Down
1 change: 1 addition & 0 deletions bin/rundler/src/cli/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl RpcArgs {

Ok(RpcTaskArgs {
chain_spec,
unsafe_mode: common.unsafe_mode,
port: self.port,
host: self.host.clone(),
rpc_url: common
Expand Down
31 changes: 27 additions & 4 deletions crates/builder/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rundler_provider::{EntryPointProvider, EthersEntryPointV0_6, Provider};
use rundler_sim::{
simulation::v0_6::{
SimulateValidationTracerImpl as SimulateValidationTracerImplV0_6,
Simulator as SimulatorV0_6,
Simulator as SimulatorV0_6, UnsafeSimulator as UnsafeSimulatorV0_6,
},
MempoolConfig, PriorityFeeMode, SimulationSettings, Simulator,
};
Expand Down Expand Up @@ -61,6 +61,8 @@ pub struct Args {
pub chain_spec: ChainSpec,
/// Full node RPC url
pub rpc_url: String,
/// True if using unsafe mode
pub unsafe_mode: bool,
/// Private key to use for signing transactions
/// If not provided, AWS KMS will be used
pub private_key: Option<String>,
Expand Down Expand Up @@ -157,8 +159,16 @@ where
info!("Mempool config for ep v0.6: {:?}", ep.mempool_configs);

for i in 0..ep.num_bundle_builders {
let (spawn_guard, bundle_sender_action) = self
.create_bundle_builder(
let (spawn_guard, bundle_sender_action) = if self.args.unsafe_mode {
self.create_bundle_builder(
i + ep.bundle_builder_index_offset,
Arc::clone(&provider),
ep_v0_6.clone(),
self.create_unsafe_simulator_v0_6(Arc::clone(&provider), ep_v0_6.clone()),
)
.await?
} else {
self.create_bundle_builder(
i + ep.bundle_builder_index_offset,
Arc::clone(&provider),
ep_v0_6.clone(),
Expand All @@ -168,7 +178,8 @@ where
ep.mempool_configs.clone(),
),
)
.await?;
.await?
};
sender_handles.push(spawn_guard);
bundle_sender_actions.push(bundle_sender_action);
}
Expand Down Expand Up @@ -384,4 +395,16 @@ where
mempool_configs,
)
}

fn create_unsafe_simulator_v0_6<C, E>(
&self,
provider: Arc<C>,
ep: E,
) -> UnsafeSimulatorV0_6<C, E>
where
C: Provider,
E: EntryPointProvider<v0_6::UserOperation> + Clone,
{
UnsafeSimulatorV0_6::new(Arc::clone(&provider), ep, self.args.sim_settings)
}
}
72 changes: 42 additions & 30 deletions crates/pool/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ use crate::{
pub struct Args {
/// Chain specification.
pub chain_spec: ChainSpec,
/// True if using unsafe mode.
pub unsafe_mode: bool,
/// HTTP URL for the full node.
pub http_url: String,
/// Poll interval for full node requests.
Expand Down Expand Up @@ -94,6 +96,7 @@ impl Task for PoolTask {
let pool = PoolTask::create_mempool_v0_6(
self.args.chain_spec.clone(),
pool_config,
self.args.unsafe_mode,
self.event_sender.clone(),
provider.clone(),
)
Expand Down Expand Up @@ -121,17 +124,6 @@ impl Task for PoolTask {
);
}
}

let pool = PoolTask::create_mempool_v0_6(
self.args.chain_spec.clone(),
pool_config,
self.event_sender.clone(),
provider.clone(),
)
.await
.context("should have created mempool")?;

mempools.insert(pool_config.entry_point, pool);
}

let pool_handle = self.pool_builder.get_handle();
Expand Down Expand Up @@ -204,6 +196,7 @@ impl PoolTask {
async fn create_mempool_v0_6<P: Provider + Middleware>(
chain_spec: ChainSpec,
pool_config: &PoolConfig,
unsafe_mode: bool,
event_sender: broadcast::Sender<WithEntryPoint<OpPoolEvent>>,
provider: Arc<P>,
) -> anyhow::Result<Arc<Box<dyn Mempool>>> {
Expand All @@ -216,16 +209,6 @@ impl PoolTask {
pool_config.precheck_settings,
);

let simulate_validation_tracer =
sim_v0_6::SimulateValidationTracerImpl::new(Arc::clone(&provider), ep.clone());
let simulator = sim_v0_6::Simulator::new(
Arc::clone(&provider),
ep.clone(),
simulate_validation_tracer,
pool_config.sim_settings,
pool_config.mempool_channel_configs.clone(),
);

let reputation = Arc::new(AddressReputation::new(
ReputationParams::new(pool_config.reputation_tracking_enabled),
pool_config.blocklist.clone().unwrap_or_default(),
Expand All @@ -246,15 +229,44 @@ impl PoolTask {
),
);

let uo_pool = UoPool::new(
pool_config.clone(),
event_sender,
prechecker,
simulator,
paymaster,
reputation,
);
if unsafe_mode {
let simulator = sim_v0_6::UnsafeSimulator::new(
Arc::clone(&provider),
ep.clone(),
pool_config.sim_settings,
);

let uo_pool = UoPool::new(
pool_config.clone(),
event_sender,
prechecker,
simulator,
paymaster,
reputation,
);

Ok(Arc::new(Box::new(uo_pool)))
Ok(Arc::new(Box::new(uo_pool)))
} else {
let simulate_validation_tracer =
sim_v0_6::SimulateValidationTracerImpl::new(Arc::clone(&provider), ep.clone());
let simulator = sim_v0_6::Simulator::new(
Arc::clone(&provider),
ep.clone(),
simulate_validation_tracer,
pool_config.sim_settings,
pool_config.mempool_channel_configs.clone(),
);

let uo_pool = UoPool::new(
pool_config.clone(),
event_sender,
prechecker,
simulator,
paymaster,
reputation,
);

Ok(Arc::new(Box::new(uo_pool)))
}
}
}
14 changes: 9 additions & 5 deletions crates/provider/src/ethers/entry_point/v0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,19 @@ where
&self,
user_op: UserOperation,
max_validation_gas: u64,
block_hash: Option<H256>,
) -> anyhow::Result<ValidationOutput> {
let pvg = user_op.pre_verification_gas;
match self
let blockless = self
.i_entry_point
.simulate_validation(user_op)
.gas(U256::from(max_validation_gas) + pvg)
.call()
.await
{
.gas(U256::from(max_validation_gas) + pvg);
let call = match block_hash {
Some(block_hash) => blockless.block(block_hash),
None => blockless,
};

match call.call().await {
Ok(()) => anyhow::bail!("simulateValidation should always revert"),
Err(ContractError::Revert(revert_data)) => ValidationOutput::decode_v0_6(revert_data)
.context("entry point should return validation output"),
Expand Down
11 changes: 9 additions & 2 deletions crates/provider/src/ethers/entry_point/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ where
&self,
user_op: UserOperation,
max_validation_gas: u64,
block_hash: Option<H256>,
) -> anyhow::Result<ValidationOutput> {
let addr = self.i_entry_point.address();
let pvg = user_op.pre_verification_gas;
Expand All @@ -319,9 +320,15 @@ where
.code(ENTRYPOINTSIMULATIONS_BYTECODE.clone());

let ep_simulations = EntryPointSimulations::new(addr, Arc::clone(&self.provider));
let result = ep_simulations
let blockless = ep_simulations
.simulate_validation(user_op.pack())
.gas(U256::from(max_validation_gas) + pvg)
.gas(U256::from(max_validation_gas) + pvg);
let call = match block_hash {
Some(block_hash) => blockless.block(block_hash),
None => blockless,
};

let result = call
.call_raw()
.state(&spoof_ep)
.await
Expand Down
1 change: 1 addition & 0 deletions crates/provider/src/traits/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub trait SimulationProvider: Send + Sync + 'static {
&self,
user_op: Self::UO,
max_validation_gas: u64,
block_hash: Option<H256>,
) -> anyhow::Result<ValidationOutput>;

/// Call the entry point contract's `simulateHandleOps` function
Expand Down
1 change: 1 addition & 0 deletions crates/provider/src/traits/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mockall::mock! {
&self,
user_op: v0_6::UserOperation,
max_validation_gas: u64,
block_hash: Option<H256>
) -> anyhow::Result<ValidationOutput>;
async fn call_spoofed_simulate_op(
&self,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/eth/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ where
) -> anyhow::Result<bool> {
let output = self
.entry_point
.call_simulate_validation(uo.into(), max_verification_gas)
.call_simulate_validation(uo.into(), max_verification_gas, None)
.await?;

Ok(!output.return_info.account_sig_failed)
Expand Down
2 changes: 2 additions & 0 deletions crates/rpc/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ use crate::{
pub struct Args {
/// Chain spec
pub chain_spec: ChainSpec,
/// True if using unsafe mode
pub unsafe_mode: bool,
/// Port to listen on.
pub port: u16,
/// Host to listen on.
Expand Down
3 changes: 3 additions & 0 deletions crates/sim/src/simulation/v0_6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ pub use simulator::Simulator;
mod tracer;
pub use tracer::{SimulateValidationTracer, SimulateValidationTracerImpl};

mod unsafe_sim;
pub use unsafe_sim::UnsafeSimulator;

/// Required buffer for verification gas limit when targeting the 0.6 entrypoint contract
pub(crate) const REQUIRED_VERIFICATION_GAS_LIMIT_BUFFER: U256 = U256([2000, 0, 0, 0]);
5 changes: 0 additions & 5 deletions crates/sim/src/simulation/v0_6/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ where
}
}

/// Return the associated settings
pub fn settings(&self) -> &Settings {
&self.sim_settings
}

// Run the tracer and transform the output.
// Any violations during this stage are errors.
async fn create_context(
Expand Down
Loading

0 comments on commit f893854

Please sign in to comment.