Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/etc/eth-contracts…
Browse files Browse the repository at this point in the history
…/follow-redirects-1.15.4
  • Loading branch information
aleksuss authored Jan 18, 2024
2 parents a24811c + 458d0b8 commit 5cb6a72
Show file tree
Hide file tree
Showing 35 changed files with 1,396 additions and 904 deletions.
1,908 changes: 1,148 additions & 760 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ ibig = { version = "0.3", default-features = false, features = ["num-traits"] }
impl-serde = { version = "0.4", default-features = false}
lazy_static = "1"
libsecp256k1 = { version = "0.7", default-features = false }
near-crypto = "0.17"
near-crypto = "0.20"
near-gas = "0.2"
near-primitives = "0.17"
near-primitives-core = "0.17"
near-parameters = "0.20"
near-primitives = "0.20"
near-primitives-core = "0.20"
near-sdk = "4"
near-vm-errors = "0.17"
near-vm-logic = "0.17"
near-vm-runner = { version = "0.17", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] }
near-vm-runner = { version = "0.20", features = [ "wasmtime_vm", "wasmer2_vm" ] }
near-workspaces = "0.9"
num = { version = "0.4", default-features = false, features = ["alloc"] }
postgres = "0.19"
Expand Down
5 changes: 1 addition & 4 deletions engine-hashchain/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
//! Link: <https://github.com/paritytech/parity-common/blob/master/ethbloom/src/lib.rs>
//!
//! Reimplemented here since there is a large mismatch in types and dependencies.
#![allow(
clippy::expl_impl_clone_on_copy,
// TODO: rust-2023-08-24 clippy::incorrect_clone_impl_on_copy_type
)]
#![allow(clippy::expl_impl_clone_on_copy, clippy::non_canonical_clone_impl)]

use aurora_engine_sdk::keccak;
use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize};
Expand Down
2 changes: 1 addition & 1 deletion engine-modexp/src/mpnat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ fn test_mp_nat_be() {
let output = mp.to_big_endian();
let hex_output = hex::encode(output);
let trimmed = match hex_input.trim_start_matches('0') {
x if x.is_empty() => "00",
"" => "00",
x => x,
};
assert_eq!(hex_output, trimmed)
Expand Down
3 changes: 1 addition & 2 deletions engine-precompiles/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub use aurora_engine_sdk as sdk;
pub use aurora_engine_types::account_id::*;
pub use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize};
pub use aurora_engine_types::borsh::BorshSerialize;
pub use aurora_engine_types::parameters;
pub use aurora_engine_types::storage;
pub use aurora_engine_types::types;
Expand Down
9 changes: 4 additions & 5 deletions engine-sdk/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub use aurora_engine_types::types::{Address, NearGas, PromiseResult, STORAGE_PRICE_PER_BYTE};
pub use aurora_engine_types::{
borsh::{BorshDeserialize, BorshSerialize},
vec, Vec, H256, U256,
};
pub use aurora_engine_types::types::{Address, NearGas, STORAGE_PRICE_PER_BYTE};
#[cfg(feature = "contract")]
pub use aurora_engine_types::U256;
pub use aurora_engine_types::{vec, Vec, H256};
8 changes: 8 additions & 0 deletions engine-standalone-storage/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ impl Diff {
Self::try_from_slice(bytes)
}
}

