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

Fix(engine): Upgrade to latest SputnikVM #445

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions engine-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ base64 = { version = "0.13.0", default-features = false, features = ["alloc"] }
near-blake2 = { git = "https://github.com/near/near-blake2.git", version = "0.9.1", default-features = false }
borsh = { version = "0.8.2", default-features = false }
bn = { package = "aurora-bn", git = "https://github.com/aurora-is-near/aurora-bn.git", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
libsecp256k1 = { version = "0.3.5", default-features = false }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
primitive-types = { version = "0.10.0", default-features = false, features = ["rlp"] }
Expand Down
2 changes: 1 addition & 1 deletion engine-standalone-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ aurora-engine-types = { path = "../engine-types", default-features = false, feat
aurora-engine-sdk = { path = "../engine-sdk", default-features = false, features = ["std"] }
aurora-engine-transactions = { path = "../engine-transactions", default-features = false, features = ["std"] }
borsh = { version = "0.8.2" }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
rocksdb = "0.16.0"
postgres = "0.19.2"
serde = "1.0.130"
Expand Down
8 changes: 4 additions & 4 deletions engine-standalone-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ crate-type = ["lib"]
aurora-engine = { path = "../engine", default-features = false, features = ["std"] }
aurora-engine-types = { path = "../engine-types", default-features = false, features = ["std"] }
aurora-engine-sdk = { path = "../engine-sdk", default-features = false, features = ["std"] }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }

[features]
default = []
Expand Down
10 changes: 9 additions & 1 deletion engine-standalone-tracing/src/sputnik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ impl evm_runtime::tracing::EventListener for TransactionTraceBuilder {
if let Ok(pc) = position {
self.current.program_counter = ProgramCounter(*pc as u32);
}
self.current.stack = stack.data().as_slice().into();
self.current.stack = stack
.data()
.iter()
.map(|x| {
let mut buf = [0u8; 32];
x.to_big_endian(&mut buf);
buf
})
.collect();
self.current.memory = memory.data().as_slice().into();
}

Expand Down
8 changes: 4 additions & 4 deletions engine-standalone-tracing/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aurora_engine_types::types::EthGas;
use aurora_engine_types::{BTreeMap, H256};
use aurora_engine_types::BTreeMap;
use evm_core::Opcode;
use std::ops::Index;

Expand Down Expand Up @@ -85,9 +85,9 @@ impl LogStack {
}
}

