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

upgrade evm #797

Open
wants to merge 3 commits into
base: develop-ready
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ percent-encoding = "2.1.0"
nix = "0.22.1"
ruc = { version = "1.0.5", default-features = false, features = ["compact"] }
module-evm = { path = "../contracts/modules/evm"}
ethereum-types = { version = "0.13.1", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }

noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ version = "0.1.0"

[dependencies]
abci = "0.7.2"
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.13.1", default-features = false }
ethereum = { version = "0.14.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.14.1", default-features = false }
futures = "0.3.16"
lazy_static = "1.4.0"
ledger = {path = "../../../ledger"}
tracing = "0.1"
parking_lot = "0.12"
primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] }
primitive-types = { version = "0.12.1", default-features = false, features = ["rlp", "byteorder", "serde"] }
protobuf = "2.16"
ruc = "1.0"
serde = {version = "1.0.124", features = ["derive"]}
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"
[dependencies]
abci = "0.7.2"
tracing = "0.1"
primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] }
primitive-types = { version = "0.12.1", default-features = false, features = ["rlp", "byteorder", "serde"] }
ruc = "1.0"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ readme = "README.md"

[dependencies]
abci = "0.7.2"
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.13.1", default-features = false }
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
ethereum = { version = "0.14.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
tracing = "0.1"
rand = "0.8"
rlp = "0.5"
Expand Down
9 changes: 5 additions & 4 deletions src/components/contracts/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ readme = "README.md"

[dependencies]
abci = "0.7.2"
ethereum-types = { version = "0.13.1", default-features = false }
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
evm-runtime = { version = "0.35.0", default-features = false }
evm-gasometer = { version = "0.30.0", default-features = false }
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum = { version = "0.14.0", default-features = false, features = ["with-serde"] }
impl-trait-for-tuples = "0.2"
tracing = "0.1"
rlp = { version = "0.5", default-features = false }
Expand All @@ -23,10 +23,11 @@ serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
sha3 = { version = "0.10", default-features = false }
hex = "0.4.2"
ethabi = "17.1.0"
ethabi = "18.0.0"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }


# primitives, don't depend on any modules
fp-core = { path = "../../primitives/core" }
fp-evm = { path = "../../primitives/evm" }
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/evm/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ description = "MODEXP precompiles for EVM module."
readme = "README.md"