impl<'diff> IntoIterator for &'diff Diff {
type Item = (&'diff Vec<u8>, &'diff DiffValue);
type IntoIter = btree_map::Iter<'diff, Vec<u8>, DiffValue>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
2 changes: 1 addition & 1 deletion engine-standalone-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Storage {
let diff_bytes = diff.try_to_bytes().unwrap();
action(&mut batch, &storage_key, &diff_bytes);

for (key, value) in diff.iter() {
for (key, value) in diff {
let storage_key = construct_engine_key(key, block_height, tx_included.position);
let value_bytes = value.try_to_bytes().unwrap();
action(&mut batch, &storage_key, &value_bytes);
Expand Down
1 change: 1 addition & 0 deletions engine-tests-connector/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl TestContract {
"metadata": metadata,
"account_with_access_right": account_with_access_right,
"owner_id": owner_id,
"min_proof_acceptance_height": 0,
}))
.gas(DEFAULT_GAS)
.transact()
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ git2.workspace = true
hex.workspace = true
libsecp256k1.workspace = true
near-crypto.workspace = true
near-parameters.workspace = true
near-primitives-core.workspace = true
near-primitives.workspace = true
near-sdk.workspace = true
near-vm-errors.workspace = true
near-vm-logic.workspace = true
near-vm-runner.workspace = true
rand.workspace = true
reqwest.workspace = true
Expand Down
1 change: 0 additions & 1 deletion engine-tests/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod v0 {
pub use aurora_engine::parameters;
pub use aurora_engine_sdk as sdk;
pub use aurora_engine_transactions as transactions;
pub use aurora_engine_types::parameters::*;
pub use aurora_engine_types::storage;
pub use aurora_engine_types::types::*;
pub use aurora_engine_types::*;
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/contract_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn setup_test() -> (AuroraRunner, Signer, Address, Tester) {
}

#[test]
#[should_panic]
#[should_panic(expected = "ERR_ARG_PARSE")]
fn test_deploy_erc20_token_with_invalid_account_id() {
let mut runner = deploy_runner();
let invalid_nep141 = "_";
Expand Down
4 changes: 1 addition & 3 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ fn erc20_mint_out_of_gas() {
.unwrap();
utils::validate_address_balance_and_nonce(
&runner,
sdk::types::near_account_to_evm_address(
runner.context.predecessor_account_id.as_ref().as_bytes(),
),
sdk::types::near_account_to_evm_address(runner.context.predecessor_account_id.as_bytes()),
Wei::new_u64(GAS_LIMIT * GAS_PRICE),
U256::zero(),
)
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::engine::{SubmitResult, TransactionStatus};
use ethabi::Token;
use libsecp256k1::SecretKey;
use near_vm_logic::VMOutcome;
use near_vm_runner::logic::VMOutcome;
use serde_json::json;
use sha3::Digest;

Expand Down
5 changes: 3 additions & 2 deletions engine-tests/src/tests/modexp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aurora_engine::engine::EngineError;
use near_primitives_core::contract::ContractCode;
use near_vm_runner::ContractCode;
use rand::{Rng, SeedableRng};

use super::sanity::initialize_transfer;
Expand Down Expand Up @@ -71,12 +71,13 @@ fn bench_modexp() {
"Aurora not least:\n{result:?}"
);

// TODO: Aurora not least anymore after switching to the nightly-2023-12-15.
// Typical example with U256-sized inputs.
let input = BenchInput::random(32);
let result = context.bench(&input);
assert_eq!(
result.least(),
Implementation::Aurora,
Implementation::IBig, // FIXME: Should be Aurora.
"Aurora not least:\n{result:?}"
);
}
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/one_inch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils::one_inch::liquidity_protocol;
use crate::utils::{self, assert_gas_bound};
use aurora_engine_types::borsh::BorshDeserialize;
use libsecp256k1::SecretKey;
use near_vm_logic::VMOutcome;
use near_vm_runner::logic::VMOutcome;
use std::sync::Once;

const INITIAL_BALANCE: Wei = Wei::new_u64(1_000_000);
Expand All @@ -22,7 +22,7 @@ fn test_1inch_liquidity_protocol() {

let (result, profile, deployer_address) = helper.create_mooniswap_deployer();
assert!(result.gas_used >= 5_100_000); // more than 5.1M EVM gas used
assert_gas_bound(profile.all_gas(), 10); // less than 10 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 11); // less than 11 NEAR Tgas used

let (result, profile, pool_factory) = helper.create_pool_factory(&deployer_address);
assert!(result.gas_used >= 2_800_000); // more than 2.8M EVM gas used
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: 121,
near_gas_used: 116,
});
}

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: 219,
near_gas_used: 210,
});
}

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: 178,
near_gas_used: 170,
});
}

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: 649,
near_gas_used: 655,
});
}

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: 180,
near_gas_used: 172,
});
}

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: 282,
near_gas_used: 296,
});
}

Expand Down
16 changes: 7 additions & 9 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::connector::FungibleTokenMetadata;
use aurora_engine_types::H160;
use libsecp256k1::SecretKey;
use near_vm_runner::ContractCode;
use rand::RngCore;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -304,7 +305,7 @@ fn test_deploy_largest_contract() {
);

// Less than 12 NEAR Tgas
utils::assert_gas_bound(profile.all_gas(), 10);
utils::assert_gas_bound(profile.all_gas(), 11);
}

