Skip to content

Commit

Permalink
Merge branch 'develop' into fix/birchmd/audit-aur-30
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored May 8, 2023
2 parents e8719ba + b63bab7 commit b361906
Show file tree
Hide file tree
Showing 31 changed files with 1,871 additions and 1,051 deletions.
2,063 changes: 1,479 additions & 584 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine-precompiles/src/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod costs {
///
/// This process is done in the `test_xcc_eth_gas_cost` test in
/// `engine-tests/src/tests/xcc.rs`.
pub const CROSS_CONTRACT_CALL_BASE: EthGas = EthGas::new(323_000);
pub const CROSS_CONTRACT_CALL_BASE: EthGas = EthGas::new(343_650);
/// Additional EVM gas cost per bytes of input given.
/// See `CROSS_CONTRACT_CALL_BASE` for estimation methodology.
pub const CROSS_CONTRACT_CALL_BYTE: EthGas = EthGas::new(3);
Expand Down
45 changes: 22 additions & 23 deletions engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,37 @@ autobenches = false

[dev-dependencies]
aurora-engine = { path = "../engine", default-features = false, features = ["std", "tracing", "impl-serde"] }
aurora-engine-test-doubles = { path = "../engine-test-doubles", default-features = false }
aurora-engine-types = { path = "../engine-types", default-features = false, features = ["std", "impl-serde"] }
aurora-engine-sdk = { path = "../engine-sdk", default-features = false, features = ["std"] }
aurora-engine-precompiles = { path = "../engine-precompiles", default-features = false, features = ["std"] }
aurora-engine-sdk = { path = "../engine-sdk", default-features = false, features = ["std"] }
aurora-engine-test-doubles = { path = "../engine-test-doubles", default-features = false }
aurora-engine-transactions = { path = "../engine-transactions", default-features = false, features = ["std", "impl-serde"] }
engine-standalone-storage = { path = "../engine-standalone-storage" }
engine-standalone-tracing = { path = "../engine-standalone-tracing", default-features = false, features = ["impl-serde"] }
aurora-engine-types = { path = "../engine-types", default-features = false, features = ["std", "impl-serde"] }
borsh = { version = "0.10", default-features = false }
sha3 = { version = "0.10.2", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
rlp = { version = "0.5.0", default-features = false }
bstr = "1.0.1"
byte-slice-cast = { version = "1.0", default-features = false }
criterion = "0.4.0"
engine-standalone-storage = { path = "../engine-standalone-storage" }
engine-standalone-tracing = { path = "../engine-standalone-tracing", default-features = false, features = ["impl-serde"] }
ethabi = "18.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
git2 = "0.17"
hex = { version = "0.4.3", default-features = false }
near-sdk = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "a4634850023fd115053970f17e10861779d5167d" }
near-sdk-sim = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "a4634850023fd115053970f17e10861779d5167d" }
near-crypto = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04" }
near-vm-errors = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04" }
near-vm-runner = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04", default-features = false, features = [ "wasmer2_vm" ] }
near-vm-logic = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04" }
near-primitives-core = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04" }
near-primitives = { git = "https://github.com/birchmd/nearcore.git", rev = "6033903be2037d67510188450f289b2d6e033f04", default-features = false, features = [ "nightly_protocol" ] }
libsecp256k1 = { version = "0.7.0", default-features = false }
near-crypto = "0.16"
near-primitives = "0.16"
near-primitives-core = "0.16"
near-sdk-sim = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" }
near-vm-errors = "0.16"
near-vm-logic = "0.16"
near-vm-runner = { version = "0.16", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] }
rand = "0.8.5"
criterion = "0.4.0"
git2 = "0.16"
tempfile = "3.2.0"
rlp = { version = "0.5.0", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha3 = { version = "0.10.2", default-features = false }
tempfile = "3"
walrus = "0.19"

[features]
Expand Down
7 changes: 3 additions & 4 deletions engine-tests/src/benches/eth_deploy_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ pub fn eth_deploy_code_benchmark(c: &mut Criterion) {
// measure gas usage
for input in &inputs {
let input_size = input.len();
let (output, maybe_err) = runner
let output = runner
.one_shot()
.call(SUBMIT, calling_account_id, input.clone());
assert!(maybe_err.is_none());
let output = output.unwrap();
.call(SUBMIT, calling_account_id, input.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
Expand Down
16 changes: 7 additions & 9 deletions engine-tests/src/benches/eth_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ pub fn eth_erc20_benchmark(c: &mut Criterion) {

// Measure mint gas usage; don't use `one_shot` because we want to keep this state change for
// the next benchmark where we transfer some of the minted tokens.
let (output, maybe_error) = runner.call(SUBMIT, calling_account_id, mint_tx_bytes.clone());
assert!(maybe_error.is_none());
let output = output.unwrap();
let output = runner
.call(SUBMIT, calling_account_id, mint_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("ETH_ERC20_MINT NEAR GAS: {gas:?}");
println!("ETH_ERC20_MINT ETH GAS: {eth_gas:?}");

// Measure transfer gas usage
let (output, maybe_err) =
runner
.one_shot()
.call(SUBMIT, calling_account_id, transfer_tx_bytes.clone());
assert!(maybe_err.is_none());
let output = output.unwrap();
let output = runner
.one_shot()
.call(SUBMIT, calling_account_id, transfer_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
Expand Down
10 changes: 4 additions & 6 deletions engine-tests/src/benches/eth_standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ pub fn eth_standard_precompiles_benchmark(c: &mut Criterion) {

// measure gas usage
for (tx_bytes, name) in transactions.iter().zip(test_names.iter()) {
let (output, maybe_err) =
runner
.one_shot()
.call(SUBMIT, calling_account_id, tx_bytes.clone());
assert!(maybe_err.is_none());
let output = output.unwrap();
let output = runner
.one_shot()
.call(SUBMIT, calling_account_id, tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
Expand Down
8 changes: 4 additions & 4 deletions engine-tests/src/benches/eth_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub fn eth_transfer_benchmark(c: &mut Criterion) {
let calling_account_id = "some-account.near";

// measure gas usage
let (output, maybe_err) = runner
let output = runner
.one_shot()
.call(SUBMIT, calling_account_id, input.clone());
assert!(maybe_err.is_none());
let gas = output.unwrap().burnt_gas;
.call(SUBMIT, calling_account_id, input.clone())
.unwrap();
let gas = output.burnt_gas;
// TODO(#45): capture this in a file
println!("ETH_TRANSFER NEAR GAS: {gas:?}");
println!("ETH_TRANSFER ETH GAS: 21_000");
Expand Down
8 changes: 5 additions & 3 deletions engine-tests/src/benches/nft_pagination.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::{Address, Wei, U256};
use crate::test_utils::{self, solidity};
use aurora_engine_transactions::legacy::TransactionLegacy;
use aurora_engine_types::parameters::engine::TransactionStatus;
use libsecp256k1::SecretKey;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -42,10 +43,11 @@ pub fn measure_gas_usage(total_tokens: usize, data_size: usize, tokens_per_page:
// show them
let nonce = source_account.nonce;
let tx = marketplace.get_page(tokens_per_page, 0, nonce.into());
let (result, profile) = runner.profiled_view_call(&test_utils::as_view_call(tx, dest_address));
let (status, profile) = runner
.profiled_view_call(&test_utils::as_view_call(tx, dest_address))
.unwrap();

let status = result.unwrap();
assert!(status.is_ok());
assert!(matches!(status, TransactionStatus::Succeed(_)));
profile.all_gas()
}

Expand Down
26 changes: 11 additions & 15 deletions engine-tests/src/benches/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,24 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) {

// Measure add_liquidity gas usage; don't use `one_shot` because we want to keep
// this state change for the next benchmark where we swap some tokens in the pool.
let (output, maybe_error) =
context
.runner
.call(SUBMIT, calling_account_id, liquidity_tx_bytes.clone());
assert!(maybe_error.is_none());
let output = output.unwrap();
let result = context
.runner
.call(SUBMIT, calling_account_id, liquidity_tx_bytes.clone());
let output = result.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("UNISWAP_ADD_LIQUIDITY NEAR GAS: {gas:?}");
println!("UNISWAP_ADD_LIQUIDITY ETH GAS: {eth_gas:?}");

// Measure swap gas usage
let (output, maybe_error) =
context
.runner
.one_shot()
.call(SUBMIT, calling_account_id, swap_tx_bytes.clone());
assert!(maybe_error.is_none());
let output = output.unwrap();
let output = context
.runner
.one_shot()
.call(SUBMIT, calling_account_id, swap_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = test_utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("UNISWAP_SWAP NEAR GAS: {gas:?}");
println!("UNISWAP_SWAP ETH GAS: {eth_gas:?}");
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/test_utils/exit_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::prelude::{
parameters::SubmitResult, transactions::legacy::TransactionLegacy, Address, Wei, U256,
};
use crate::test_utils::{self, solidity, AuroraRunner, Signer};
use near_vm_errors::VMError;
use aurora_engine::engine::EngineError;

pub struct TesterConstructor(pub solidity::ContractConstructor);

Expand Down Expand Up @@ -69,7 +69,7 @@ impl Tester {
method: &str,
value: Wei,
params: &[ethabi::Token],
) -> Result<SubmitResult, VMError> {
) -> Result<SubmitResult, EngineError> {
let data = self
.contract
.abi
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Tester {
runner: &mut AuroraRunner,
signer: &mut Signer,
flag: bool,
) -> Result<SubmitResult, VMError> {
) -> Result<SubmitResult, EngineError> {
self.call_function(
runner,
signer,
Expand Down
3 changes: 2 additions & 1 deletion engine-tests/src/test_utils/mocked_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ impl near_vm_logic::External for MockedExternalWithTrie {
fn storage_get<'a>(
&'a self,
key: &[u8],
mode: near_vm_logic::StorageGetMode,
) -> Result<Option<Box<dyn near_vm_logic::ValuePtr + 'a>>, near_vm_logic::VMLogicError> {
self.increment_new_trie_node_count(MAINNET_AVERAGE_TOUCHED_TRIE_PER_READ);
self.increment_cached_trie_node_count(MAINNET_AVERAGE_READ_CACHED_TRIE_PER_READ);
self.underlying.storage_get(key)
self.underlying.storage_get(key, mode)
}

fn storage_remove(&mut self, key: &[u8]) -> Result<(), near_vm_logic::VMLogicError> {
Expand Down
Loading

0 comments on commit b361906

Please sign in to comment.