Skip to content

Commit

Permalink
Merge branch 'develop' into new-bn258
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajbouw committed Aug 8, 2022
2 parents 687885d + f90e424 commit 888b37f
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 279 deletions.
245 changes: 146 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

Binary file removed bin/aurora-local.wasm
Binary file not shown.
Binary file removed bin/aurora-mainnet.wasm
Binary file not shown.
Binary file removed bin/aurora-mainnet2.wasm
Binary file not shown.
Binary file removed bin/aurora-testnet-test.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions engine-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ aurora-engine-sdk = { path = "../engine-sdk", default-features = false }
base64 = { version = "0.13.0", default-features = false, features = ["alloc"] }
borsh = { version = "0.8.2", default-features = false }
bn = { package = "zeropool-bn", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false }
libsecp256k1 = { version = "0.7.0", default-features = false, features = ["static-context", "hmac"] }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
primitive-types = { version = "0.10.0", default-features = false, features = ["rlp"] }
primitive-types = { version = "0.11", default-features = false, features = ["rlp"] }
ripemd160 = { version = "0.9.1", default-features = false }
sha2 = { version = "0.9.3", default-features = false }
sha3 = { version = "0.9.1", default-features = false }
ethabi = { git = "https://github.com/darwinia-network/ethabi", branch = "xavier-no-std", default-features = false }
ethabi = { version = "17.1", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }

[dev-dependencies]
Expand Down
13 changes: 8 additions & 5 deletions engine-precompiles/src/account_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ impl<'a, E: Env> Precompile for PredecessorAccount<'a, E> {
}

let predecessor_account_id = self.env.predecessor_account_id();
Ok(PrecompileOutput::without_logs(cost, predecessor_account_id.as_bytes().to_vec()).into())
Ok(PrecompileOutput::without_logs(
cost,
predecessor_account_id.as_bytes().to_vec(),
))
}
}

Expand Down Expand Up @@ -95,10 +98,10 @@ impl Precompile for CurrentAccount {
}
}

Ok(
PrecompileOutput::without_logs(cost, self.current_account_id.as_bytes().to_vec())
.into(),
)
Ok(PrecompileOutput::without_logs(
cost,
self.current_account_id.as_bytes().to_vec(),
))
}
}

Expand Down
12 changes: 6 additions & 6 deletions engine-precompiles/src/alt_bn256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Precompile for Bn256Add<Byzantium> {
}

let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ impl Precompile for Bn256Add<Istanbul> {
}
}
let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -365,7 +365,7 @@ impl Precompile for Bn256Mul<Byzantium> {
}

let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -393,7 +393,7 @@ impl Precompile for Bn256Mul<Istanbul> {
}

let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ impl Precompile for Bn256Pair<Byzantium> {
}

let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -551,7 +551,7 @@ impl Precompile for Bn256Pair<Istanbul> {
}

let output = Self::run_inner(input, context)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine-precompiles/src/blake2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Precompile for Blake2F {
let finished = input[212] != 0;

let output = f(h, m, t, finished, rounds);
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down
6 changes: 3 additions & 3 deletions engine-precompiles/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Precompile for SHA256 {
}

let output = sha2::Sha256::digest(input).to_vec();
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}

/// See: https://ethereum.github.io/yellowpaper/paper.pdf
Expand All @@ -82,7 +82,7 @@ impl Precompile for SHA256 {
}

let output = sdk::sha256(input).as_bytes().to_vec();
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ impl Precompile for RIPEMD160 {
// the evm works with 32-byte words.
let mut output = vec![0u8; 32];
output[12..].copy_from_slice(&hash);
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine-precompiles/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Precompile for Identity {
}
}

Ok(PrecompileOutput::without_logs(cost, input.to_vec()).into())
Ok(PrecompileOutput::without_logs(cost, input.to_vec()))
}
}

Expand Down
43 changes: 23 additions & 20 deletions engine-precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use aurora_engine_sdk::env::Env;
use aurora_engine_sdk::io::IO;
use aurora_engine_types::{account_id::AccountId, types::Address, vec, BTreeMap, Box};
use evm::backend::Log;
use evm::executor;
use evm::executor::{self, stack::PrecompileHandle};
use evm::{Context, ExitError, ExitSucceed};

#[derive(Debug, Default)]
Expand All @@ -52,18 +52,7 @@ impl PrecompileOutput {
}
}

impl From<PrecompileOutput> for executor::stack::PrecompileOutput {
fn from(output: PrecompileOutput) -> Self {
executor::stack::PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: output.cost.as_u64(),
output: output.output,
logs: output.logs,
}
}
}

type EvmPrecompileResult = Result<executor::stack::PrecompileOutput, ExitError>;
type EvmPrecompileResult = Result<PrecompileOutput, ExitError>;

