|
1 | 1 | //! Error module for the bus-mapping crate |
2 | 2 |
|
3 | 3 | use core::fmt::{Display, Formatter, Result as FmtResult}; |
4 | | -use eth_types::{evm_types::OpcodeId, Address, GethExecStep, Word, H256}; |
| 4 | +use eth_types::{evm_types::OpcodeId, Address, GethExecError, GethExecStep, Word, H256}; |
5 | 5 | use ethers_providers::ProviderError; |
6 | 6 | use std::error::Error as StdError; |
7 | 7 |
|
8 | | -use crate::geth_errors::{ |
9 | | - GETH_ERR_GAS_UINT_OVERFLOW, GETH_ERR_OUT_OF_GAS, GETH_ERR_STACK_OVERFLOW, |
10 | | - GETH_ERR_STACK_UNDERFLOW, GETH_ERR_WRITE_PROTECTION, |
11 | | -}; |
12 | | - |
13 | 8 | /// Error type for any BusMapping related failure. |
14 | 9 | #[derive(Debug)] |
15 | 10 | pub enum Error { |
@@ -185,42 +180,43 @@ pub enum ExecError { |
185 | 180 | } |
186 | 181 |
|
187 | 182 | // TODO: Move to impl block. |
188 | | -pub(crate) fn get_step_reported_error(op: &OpcodeId, error: &str) -> ExecError { |
189 | | - if [GETH_ERR_OUT_OF_GAS, GETH_ERR_GAS_UINT_OVERFLOW].contains(&error) { |
190 | | - // NOTE: We report a GasUintOverflow error as an OutOfGas error |
191 | | - let oog_err = match op { |
192 | | - OpcodeId::MLOAD | OpcodeId::MSTORE | OpcodeId::MSTORE8 => { |
193 | | - OogError::StaticMemoryExpansion |
194 | | - } |
195 | | - OpcodeId::RETURN | OpcodeId::REVERT => OogError::DynamicMemoryExpansion, |
196 | | - OpcodeId::CALLDATACOPY |
197 | | - | OpcodeId::CODECOPY |
198 | | - | OpcodeId::EXTCODECOPY |
199 | | - | OpcodeId::RETURNDATACOPY => OogError::MemoryCopy, |
200 | | - OpcodeId::BALANCE | OpcodeId::EXTCODESIZE | OpcodeId::EXTCODEHASH => { |
201 | | - OogError::AccountAccess |
202 | | - } |
203 | | - OpcodeId::LOG0 | OpcodeId::LOG1 | OpcodeId::LOG2 | OpcodeId::LOG3 | OpcodeId::LOG4 => { |
204 | | - OogError::Log |
205 | | - } |
206 | | - OpcodeId::EXP => OogError::Exp, |
207 | | - OpcodeId::SHA3 => OogError::Sha3, |
208 | | - OpcodeId::CALL | OpcodeId::CALLCODE | OpcodeId::DELEGATECALL | OpcodeId::STATICCALL => { |
209 | | - OogError::Call |
210 | | - } |
211 | | - OpcodeId::SLOAD | OpcodeId::SSTORE => OogError::SloadSstore, |
212 | | - OpcodeId::CREATE | OpcodeId::CREATE2 => OogError::Create, |
213 | | - OpcodeId::SELFDESTRUCT => OogError::SelfDestruct, |
214 | | - _ => OogError::Constant, |
215 | | - }; |
216 | | - ExecError::OutOfGas(oog_err) |
217 | | - } else if error.starts_with(GETH_ERR_STACK_OVERFLOW) { |
218 | | - ExecError::StackOverflow |
219 | | - } else if error.starts_with(GETH_ERR_STACK_UNDERFLOW) { |
220 | | - ExecError::StackUnderflow |
221 | | - } else if error.starts_with(GETH_ERR_WRITE_PROTECTION) { |
222 | | - ExecError::WriteProtection |
223 | | - } else { |
224 | | - panic!("Unknown GethExecStep.error: {error}"); |
| 183 | +pub(crate) fn get_step_reported_error(op: &OpcodeId, error: GethExecError) -> ExecError { |
| 184 | + match error { |
| 185 | + GethExecError::OutOfGas | GethExecError::GasUintOverflow => { |
| 186 | + // NOTE: We report a GasUintOverflow error as an OutOfGas error |
| 187 | + let oog_err = match op { |
| 188 | + OpcodeId::MLOAD | OpcodeId::MSTORE | OpcodeId::MSTORE8 => { |
| 189 | + OogError::StaticMemoryExpansion |
| 190 | + } |
| 191 | + OpcodeId::RETURN | OpcodeId::REVERT => OogError::DynamicMemoryExpansion, |
| 192 | + OpcodeId::CALLDATACOPY |
| 193 | + | OpcodeId::CODECOPY |
| 194 | + | OpcodeId::EXTCODECOPY |
| 195 | + | OpcodeId::RETURNDATACOPY => OogError::MemoryCopy, |
| 196 | + OpcodeId::BALANCE | OpcodeId::EXTCODESIZE | OpcodeId::EXTCODEHASH => { |
| 197 | + OogError::AccountAccess |
| 198 | + } |
| 199 | + OpcodeId::LOG0 |
| 200 | + | OpcodeId::LOG1 |
| 201 | + | OpcodeId::LOG2 |
| 202 | + | OpcodeId::LOG3 |
| 203 | + | OpcodeId::LOG4 => OogError::Log, |
| 204 | + OpcodeId::EXP => OogError::Exp, |
| 205 | + OpcodeId::SHA3 => OogError::Sha3, |
| 206 | + OpcodeId::CALL |
| 207 | + | OpcodeId::CALLCODE |
| 208 | + | OpcodeId::DELEGATECALL |
| 209 | + | OpcodeId::STATICCALL => OogError::Call, |
| 210 | + OpcodeId::SLOAD | OpcodeId::SSTORE => OogError::SloadSstore, |
| 211 | + OpcodeId::CREATE | OpcodeId::CREATE2 => OogError::Create, |
| 212 | + OpcodeId::SELFDESTRUCT => OogError::SelfDestruct, |
| 213 | + _ => OogError::Constant, |
| 214 | + }; |
| 215 | + ExecError::OutOfGas(oog_err) |
| 216 | + } |
| 217 | + GethExecError::StackOverflow { .. } => ExecError::StackOverflow, |
| 218 | + GethExecError::StackUnderflow { .. } => ExecError::StackUnderflow, |
| 219 | + GethExecError::WriteProtection => ExecError::WriteProtection, |
| 220 | + _ => panic!("Unknown GethExecStep.error: {error}"), |
225 | 221 | } |
226 | 222 | } |
0 commit comments