Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: refactore gas charge logic form EVM exit reason #935

Merged
merged 26 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0647fcd
Gas cost estimation fot aurora-evm usize checked casting
mrLSD Jun 26, 2024
8866fbe
Changes gas costs
mrLSD Jun 26, 2024
8f0d5bc
Fix clippy
mrLSD Jun 27, 2024
551b79d
Update SpuntikVM to v0.44.1-aurora and change gas costs for some tests
mrLSD Jul 3, 2024
f79d294
Refactore EVM ExitReason gas charge logic
mrLSD Jul 5, 2024
0dd2cb9
Merge branch 'develop' into feat/charge-gas-refactoring
mrLSD Aug 12, 2024
a993c64
Extended TransactionStatus erros and added From impls for EVM ExitError
mrLSD Aug 13, 2024
16f1551
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Aug 13, 2024
763823d
Refactore tests
mrLSD Aug 13, 2024
48999d3
Refactore tests
mrLSD Aug 13, 2024
74bc509
Renamed EvmErrorKind and added Docs
mrLSD Aug 13, 2024
fc1aeeb
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Aug 13, 2024
8e5a941
Test: test_contract_create_too_large - change expected error
mrLSD Aug 13, 2024
4bc53ae
Changed comment for test: test_contract_create_too_large
mrLSD Aug 13, 2024
4945df0
Update to evm-0.45.1-aurora - with ExitFatal refactoring
mrLSD Aug 13, 2024
9a74881
Added chenges from PR review
mrLSD Aug 13, 2024
0ef3c57
Return panic erorr message
mrLSD Aug 14, 2024
56d8b35
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Aug 14, 2024
0e8b034
Update gas cost
mrLSD Aug 14, 2024
a672169
Return empty line
mrLSD Aug 14, 2024
e92d8b6
Refactore is_empty_storage
mrLSD Aug 14, 2024
ad70951
Refactore is_empty_storage
mrLSD Aug 14, 2024
40d2eed
Returned TransactionStatus old attributes. Adde test: is_empty_storage
mrLSD Aug 20, 2024
b979225
Added transaction_status order test. Fixed is_fail func
mrLSD Aug 21, 2024
20bc926
Fix clippy
mrLSD Aug 21, 2024
fdde7a5
chore: use plain enum for the TransactionStatus (#949)
aleksuss Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ byte-slice-cast = { version = "1", default-features = false }
criterion = "0.5"
digest = "0.10"
ethabi = { version = "18", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.43.1-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.43.1-aurora", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.43.1-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.43.1-aurora", default-features = false, features = ["std", "tracing"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.45.0-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.45.0-aurora", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.45.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.45.0-aurora", default-features = false, features = ["std", "tracing"] }
fixed-hash = { version = "0.8", default-features = false }
function_name = "0.3"
git2 = "0.19"
Expand Down
13 changes: 10 additions & 3 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::parameters::connector::{
Erc20Identifier, Erc20Metadata, SetErc20MetadataArgs,
};
use aurora_engine_types::parameters::engine::SetOwnerArgs;
use aurora_engine_types::parameters::engine::{EvmErrorKind, SetOwnerArgs};
use bstr::ByteSlice;

use libsecp256k1::SecretKey;
use std::str::FromStr;

Expand Down Expand Up @@ -78,7 +79,10 @@ fn erc20_mint_out_of_gas() {
mint_tx.gas_price = U256::from(GAS_PRICE); // also set non-zero gas price to check gas still charged.
let outcome = runner.submit_transaction(&source_account.secret_key, mint_tx);
let error = outcome.unwrap();
assert_eq!(error.status, TransactionStatus::OutOfGas);
assert_eq!(
error.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);

// Validate post-state

Expand Down Expand Up @@ -232,7 +236,10 @@ fn deploy_erc_20_out_of_gas() {
deploy_transaction.gas_limit = U256::from(intrinsic_gas + 1);
let outcome = runner.submit_transaction(&source_account, deploy_transaction);
let error = outcome.unwrap();
assert_eq!(error.status, TransactionStatus::OutOfGas);
assert_eq!(
error.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);

// Validate post-state
utils::validate_address_balance_and_nonce(
Expand Down
12 changes: 6 additions & 6 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn repro_GdASJ3KESs() {
block_timestamp: 1_645_717_564_644_206_730,
input_path: "src/tests/res/input_GdASJ3KESs.hex",
evm_gas_used: 706_713,
near_gas_used: 113,
near_gas_used: 114,
});
}

Expand All @@ -51,7 +51,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1_648_829_935_343_349_589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1_732_181,
near_gas_used: 204,
near_gas_used: 205,
});
}

