Skip to content

Commit

Permalink
Renamed EvmErrorKind and added Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Aug 13, 2024
1 parent 48999d3 commit 74bc509
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 76 deletions.
6 changes: 3 additions & 3 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::parameters::connector::{
Erc20Identifier, Erc20Metadata, SetErc20MetadataArgs,
};
use aurora_engine_types::parameters::engine::{SetOwnerArgs, TransactionStatusEvmErrorKind};
use aurora_engine_types::parameters::engine::{EvmErrorKind, SetOwnerArgs};
use bstr::ByteSlice;

use libsecp256k1::SecretKey;
Expand Down Expand Up @@ -81,7 +81,7 @@ fn erc20_mint_out_of_gas() {
let error = outcome.unwrap();
assert_eq!(
error.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfGas)
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);

// Validate post-state
Expand Down Expand Up @@ -238,7 +238,7 @@ fn deploy_erc_20_out_of_gas() {
let error = outcome.unwrap();
assert_eq!(
error.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfGas)
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);

// Validate post-state
Expand Down
26 changes: 8 additions & 18 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aurora_engine_sdk as sdk;
use aurora_engine_types::borsh::BorshDeserialize;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine_types::parameters::connector::FungibleTokenMetadata;
use aurora_engine_types::parameters::engine::TransactionStatusEvmErrorKind;
use aurora_engine_types::parameters::engine::EvmErrorKind;
use aurora_engine_types::H160;
use libsecp256k1::SecretKey;
use near_vm_runner::ContractCode;
Expand Down Expand Up @@ -57,7 +57,7 @@ fn bench_memory_get_standalone() {
assert!(
matches!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfGas)
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"Infinite loops in the EVM run out of gas"
);
Expand Down Expand Up @@ -114,7 +114,7 @@ fn test_returndatacopy() {
assert!(
matches!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfGas)
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"EVM must run out of gas if len > 0 with large memory offset"
);
Expand Down Expand Up @@ -573,7 +573,7 @@ fn test_create_out_of_gas() {
assert!(
matches!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfGas)
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"Unexpected status: {:?}",
result.status
Expand Down Expand Up @@ -770,7 +770,7 @@ fn test_eth_transfer_insufficient_balance() {
.unwrap();
assert_eq!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund)
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
Expand Down Expand Up @@ -1081,7 +1081,7 @@ fn test_block_hash_contract() {
.unwrap();

let res = utils::panic_on_fail(result.status);
assert!(res.is_none(), "Status: {:?}", res);
assert!(res.is_none(), "Status: {res:?}");
}

#[cfg(not(feature = "ext-connector"))]
Expand Down Expand Up @@ -1234,9 +1234,7 @@ mod workspace {
use crate::prelude::{Address, U256};
use crate::tests::sanity::{GAS_PRICE, INITIAL_BALANCE, INITIAL_NONCE, TRANSFER_AMOUNT};
use crate::utils;
use aurora_engine_types::parameters::engine::{
TransactionStatus, TransactionStatusEvmErrorKind,
};
use aurora_engine_types::parameters::engine::{EvmErrorKind, TransactionStatus};
use aurora_engine_workspace::EngineContract;

// Same as `test_eth_transfer_insufficient_balance` above, except runs through
Expand All @@ -1262,14 +1260,6 @@ mod workspace {
&signer.secret_key,
);

let res = aurora
.submit(rlp::encode(&signed_tx).to_vec())
.transact()
.await;
if let Err(err) = res {
println!("ERROR: {:#?}", err);
}

let result = aurora
.submit(rlp::encode(&signed_tx).to_vec())
.transact()
Expand All @@ -1278,7 +1268,7 @@ mod workspace {
.into_value();
assert_eq!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund)
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use aurora_engine::{
parameters::{ResultLog, SubmitResult, TransactionStatus},
};
use aurora_engine_transactions::eip_2930::AccessTuple;
use aurora_engine_types::parameters::engine::TransactionStatusEvmErrorKind;
use aurora_engine_types::parameters::engine::EvmErrorKind;
use aurora_engine_types::{types::Address, H160};

#[test]
fn test_serde_submit_result() {
let result = SubmitResult::new(
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund),
TransactionStatus::Error(EvmErrorKind::OutOfFund),
0,
vec![ResultLog {
address: Address::default(),
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/tests/silo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use aurora_engine::engine::EngineErrorKind;
use aurora_engine_sdk as sdk;
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::borsh::BorshSerialize;
use aurora_engine_types::parameters::engine::{TransactionStatus, TransactionStatusEvmErrorKind};
use aurora_engine_types::parameters::engine::{EvmErrorKind, TransactionStatus};
use aurora_engine_types::parameters::silo::{
FixedGasArgs, SiloParamsArgs, WhitelistAccountArgs, WhitelistAddressArgs, WhitelistArgs,
WhitelistKind, WhitelistStatusArgs,
Expand Down Expand Up @@ -101,7 +101,7 @@ fn test_transfer_insufficient_balance() {
.unwrap();
assert_eq!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund)
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
Expand Down Expand Up @@ -169,7 +169,7 @@ fn test_transfer_insufficient_balance_fee() {
.unwrap();
assert!(matches!(
result.status,
TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund)
TransactionStatus::Error(EvmErrorKind::OutOfFund)
));
}

Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_standard_precompiles() {
.unwrap();

let res = utils::panic_on_fail(outcome.status);
assert!(res.is_none(), "Status: {:?}", res);
assert!(res.is_none(), "Status: {res:?}");
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions engine-types/src/parameters/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub struct ResultLog {
/// EVM error king of transaction status
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
#[cfg_attr(feature = "impl-serde", derive(Serialize, Deserialize))]
pub enum TransactionStatusEvmErrorKind {
pub enum EvmErrorKind {
/// Trying to pop from an empty stack.
StackUnderflow,
/// Trying to push into a stack over stack limit.
Expand Down Expand Up @@ -217,7 +217,7 @@ pub enum TransactionStatusEvmErrorKind {
MaxNonce,
}

impl AsRef<[u8]> for TransactionStatusEvmErrorKind {
impl AsRef<[u8]> for EvmErrorKind {
fn as_ref(&self) -> &[u8] {
match self {
Self::StackUnderflow => b"STACK_UNDERFLOW",
Expand Down Expand Up @@ -246,7 +246,7 @@ impl AsRef<[u8]> for TransactionStatusEvmErrorKind {
pub enum TransactionStatus {
Succeed(Vec<u8>),
Revert(Vec<u8>),
Error(TransactionStatusEvmErrorKind),
Error(EvmErrorKind),
}

impl TransactionStatus {
Expand Down
84 changes: 38 additions & 46 deletions engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use aurora_engine_precompiles::PrecompileConstructorContext;
use aurora_engine_types::parameters::connector::{
Erc20Identifier, Erc20Metadata, MirrorErc20TokenArgs,
};
use aurora_engine_types::parameters::engine::{FunctionCallArgsV2, TransactionStatusEvmErrorKind};
use aurora_engine_types::parameters::engine::{EvmErrorKind, FunctionCallArgsV2};
use aurora_engine_types::types::EthGas;
use core::cell::RefCell;
use core::iter::once;
Expand Down Expand Up @@ -168,29 +168,25 @@ impl From<ExitFatal> for EngineErrorKind {
}
}

impl From<TransactionStatusEvmErrorKind> for EngineErrorKind {
fn from(kind: TransactionStatusEvmErrorKind) -> Self {
impl From<EvmErrorKind> for EngineErrorKind {
fn from(kind: EvmErrorKind) -> Self {
match kind {
TransactionStatusEvmErrorKind::StackUnderflow => ExitError::StackUnderflow.into(),
TransactionStatusEvmErrorKind::StackOverflow => ExitError::StackOverflow.into(),
TransactionStatusEvmErrorKind::InvalidJump => ExitError::InvalidJump.into(),
TransactionStatusEvmErrorKind::InvalidRange => ExitError::InvalidRange.into(),
TransactionStatusEvmErrorKind::DesignatedInvalid => ExitError::DesignatedInvalid.into(),
TransactionStatusEvmErrorKind::CallTooDeep => ExitError::CallTooDeep.into(),
TransactionStatusEvmErrorKind::CreateCollision => ExitError::CreateCollision.into(),
TransactionStatusEvmErrorKind::CreateContractLimit => {
ExitError::CreateContractLimit.into()
}
TransactionStatusEvmErrorKind::InvalidCode(opcode) => {
ExitError::InvalidCode(evm::Opcode(opcode)).into()
}
TransactionStatusEvmErrorKind::OutOfOffset => ExitError::OutOfOffset.into(),
TransactionStatusEvmErrorKind::OutOfGas => ExitError::OutOfGas.into(),
TransactionStatusEvmErrorKind::OutOfFund => ExitError::OutOfFund.into(),
TransactionStatusEvmErrorKind::PCUnderflow => ExitError::PCUnderflow.into(),
TransactionStatusEvmErrorKind::CreateEmpty => ExitError::CreateEmpty.into(),
TransactionStatusEvmErrorKind::MaxNonce => ExitError::MaxNonce.into(),
TransactionStatusEvmErrorKind::Other(msg) => ExitError::Other(msg).into(),
EvmErrorKind::StackUnderflow => ExitError::StackUnderflow.into(),
EvmErrorKind::StackOverflow => ExitError::StackOverflow.into(),
EvmErrorKind::InvalidJump => ExitError::InvalidJump.into(),
EvmErrorKind::InvalidRange => ExitError::InvalidRange.into(),
EvmErrorKind::DesignatedInvalid => ExitError::DesignatedInvalid.into(),
EvmErrorKind::CallTooDeep => ExitError::CallTooDeep.into(),
EvmErrorKind::CreateCollision => ExitError::CreateCollision.into(),
EvmErrorKind::CreateContractLimit => ExitError::CreateContractLimit.into(),
EvmErrorKind::InvalidCode(opcode) => ExitError::InvalidCode(evm::Opcode(opcode)).into(),
EvmErrorKind::OutOfOffset => ExitError::OutOfOffset.into(),
EvmErrorKind::OutOfGas => ExitError::OutOfGas.into(),
EvmErrorKind::OutOfFund => ExitError::OutOfFund.into(),
EvmErrorKind::PCUnderflow => ExitError::PCUnderflow.into(),
EvmErrorKind::CreateEmpty => ExitError::CreateEmpty.into(),
EvmErrorKind::MaxNonce => ExitError::MaxNonce.into(),
EvmErrorKind::Other(msg) => ExitError::Other(msg).into(),
}
}
}
Expand All @@ -216,28 +212,22 @@ impl ExitIntoResult for ExitReason {
// To be compatible with Ethereum behaviour we should charge gas for Execution errors
Self::Error(err) => {
let error_status = match err {
ExitError::StackUnderflow => TransactionStatusEvmErrorKind::StackUnderflow,
ExitError::StackOverflow => TransactionStatusEvmErrorKind::StackOverflow,
ExitError::InvalidJump => TransactionStatusEvmErrorKind::InvalidJump,
ExitError::InvalidRange => TransactionStatusEvmErrorKind::InvalidRange,
ExitError::DesignatedInvalid => {
TransactionStatusEvmErrorKind::DesignatedInvalid
}
ExitError::CallTooDeep => TransactionStatusEvmErrorKind::CallTooDeep,
ExitError::CreateCollision => TransactionStatusEvmErrorKind::CreateCollision,
ExitError::CreateContractLimit => {
TransactionStatusEvmErrorKind::CreateContractLimit
}
ExitError::InvalidCode(opcode) => {
TransactionStatusEvmErrorKind::InvalidCode(opcode.0)
}
ExitError::OutOfOffset => TransactionStatusEvmErrorKind::OutOfOffset,
ExitError::OutOfGas => TransactionStatusEvmErrorKind::OutOfGas,
ExitError::OutOfFund => TransactionStatusEvmErrorKind::OutOfFund,
ExitError::PCUnderflow => TransactionStatusEvmErrorKind::PCUnderflow,
ExitError::CreateEmpty => TransactionStatusEvmErrorKind::CreateEmpty,
ExitError::MaxNonce => TransactionStatusEvmErrorKind::MaxNonce,
ExitError::Other(msg) => TransactionStatusEvmErrorKind::Other(msg),
ExitError::StackUnderflow => EvmErrorKind::StackUnderflow,
ExitError::StackOverflow => EvmErrorKind::StackOverflow,
ExitError::InvalidJump => EvmErrorKind::InvalidJump,
ExitError::InvalidRange => EvmErrorKind::InvalidRange,
ExitError::DesignatedInvalid => EvmErrorKind::DesignatedInvalid,
ExitError::CallTooDeep => EvmErrorKind::CallTooDeep,
ExitError::CreateCollision => EvmErrorKind::CreateCollision,
ExitError::CreateContractLimit => EvmErrorKind::CreateContractLimit,
ExitError::InvalidCode(opcode) => EvmErrorKind::InvalidCode(opcode.0),
ExitError::OutOfOffset => EvmErrorKind::OutOfOffset,
ExitError::OutOfGas => EvmErrorKind::OutOfGas,
ExitError::OutOfFund => EvmErrorKind::OutOfFund,
ExitError::PCUnderflow => EvmErrorKind::PCUnderflow,
ExitError::CreateEmpty => EvmErrorKind::CreateEmpty,
ExitError::MaxNonce => EvmErrorKind::MaxNonce,
ExitError::Other(msg) => EvmErrorKind::Other(msg),
};
Ok(TransactionStatus::Error(error_status))
}
Expand Down Expand Up @@ -1963,6 +1953,8 @@ impl<'env, I: IO + Copy, E: Env, M: ModExpAlgorithm> Backend for Engine<'env, I,
result
}

/// Check if the storage of the address is empty.
/// Related to EIP-7610.
fn is_empty_storage(&self, address: H160) -> bool {
let address = Address::new(address);
if self
Expand Down Expand Up @@ -2267,7 +2259,7 @@ mod tests {
});
let actual_result = engine.call_with_args(args, &mut handler).unwrap();

let expected_status = TransactionStatus::Error(TransactionStatusEvmErrorKind::OutOfFund);
let expected_status = TransactionStatus::Error(EvmErrorKind::OutOfFund);
let expected_gas_used = 21000;
let expected_logs = Vec::new();
let expected_result = SubmitResult::new(expected_status, expected_gas_used, expected_logs);
Expand Down

0 comments on commit 74bc509

Please sign in to comment.