[dependencies]
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
module-evm = { path = "../../../modules/evm"}
ethereum-types = "0.13.1"
ethereum-types = "0.14.1"
evm-precompile-basic = { path = "./basic" }
evm-precompile-sha3fips = {path = "./sha3fips" }
evm-precompile-modexp = { path = "./modexp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Basic precompiles for EVM module."
readme = "README.md"

[dependencies]
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
module-evm = { path = "../../../../modules/evm"}
ripemd = "0.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
eth_pairings = { git = "https://github.com/FindoraNetwork/eip1962", branch = "master" }
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
evm-precompile-utils = { path = "../utils"}
tracing = "0.1"
module-evm = { path = "../../../../modules/evm"}
Expand All @@ -16,5 +16,5 @@ num_enum = { version = "0.5.4", default-features = false }
[dev-dependencies]
baseapp = { path = "../../../../baseapp" }
fp-mocks = { path = "../../../../primitives/mocks" }
ethereum-types = { version = "0.13.1", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
hex = "0.4"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
mod tests;

use eth_pairings::public_interface::{perform_operation, ApiError, OperationType};
use evm::executor::stack::{PrecompileFailure, PrecompileOutput};
use evm::{Context, ExitError, ExitSucceed};
use evm::executor::stack::{PrecompileFailure, PrecompileHandle, PrecompileOutput};
use evm::{
// Context,
ExitError,
ExitSucceed,
};
use evm_precompile_utils::{EvmDataReader, EvmDataWriter, EvmResult, Gasometer};
use module_evm::precompile::{FinState, Precompile, PrecompileId, PrecompileResult};
use tracing::debug;
Expand All @@ -25,11 +29,12 @@ pub enum Call {

impl Precompile for EthPairing {
fn execute(
input: &[u8],
target_gas: Option<u64>,
_context: &Context,
handle: &mut impl PrecompileHandle,
_state: &FinState,
) -> PrecompileResult {
let input = handle.input();
let target_gas = handle.gas_limit();

let mut input = EvmDataReader::new(input);
let selector = match input.read_selector::<Call>() {
Ok(v) => v,
Expand Down Expand Up @@ -86,11 +91,11 @@ impl EthPairing {

Ok(PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: gasometer.used_gas(),
// cost: gasometer.used_gas(),
output: EvmDataWriter::new()
.write_raw_bytes(result.as_slice())
.build(),
logs: vec![],
// logs: vec![],
})
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::*;
use ethereum_types::H160;
use ethereum_types::{H160, H256};
use evm::{executor::stack::PrecompileHandle, Context, ExitError, ExitReason, Transfer};
use fp_mocks::*;

// Test from eth-pairings (eip1962) repository https://github.com/FindoraNetwork/eip1962
Expand All @@ -9,21 +10,95 @@ fn test_bls12_pairing() {
let hex_string = "07202912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011603e65409b693c8a08aeb3478d10aa3732a6672ba06d12912811758d871b77a9c3635c28570dc020576f9fc2719d8d0494439162b2b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010206059efde42f3701020127ccb2831f0011c1d547c491b9dffbd4cfdb87598a4b370f5873ea62094a2f201faa6cb7f6fcca66de3f308a25776dac3f61edb792948fbe53e4d18a3d8aefbe011a7e9f75f3fdc77b83a97f7acd58326a0545f8aa37b69bfb32c52dc195763e8c17176e0ad4ee94d9c720e922d42688127c4b812cd7c2f8cf6126acd4c3d7568121e48b3fefe66c279f2ec71f0d6f8156a3343d1cfa54b808d747cd02419278290ad2d7d03f5de1e7b3c97732f53dbe1dfd42e51f9571f7fee3d9c1785d5a1ed6010b4f7f211a0a5f4425728e2df580196d3e3b85ef148ed769acd23e9be6e8440726cb40655787f48eaf46154cb740e2a58db5b96fa02d83fb9d0f94320da1471e0104ece4c46ac4f05a7c28ecda84292f15999747bb77c530c65448f1f837a47dd70e972c4065d0b39d40b5d550a55901516afa7f02b395963d1535fcba1705e31a117cb4beab1dc582198c4ab0c02e96a22f7bd10dde3bbbdbc9182a9596cb0ed32121616b692e8036437efb4c3816f018f11e643c6e0a049da431986a3a722b06";
let data = hex::decode(hex_string).unwrap();

let output = EthPairing::execute(
&EvmDataWriter::new()
.write_selector(Call::ExecuteOperation)
.write_raw_bytes(&data)
.build(),
None,
&evm::Context {
address: H160::from_low_u64_be(2001),
caller: ALICE_ECDSA.address,
apparent_value: From::from(0),
},
&BASE_APP.lock().unwrap().deliver_state,
);
let input = EvmDataWriter::new()
.write_selector(Call::ExecuteOperation)
.write_raw_bytes(&data)
.build();

let context = evm::Context {
address: H160::from_low_u64_be(2001),
caller: ALICE_ECDSA.address,
apparent_value: From::from(0),
};

let cost = None;

let mut handle = MockHandle::new(input, cost, context);

let output =
EthPairing::execute(&mut handle, &BASE_APP.lock().unwrap().deliver_state);

assert!(output.is_ok());
assert_eq!(output.as_ref().unwrap().cost, 164986);
// assert_eq!(output.as_ref().unwrap().cost, 164986);
assert_eq!(handle.gas_used, 0);
assert_eq!(output.unwrap().output, vec![0x1]);
}

pub struct MockHandle {
pub input: Vec<u8>,
pub gas_limit: Option<u64>,
pub context: Context,
pub is_static: bool,
pub gas_used: u64,
}

impl MockHandle {
pub fn new(input: Vec<u8>, gas_limit: Option<u64>, context: Context) -> Self {
Self {
input,
gas_limit,
context,
is_static: false,
gas_used: 0,
}
}
}

impl PrecompileHandle for MockHandle {
/// Perform subcall in provided context.
/// Precompile specifies in which context the subcall is executed.
fn call(
&mut self,
_: H160,
_: Option<Transfer>,
_: Vec<u8>,
_: Option<u64>,
_: bool,
_: &Context,
) -> (ExitReason, Vec<u8>) {
unimplemented!()
}

fn record_cost(&mut self, cost: u64) -> Result<(), ExitError> {
self.gas_used += cost;
Ok(())
}

fn log(&mut self, _: H160, _: Vec<H256>, _: Vec<u8>) -> Result<(), ExitError> {
unimplemented!()
}

fn remaining_gas(&self) -> u64 {
unimplemented!()
}

fn code_address(&self) -> H160 {
unimplemented!()
}

fn input(&self) -> &[u8] {
&self.input
}

fn context(&self) -> &Context {
&self.context
}

fn is_static(&self) -> bool {
self.is_static
}

fn gas_limit(&self) -> Option<u64> {
self.gas_limit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "FRC20 precompiles for EVM module."
readme = "README.md"

[dependencies]
ethereum-types = { version = "0.13.1", default-features = false }
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false, features = ["with-serde"] }
evm-precompile-utils = { path = "../utils"}
fp-traits = { path = "../../../../primitives/traits" }
tracing = "0.1"
Expand Down
Loading