arb_precompiles/
arbostest.rs

1use alloy_evm::precompiles::{DynPrecompile, PrecompileInput};
2use alloy_primitives::{Address, U256};
3use alloy_sol_types::SolInterface;
4use revm::precompile::{PrecompileId, PrecompileOutput, PrecompileResult};
5
6use crate::interfaces::IArbosTest;
7
8/// ArbosTest precompile address (0x69). Burns arbitrary amounts of L2 gas.
9pub const ARBOSTEST_ADDRESS: Address = Address::new([
10    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11    0x00, 0x00, 0x00, 0x69,
12]);
13
14pub fn create_arbostest_precompile() -> DynPrecompile {
15    DynPrecompile::new_stateful(PrecompileId::custom("arbostest"), handler)
16}
17
18fn handler(input: PrecompileInput<'_>) -> PrecompileResult {
19    let gas_limit = input.gas;
20    if !crate::allow_debug_precompiles() {
21        return crate::burn_all_revert(gas_limit);
22    }
23    crate::init_precompile_gas(input.data.len());
24
25    let call = match IArbosTest::ArbosTestCalls::abi_decode(input.data) {
26        Ok(c) => c,
27        Err(_) => return crate::burn_all_revert(gas_limit),
28    };
29
30    use IArbosTest::ArbosTestCalls;
31    let result = match call {
32        ArbosTestCalls::burnArbGas(c) => handle_burn_arb_gas(gas_limit, c.gasAmount),
33    };
34    crate::gas_check(gas_limit, result)
35}
36
37fn handle_burn_arb_gas(gas_limit: u64, amount: U256) -> PrecompileResult {
38    let to_burn: u64 = amount.try_into().unwrap_or(u64::MAX);
39    Ok(PrecompileOutput::new(
40        to_burn.min(gas_limit),
41        Vec::new().into(),
42    ))
43}