Skip to content

Commit

Permalink
upgrade evm 0.36.0
Browse files Browse the repository at this point in the history
  • Loading branch information
harryliisme3 committed Jan 31, 2023
1 parent faebb77 commit 8208b93
Show file tree
Hide file tree
Showing 21 changed files with 602 additions and 332 deletions.
2 changes: 1 addition & 1 deletion src/components/contracts/modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
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"] }
evm = { version = "0.36.0", default-features = false, features = ["with-serde"] }
tracing = "0.1"
rand = "0.8"
rlp = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/evm/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"
ethereum-types = { version = "0.13.1", default-features = false }
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
evm = { version = "0.36.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"] }
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/evm/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "MODEXP precompiles for EVM module."
readme = "README.md"

[dependencies]
evm = { version = "0.35.0", default-features = false, features = ["with-serde"] }
evm = { version = "0.36.0", default-features = false, features = ["with-serde"] }
module-evm = { path = "../../../modules/evm"}
ethereum-types = "0.13.1"
evm-precompile-basic = { path = "./basic" }
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.36.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.36.0", default-features = false, features = ["with-serde"] }
evm-precompile-utils = { path = "../utils"}
tracing = "0.1"
module-evm = { path = "../../../../modules/evm"}
Expand Down
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 @@ -10,7 +10,7 @@ readme = "README.md"

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

0 comments on commit 8208b93

Please sign in to comment.