/// A precompiled function for use in the EVM.
pub trait Precompile {
Expand Down Expand Up @@ -118,15 +107,29 @@ pub struct Precompiles<'a, I, E> {
impl<'a, I: IO + Copy, E: Env> executor::stack::PrecompileSet for Precompiles<'a, I, E> {
fn execute(
&self,
address: prelude::H160,
input: &[u8],
gas_limit: Option<u64>,
context: &Context,
is_static: bool,
handle: &mut impl PrecompileHandle,
) -> Option<Result<executor::stack::PrecompileOutput, executor::stack::PrecompileFailure>> {
let address = handle.code_address();

self.precompile_action(Address::new(address), |p| {
p.run(input, gas_limit.map(EthGas::new), context, is_static)
.map_err(|exit_status| executor::stack::PrecompileFailure::Error { exit_status })
let input = handle.input();
let gas_limit = handle.gas_limit();
let context = handle.context();
let is_static = handle.is_static();

match p.run(input, gas_limit.map(EthGas::new), context, is_static) {
Ok(output) => {
handle.record_cost(output.cost.as_u64())?;
for log in output.logs {
handle.log(log.address, log.topics, log.data)?;
}
Ok(executor::stack::PrecompileOutput {
exit_status: ExitSucceed::Returned,
output: output.output,
})
}
Err(exit_status) => Err(executor::stack::PrecompileFailure::Error { exit_status }),
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions engine-precompiles/src/modexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Precompile for ModExp<Byzantium> {
}

let output = Self::run_inner(input)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down Expand Up @@ -163,7 +163,7 @@ impl Precompile for ModExp<Berlin> {
}

let output = Self::run_inner(input)?;
Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

Expand Down
6 changes: 2 additions & 4 deletions engine-precompiles/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ impl<I: IO> Precompile for ExitToNear<I> {
Ok(PrecompileOutput {
logs: vec![promise_log, exit_event_log],
..Default::default()
}
.into())
})
}
}

Expand Down Expand Up @@ -573,8 +572,7 @@ impl<I: IO> Precompile for ExitToEthereum<I> {
Ok(PrecompileOutput {
logs: vec![promise_log, exit_event_log],
..Default::default()
}
.into())
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine-precompiles/src/prepaid_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'a, E: Env> Precompile for PrepaidGas<'a, E> {
U256::from(prepaid_gas.as_u64()).to_big_endian(&mut buf);
buf
};
Ok(PrecompileOutput::without_logs(cost, bytes).into())
Ok(PrecompileOutput::without_logs(cost, bytes))
}
}

Expand Down
5 changes: 4 additions & 1 deletion engine-precompiles/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ impl Precompile for RandomSeed {
}
}

Ok(PrecompileOutput::without_logs(cost, self.random_seed.as_bytes().to_vec()).into())
Ok(PrecompileOutput::without_logs(
cost,
self.random_seed.as_bytes().to_vec(),
))
}
}

Expand Down
4 changes: 2 additions & 2 deletions engine-precompiles/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Precompile for ECRecover {
let v_bit = match v[31] {
27 | 28 if v[..31] == [0; 31] => v[31] - 27,
_ => {
return Ok(PrecompileOutput::without_logs(cost, Vec::new()).into());
return Ok(PrecompileOutput::without_logs(cost, Vec::new()));
}
};
signature[64] = v_bit; // v
Expand All @@ -109,7 +109,7 @@ impl Precompile for ECRecover {
Err(_) => Vec::new(),
};

Ok(PrecompileOutput::without_logs(cost, output).into())
Ok(PrecompileOutput::without_logs(cost, output))
}
}

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 = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false }
rocksdb = { version = "0.18.0", default-features = false }
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 = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
serde = { version = "1", features = ["derive"], optional = true }

[features]
Expand Down
1 change: 1 addition & 0 deletions engine-standalone-tracing/src/sputnik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl evm::tracing::EventListener for TransactionTraceBuilder {
self.output = return_value.to_vec();
}
}
Event::PrecompileSubcall { .. } => (),
Event::TransactCall { .. } => (), // no useful information
Event::TransactCreate { .. } => (), // no useful information
Event::TransactCreate2 { .. } => (), // no useful information
Expand Down
1 change: 1 addition & 0 deletions engine-standalone-tracing/src/types/call_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl evm::tracing::EventListener for CallTracer {
}

// not useful
evm::tracing::Event::PrecompileSubcall { .. } => (),
evm::tracing::Event::TransactCall { .. } => (),
evm::tracing::Event::TransactCreate { .. } => (),
evm::tracing::Event::TransactCreate2 { .. } => (),
Expand Down
8 changes: 4 additions & 4 deletions engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ engine-standalone-storage = { path = "../engine-standalone-storage" }
engine-standalone-tracing = { path = "../engine-standalone-tracing" }
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 = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false, features = ["std", "tracing"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.36.0-aurora", default-features = false, features = ["std", "tracing"] }
rlp = { version = "0.5.0", default-features = false }

[dev-dependencies]
base64 = "0.13.0"
bstr = "0.2"
byte-slice-cast = { version = "1.0", default-features = false }
ethabi = { git = "https://github.com/darwinia-network/ethabi", branch = "xavier-no-std" }
ethabi = "17.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
hex = { version = "0.4.3", default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn repro_GdASJ3KESs() {
block_timestamp: 1645717564644206730,
input_path: "src/tests/res/input_GdASJ3KESs.hex",
evm_gas_used: 706713,
near_gas_used: 133,
near_gas_used: 132,
});
}

Expand All @@ -52,7 +52,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1648829935343349589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1732181,
near_gas_used: 242,
near_gas_used: 240,
});
}

Expand All @@ -72,7 +72,7 @@ fn repro_FRcorNv() {
block_timestamp: 1650960438774745116,
input_path: "src/tests/res/input_FRcorNv.hex",
evm_gas_used: 1239721,
near_gas_used: 197,
near_gas_used: 196,
});
}

Expand All @@ -89,7 +89,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1651073772931594646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 706,
near_gas_used: 695,
});
}

Expand All @@ -107,7 +107,7 @@ fn repro_D98vwmi() {
block_timestamp: 1651753443421003245,
input_path: "src/tests/res/input_D98vwmi.hex",
evm_gas_used: 1_035_348,
near_gas_used: 199,
near_gas_used: 198,
});
}

Expand Down
Loading

0 comments on commit 888b37f

Please sign in to comment.