Skip to content

Commit

Permalink
feat: spoof balances
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmiller committed Jul 13, 2024
1 parent db634fc commit ba3d618
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/rbuilder/src/bin/debug-bench-machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ async fn main() -> eyre::Result<()> {
blocklist: Default::default(),
excess_blob_gas: block_data.excess_blob_gas,
spec_id: SpecId::LATEST,
backtest_balances_to_spoof: None,
};

let orders = block_data
Expand Down
5 changes: 5 additions & 0 deletions crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub struct BlockBuildingContext {
pub excess_blob_gas: Option<u64>,
/// Version of the EVM that we are going to use
pub spec_id: SpecId,
// An optional Vec of a tuple of addresses and balances to spoof during simulation
// [!SAFETY!] Only use in backtesting
pub backtest_balances_to_spoof: Option<Vec<(Address, u128)>>,
}

impl BlockBuildingContext {
Expand Down Expand Up @@ -138,6 +141,7 @@ impl BlockBuildingContext {
extra_data,
excess_blob_gas,
spec_id,
backtest_balances_to_spoof: None,
}
}

Expand Down Expand Up @@ -235,6 +239,7 @@ impl BlockBuildingContext {
.excess_blob_gas
.map(|b| b as u64),
spec_id,
backtest_balances_to_spoof: None,
}
}

Expand Down
13 changes: 11 additions & 2 deletions crates/rbuilder/src/building/order_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,17 @@ impl<'a, 'b, 'c, Tracer: SimulationTracer> PartialBlockFork<'a, 'b, 'c, Tracer>
.with_env(Box::new(env))
.with_db(db.as_mut())
.with_external_context(&mut rbuilder_inspector)
.append_handler_register(inspector_handle_register)
.build();
.append_handler_register(inspector_handle_register);

if let Some(balances_to_increment) = &ctx.backtest_balances_to_spoof {
evm = evm.modify_db(|db| {
for (addr, balance) in balances_to_increment {
let _ = db.increment_balances([(*addr, *balance)]);
}
});
}

let mut evm = evm.build();
let res = match evm.transact() {
Ok(res) => res,
Err(err) => match err {
Expand Down

0 comments on commit ba3d618

Please sign in to comment.