Expand All @@ -71,7 +71,7 @@ fn repro_FRcorNv() {
block_timestamp: 1_650_960_438_774_745_116,
input_path: "src/tests/res/input_FRcorNv.hex",
evm_gas_used: 1_239_721,
near_gas_used: 165,
near_gas_used: 167,
});
}

Expand All @@ -88,7 +88,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1_651_073_772_931_594_646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 645,
near_gas_used: 649,
});
}

Expand All @@ -106,7 +106,7 @@ fn repro_D98vwmi() {
block_timestamp: 1_651_753_443_421_003_245,
input_path: "src/tests/res/input_D98vwmi.hex",
evm_gas_used: 1_035_348,
near_gas_used: 167,
near_gas_used: 168,
});
}

Expand All @@ -125,7 +125,7 @@ fn repro_Emufid2() {
block_timestamp: 1_662_118_048_636_713_538,
input_path: "src/tests/res/input_Emufid2.hex",
evm_gas_used: 1_156_364,
near_gas_used: 291,
near_gas_used: 293,
});
}

Expand Down
32 changes: 25 additions & 7 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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::EvmErrorKind;
use aurora_engine_types::H160;
use libsecp256k1::SecretKey;
use near_vm_runner::ContractCode;
Expand Down Expand Up @@ -54,7 +55,10 @@ fn bench_memory_get_standalone() {
.unwrap();
let duration = start.elapsed().as_secs_f32();
assert!(
matches!(result.status, TransactionStatus::OutOfGas),
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"Infinite loops in the EVM run out of gas"
);
assert!(
Expand Down Expand Up @@ -108,7 +112,10 @@ fn test_returndatacopy() {
let address = deploy_contract(&mut runner, &mut signer, contract_bytes);
let result = call_contract(&mut runner, &mut signer, address);
assert!(
matches!(result.status, TransactionStatus::OutOfGas),
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"EVM must run out of gas if len > 0 with large memory offset"
);
}
Expand Down Expand Up @@ -564,7 +571,10 @@ fn test_create_out_of_gas() {
})
.unwrap();
assert!(
matches!(result.status, TransactionStatus::OutOfGas),
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
"Unexpected status: {:?}",
result.status
);
Expand Down Expand Up @@ -758,7 +768,10 @@ fn test_eth_transfer_insufficient_balance() {
utils::transfer(dest_address, INITIAL_BALANCE + INITIAL_BALANCE, nonce)
})
.unwrap();
assert_eq!(result.status, TransactionStatus::OutOfFund);
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
utils::validate_address_balance_and_nonce(
Expand Down Expand Up @@ -1067,7 +1080,8 @@ fn test_block_hash_contract() {
})
.unwrap();

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

#[cfg(not(feature = "ext-connector"))]
Expand Down Expand Up @@ -1220,7 +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;
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 @@ -1245,13 +1259,17 @@ mod workspace {
Some(utils::AuroraRunner::default().chain_id),
&signer.secret_key,
);

let result = aurora
.submit(rlp::encode(&signed_tx).to_vec())
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
.transact()
.await
.unwrap()
.into_value();
assert_eq!(result.status, TransactionStatus::OutOfFund);
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion engine-tests/src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use aurora_engine::{
parameters::{ResultLog, SubmitResult, TransactionStatus},
};
use aurora_engine_transactions::eip_2930::AccessTuple;
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::OutOfFund,
TransactionStatus::Error(EvmErrorKind::OutOfFund),
0,
vec![ResultLog {
address: Address::default(),
Expand Down
12 changes: 9 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;
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 @@ -99,7 +99,10 @@ fn test_transfer_insufficient_balance() {
)
})
.unwrap();
assert_eq!(result.status, TransactionStatus::OutOfFund);
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);