impl From<&[H256]> for LogStack {
fn from(stack: &[H256]) -> Self {
let vec = stack.iter().map(|bytes| bytes.0).collect();
impl std::iter::FromIterator<[u8; 32]> for LogStack {
fn from_iter<T: IntoIterator<Item = [u8; 32]>>(iter: T) -> Self {
let vec = iter.into_iter().collect();
Self(vec)
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ engine-standalone-storage = { path = "../engine-standalone-storage", default-fea
engine-standalone-tracing = { path = "../engine-standalone-tracing", default-features = false }
borsh = { version = "0.8.2", default-features = false }
sha3 = { version = "0.9.1", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false, features = ["std", "tracing"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false, features = ["std", "tracing"] }
rlp = { version = "0.5.0", default-features = false }

[dev-dependencies]
Expand Down
16 changes: 8 additions & 8 deletions engine-tests/src/tests/one_inch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ 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(), 18); // less than 18 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 14); // less than 14 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
assert_gas_bound(profile.all_gas(), 18); // less than 18 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 13); // less than 13 NEAR Tgas used

// create some ERC-20 tokens to have a liquidity pool for
let signer_address = test_utils::address_from_secret_key(&helper.signer.secret_key);
Expand All @@ -39,7 +39,7 @@ fn test_1inch_liquidity_protocol() {
let (result, profile, pool) =
helper.create_pool(&pool_factory, token_a.0.address, token_b.0.address);
assert!(result.gas_used >= 4_500_000); // more than 4.5M EVM gas used
assert_gas_bound(profile.all_gas(), 48); // less than 48 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 40); // less than 40 NEAR Tgas used

// Approve giving ERC-20 tokens to the pool
helper.approve_erc20_tokens(&token_a, pool.address());
Expand All @@ -58,7 +58,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 302_000); // more than 302k EVM gas used
assert_gas_bound(profile.all_gas(), 64); // less than 64 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 55); // less than 55 NEAR Tgas used

// Same here
helper.runner.context.block_timestamp += 10_000_000 * 1_000_000_000;
Expand All @@ -73,7 +73,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 210_000); // more than 210k EVM gas used
assert_gas_bound(profile.all_gas(), 66); // less than 66 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 57); // less than 57 NEAR Tgas used

let (result, profile) = helper.pool_withdraw(
&pool,
Expand All @@ -84,7 +84,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 150_000); // more than 150k EVM gas used
assert_gas_bound(profile.all_gas(), 57); // less than 57 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 49); // less than 49 NEAR Tgas used
}

#[test]
Expand All @@ -100,8 +100,8 @@ fn test_1_inch_limit_order_deploy() {

// more than 3.5 million Ethereum gas used
assert!(result.gas_used > 3_500_000);
// less than 17 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 17);
// less than 14 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 14);
// at least 45% of which is from wasm execution
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
Expand Down
8 changes: 4 additions & 4 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ fn test_deploy_largest_contract() {
result.gas_used,
);

// Less than 18 NEAR Tgas
test_utils::assert_gas_bound(profile.all_gas(), 18);
// Less than 14 NEAR Tgas
test_utils::assert_gas_bound(profile.all_gas(), 14);
}

#[test]
Expand Down Expand Up @@ -171,8 +171,8 @@ fn test_solidity_pure_bench() {
"Over 38 million EVM gas is used"
);
assert!(
profile.all_gas() > 2900 * 1_000_000_000_000,
"Over 2900 NEAR Tgas is used"
profile.all_gas() > 2200 * 1_000_000_000_000,
"Over 2200 NEAR Tgas is used"
);
}

Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn test_uniswap_input_multihop() {
let mut context = UniswapTestContext::new("uniswap");

// evm_gas = 970k
// near total gas = 302 Tgas
// near total gas = 258 Tgas
// Wish: optimize so that this transaction costs less than 200 Tgas.
// For now we just have to increase the burnt gas limit to make it run to completion.
context.runner.wasm_config.limit_config.max_gas_burnt = 500_000_000_000_000;
Expand All @@ -54,7 +54,7 @@ fn test_uniswap_exact_output() {

let (_result, profile) =
context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
test_utils::assert_gas_bound(profile.all_gas(), 88);
test_utils::assert_gas_bound(profile.all_gas(), 76);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
20 <= wasm_fraction && wasm_fraction <= 30,
Expand All @@ -64,7 +64,7 @@ fn test_uniswap_exact_output() {

let (_amount_in, profile) =
context.exact_output_single(&token_a, &token_b, OUTPUT_AMOUNT.into());
test_utils::assert_gas_bound(profile.all_gas(), 48);
test_utils::assert_gas_bound(profile.all_gas(), 38);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
25 <= wasm_fraction && wasm_fraction <= 35,
Expand Down
2 changes: 1 addition & 1 deletion engine-transactions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ autobenches = false
aurora-engine-types = { path = "../engine-types", default-features = false }
aurora-engine-sdk = { path = "../engine-sdk", default-features = false }
aurora-engine-precompiles = { path = "../engine-precompiles", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
rlp = { version = "0.5.0", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }

Expand Down
4 changes: 2 additions & 2 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ base64 = { version = "0.13.0", default-features = false, features = ["alloc"] }
near-blake2 = { git = "https://github.com/near/near-blake2.git", version = "0.9.1", default-features = false }
borsh = { version = "0.8.2", default-features = false }
bn = { package = "aurora-bn", git = "https://github.com/aurora-is-near/aurora-bn.git", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "177e253ad947b7186bfa6920843075556b60ff54", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "f4ee520254856898d451c7225851520a35c97cea", default-features = false }
libsecp256k1 = { version = "0.3.5", default-features = false }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
primitive-types = { version = "0.10.0", default-features = false, features = ["rlp"] }
Expand Down
8 changes: 4 additions & 4 deletions etc/state-migration-test/Cargo.lock

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