#[test]
Expand Down Expand Up @@ -455,7 +456,7 @@ fn test_solidity_pure_bench() {
base_path.join("target/wasm32-unknown-unknown/release/benchmark_contract.wasm");
utils::rust::compile(base_path);
let contract_bytes = std::fs::read(output_path).unwrap();
let code = near_primitives_core::contract::ContractCode::new(contract_bytes, None);
let code = ContractCode::new(contract_bytes, None);
let mut context = runner.context.clone();
context.input = loop_limit.to_le_bytes().to_vec();
let outcome = near_vm_runner::run(
Expand All @@ -466,7 +467,6 @@ fn test_solidity_pure_bench() {
&runner.wasm_config,
&runner.fees_config,
&[],
runner.current_protocol_version,
Some(&runner.cache),
)
.unwrap();
Expand Down Expand Up @@ -907,9 +907,8 @@ fn test_transfer_charging_gas_success() {
let expected_source_balance = INITIAL_BALANCE - TRANSFER_AMOUNT - spent_amount;
let expected_dest_balance = TRANSFER_AMOUNT;
let expected_relayer_balance = spent_amount;
let relayer_address = sdk::types::near_account_to_evm_address(
runner.context.predecessor_account_id.as_ref().as_bytes(),
);
let relayer_address =
sdk::types::near_account_to_evm_address(runner.context.predecessor_account_id.as_bytes());

// validate post-state
utils::validate_address_balance_and_nonce(
Expand Down Expand Up @@ -969,9 +968,8 @@ fn test_eth_transfer_charging_gas_not_enough_balance() {
);

// validate post-state
let relayer = sdk::types::near_account_to_evm_address(
runner.context.predecessor_account_id.as_ref().as_bytes(),
);
let relayer =
sdk::types::near_account_to_evm_address(runner.context.predecessor_account_id.as_bytes());

utils::validate_address_balance_and_nonce(
&runner,
Expand Down
5 changes: 2 additions & 3 deletions engine-tests/src/tests/silo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ fn test_relayer_balance_after_transfer() {
.submit_with_signer(&mut source_account, transaction)
.unwrap();

let relayer = sdk::types::near_account_to_evm_address(
runner.context.predecessor_account_id.as_ref().as_bytes(),
);
let relayer =
sdk::types::near_account_to_evm_address(runner.context.predecessor_account_id.as_bytes());

// validate post-state
validate_address_balance_and_nonce(
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/standalone/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn test_consume_deploy_message() {
})
.unwrap();
let mut deployed_address = Address::zero();
for (key, value) in diff.iter() {
for (key, value) in &diff {
match value.value() {
Some(bytes) if bytes == code.as_slice() => {
deployed_address = Address::try_from_slice(&key[2..22]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/standalone/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_evm_tracing_with_storage() {

// Move it over to the same address as it exists on mainnet
let mut diff = engine_standalone_storage::Diff::default();
for (key, value) in runner.get_current_state().iter() {
for (key, value) in runner.get_current_state() {
if key.len() >= 22 && &key[2..22] == contract_address.as_bytes() {
let mut new_key = key.clone();
new_key[2..22].copy_from_slice(weth_address.as_bytes());
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/tests/standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_standard_precompiles() {
#[test]
fn profile_ecrecover() {
let profile = precompile_execution_profile("test_ecrecover");
utils::assert_gas_bound(profile.all_gas(), 6);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
Expand Down Expand Up @@ -60,25 +60,25 @@ fn profile_modexp() {
#[test]
fn profile_ecadd() {
let profile = precompile_execution_profile("test_ecadd");
utils::assert_gas_bound(profile.all_gas(), 6);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_ecmul() {
let profile = precompile_execution_profile("test_ecmul");
utils::assert_gas_bound(profile.all_gas(), 7);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_ecpair() {
let profile = precompile_execution_profile("test_ecpair");
utils::assert_gas_bound(profile.all_gas(), 102);
utils::assert_gas_bound(profile.all_gas(), 115);
}

#[test]
fn profile_blake2f() {
let profile = precompile_execution_profile("test_blake2f");
utils::assert_gas_bound(profile.all_gas(), 6);
utils::assert_gas_bound(profile.all_gas(), 5);
}

fn initialize() -> (AuroraRunner, Signer, PrecompilesContract) {
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn test_uniswap_input_multihop() {

let (_amount_out, _evm_gas, profile) = context.exact_input(&tokens, INPUT_AMOUNT.into());

assert_eq!(115, profile.all_gas() / 1_000_000_000_000);
assert_eq!(109, profile.all_gas() / 1_000_000_000_000);
}

#[test]
Expand All @@ -49,7 +49,7 @@ fn test_uniswap_exact_output() {

let (_result, profile) =
context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
utils::assert_gas_bound(profile.all_gas(), 32);
utils::assert_gas_bound(profile.all_gas(), 31);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(40..=50).contains(&wasm_fraction),
Expand All @@ -58,11 +58,11 @@ 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(), 17);
utils::assert_gas_bound(profile.all_gas(), 16);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(45..=55).contains(&wasm_fraction),
"{wasm_fraction}% is not between 45% and 55%",
(40..=50).contains(&wasm_fraction),
"{wasm_fraction}% is not between 40% and 50%",
);
}

Expand Down
Loading

0 comments on commit 5cb6a72

Please sign in to comment.