// validate post-state
validate_address_balance_and_nonce(
Expand Down Expand Up @@ -164,7 +167,10 @@ fn test_transfer_insufficient_balance_fee() {
utils::transfer_with_price(receiver, TRANSFER_AMOUNT, nonce, ONE_GAS_PRICE.raw())
})
.unwrap();
assert!(matches!(result.status, TransactionStatus::OutOfFund));
assert!(matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
));
}

#[test]
Expand Down
9 changes: 5 additions & 4 deletions engine-tests/src/tests/standalone/call_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::prelude::{H160, H256};
use crate::utils::solidity::erc20::{ERC20Constructor, ERC20};
use crate::utils::{self, standalone, Signer};
use aurora_engine_modexp::AuroraModExp;
use aurora_engine_types::parameters::engine::{EvmErrorKind, TransactionStatus};
use aurora_engine_types::{
parameters::{CrossContractCallArgs, PromiseArgs, PromiseCreateArgs},
storage,
Expand Down Expand Up @@ -296,10 +297,10 @@ fn test_contract_create_too_large() {
let standalone_result = sputnik::traced_call(&mut listener, || {
runner.submit_transaction(&signer.secret_key, tx)
});
assert!(
standalone_result.is_err(),
"Expected contract too large error"
);
assert!(matches!(
standalone_result.unwrap().status,
TransactionStatus::Error(EvmErrorKind::CreateContractLimit)
));
}

#[allow(clippy::too_many_lines)]
Expand Down
3 changes: 2 additions & 1 deletion engine-tests/src/tests/standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fn test_standard_precompiles() {
.submit_with_signer(&mut signer, |nonce| contract.call_method("test_all", nonce))
.unwrap();

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

#[test]
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_uniswap_exact_output() {

let (_amount_in, profile) =
context.exact_output_single(&token_a, &token_b, OUTPUT_AMOUNT.into());
utils::assert_gas_bound(profile.all_gas(), 16);
utils::assert_gas_bound(profile.all_gas(), 17);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(40..=50).contains(&wasm_fraction),
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ pub mod workspace {
.unwrap();
anyhow::bail!("TX has been reverted with message: {revert_message}");
}
_ => anyhow::bail!("Wrong status of the transaction"),
TransactionStatus::Error(_) => anyhow::bail!("Wrong status of the transaction"),
}
}

Expand Down
12 changes: 8 additions & 4 deletions engine-tests/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,15 @@ pub fn unwrap_revert_slice(result: &SubmitResult) -> &[u8] {
}
}

pub fn panic_on_fail(status: TransactionStatus) {
pub fn panic_on_fail(status: TransactionStatus) -> Option<String> {
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
match status {
TransactionStatus::Succeed(_) => (),
TransactionStatus::Revert(message) => panic!("{}", String::from_utf8_lossy(&message)),
other => panic!("{}", String::from_utf8_lossy(other.as_ref())),
TransactionStatus::Succeed(_) => None,
TransactionStatus::Revert(message) => {
Some(format!("Revert: {}", String::from_utf8_lossy(&message)))
}
TransactionStatus::Error(err) => {
Some(format!("Error: {}", String::from_utf8_lossy(err.as_ref())))
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion engine-tests/src/utils/solidity/exit_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ impl Tester {
match result.status {
aurora_engine::parameters::TransactionStatus::Succeed(_) => Ok(result),
aurora_engine::parameters::TransactionStatus::Revert(_bytes) => Err(Revert),
other => panic!("Unexpected status {other:?}"),
aurora_engine::parameters::TransactionStatus::Error(err) => {
panic!("Unexpected status {err:?}")
mrLSD marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
Loading
Loading