bluealloy / revm

Rust implementation of the Ethereum Virtual Machine.
https://bluealloy.github.io/revm/
MIT License
1.64k stars 553 forks source link

Optimism Crate: Custom tx not supported during deposit transaction #1839

Open PinelliaC opened 1 week ago

PinelliaC commented 1 week ago

Issue

I am developing on the main branch. While executing a deposit transaction using Optimism’s EVM, a panic occurs due to an issue with tx_type: “Custom tx not supported.”

Description

When using the Optimism crate and executing load_accounts, the function mainnet::load_accounts is called.

pub fn load_accounts<EvmWiringT: OptimismWiring, SPEC: OptimismSpec>(
    context: &mut Context<EvmWiringT>,
) -> EVMResultGeneric<(), EvmWiringT> {
    // the L1-cost fee is only computed for Optimism non-deposit transactions.

    if context.evm.env.tx.tx_type() != OpTransactionType::Deposit {
        let l1_block_info =
            super::L1BlockInfo::try_fetch(&mut context.evm.inner.db, SPEC::OPTIMISM_SPEC_ID)
                .map_err(EVMError::Database)?;

        // storage l1 block info for later use.
        *context.evm.chain.l1_block_info_mut() = Some(l1_block_info);
    }

    mainnet::load_accounts::<EvmWiringT, SPEC>(context) // <-
}

executing the load_accounts method calls the access_list method

    fn access_list(&self) -> Option<&Self::AccessList> {
        let tx_type = self.tx_type().into();
        match tx_type {
            TransactionType::Legacy => None,
            TransactionType::Eip2930 => Some(self.eip2930().access_list()),
            TransactionType::Eip1559 => Some(self.eip1559().access_list()),
            TransactionType::Eip4844 => Some(self.eip4844().access_list()),
            TransactionType::Eip7702 => Some(self.eip7702().access_list()),
            TransactionType::Custom => unimplemented!("Custom tx not supported"),
        }
    }

but during this process, the deposit transaction is matched as a custom transaction when converting it via into,

impl From<OpTransactionType> for TransactionType {
    fn from(tx_type: OpTransactionType) -> Self {
        match tx_type {
            OpTransactionType::Base(tx_type) => tx_type,
            OpTransactionType::Deposit => TransactionType::Custom,
        }
    }
}

which causes a panic in the access_list function.

This seems to be a consistent issue.

Any guidance or support would be greatly appreciated. Thank you!

rakita commented 2 days ago

Thanks for reporting, will check it out. Current main is experiencing bigger restructuring