arb_precompiles/
arbfunctiontable.rs

1use alloy_evm::precompiles::{DynPrecompile, PrecompileInput};
2use alloy_primitives::{Address, U256};
3use alloy_sol_types::SolInterface;
4use revm::precompile::{PrecompileError, PrecompileId, PrecompileOutput, PrecompileResult};
5
6use crate::interfaces::IArbFunctionTable;
7
8/// ArbFunctionTable precompile address (0x68).
9pub const ARBFUNCTIONTABLE_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, 0x68,
12]);
13
14const COPY_GAS: u64 = 3;
15
16pub fn create_arbfunctiontable_precompile() -> DynPrecompile {
17    DynPrecompile::new_stateful(PrecompileId::custom("arbfunctiontable"), handler)
18}
19
20fn handler(input: PrecompileInput<'_>) -> PrecompileResult {
21    let gas_limit = input.gas;
22    crate::init_precompile_gas(input.data.len());
23
24    let call = match IArbFunctionTable::ArbFunctionTableCalls::abi_decode(input.data) {
25        Ok(c) => c,
26        Err(_) => return crate::burn_all_revert(gas_limit),
27    };
28
29    use IArbFunctionTable::ArbFunctionTableCalls;
30    let result = match call {
31        ArbFunctionTableCalls::upload(_) => Ok(PrecompileOutput::new(
32            COPY_GAS.min(gas_limit),
33            vec![].into(),
34        )),
35        ArbFunctionTableCalls::size(_) => Ok(PrecompileOutput::new(
36            COPY_GAS.min(gas_limit),
37            U256::ZERO.to_be_bytes::<32>().to_vec().into(),
38        )),
39        ArbFunctionTableCalls::get(_) => Err(PrecompileError::other("table is empty")),
40    };
41    crate::gas_check(gas_limit, result)
42}