Skip to content
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
13 changes: 5 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ members = [
"template/node",
"template/runtime",
]
resolver = "2"
resolver = "2"
2 changes: 1 addition & 1 deletion client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
codec = { package = "parity-scale-codec", version = "3.0.0" }
ethereum = { version = "0.12.0", features = ["with-codec"] }
ethereum-types = "0.13.1"
evm = "0.35.0"
evm = { git = "https://github.com/rust-blockchain/evm", branch = "master" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new evm version rust-ethereum/evm#124

futures = { version = "0.3.1", features = ["compat"] }
hex = "0.4"
jsonrpc-core = "18.0"
Expand Down
2 changes: 1 addition & 1 deletion frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"
[dependencies]
ethereum = { version = "0.12.0", default-features = false, features = ["with-codec"] }
ethereum-types = { version = "0.13.1", default-features = false }
evm = { version = "0.35.0", features = ["with-codec"], default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", branch = "master", features = ["with-codec"], default-features = false }
rlp = { version = "0.5", default-features = false }
serde = { version = "1.0.101", optional = true }
sha3 = { version = "0.10", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
evm = { version = "0.35.0", default-features = false, features = ["with-codec"] }
evm = { git = "https://github.com/rust-blockchain/evm", branch = "master", default-features = false, features = ["with-codec"] }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
log = { version = "0.4", default-features = false }
primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder"] }
Expand Down
17 changes: 8 additions & 9 deletions frame/evm/precompile/blake2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern crate alloc;
mod eip_152;

use fp_evm::{
Context, ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileOutput,
ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput,
PrecompileResult,
};

Expand All @@ -35,14 +35,12 @@ impl Blake2F {
impl Precompile for Blake2F {
/// Format of `input`:
/// [4 bytes for rounds][64 bytes for h][128 bytes for m][8 bytes for t_0][8 bytes for t_1][1 byte for f]
fn execute(
input: &[u8],
target_gas: Option<u64>,
_context: &Context,
_is_static: bool,
) -> PrecompileResult {
fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
const BLAKE2_F_ARG_LEN: usize = 213;

let input = handle.input();
let target_gas = handle.gas_limit();

if input.len() != BLAKE2_F_ARG_LEN {
return Err(PrecompileFailure::Error {
exit_status: ExitError::Other(
Expand All @@ -64,6 +62,9 @@ impl Precompile for Blake2F {
}
}

handle.record_cost(gas_cost)?;
let input = handle.input();

// we use from_le_bytes below to effectively swap byte order to LE if architecture is BE

let mut h_buf: [u8; 64] = [0; 64];
Expand Down Expand Up @@ -115,9 +116,7 @@ impl Precompile for Blake2F {

Ok(PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: gas_cost,
output: output_buf.to_vec(),
logs: Default::default(),
})
}
}
Expand Down
42 changes: 17 additions & 25 deletions frame/evm/precompile/bn128/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate alloc;

use alloc::vec::Vec;
use fp_evm::{
Context, ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileOutput,
ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput,
PrecompileResult,
};
use sp_core::U256;
Expand Down Expand Up @@ -76,14 +76,13 @@ impl Bn128Add {
}

impl Precompile for Bn128Add {
fn execute(
input: &[u8],
_target_gas: Option<u64>,
_context: &Context,
_is_static: bool,
) -> PrecompileResult {
fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
use bn::AffineG1;

handle.record_cost(Bn128Add::GAS_COST)?;

let input = handle.input();

let p1 = read_point(input, 0)?;
let p2 = read_point(input, 64)?;

Expand All @@ -108,9 +107,7 @@ impl Precompile for Bn128Add {

Ok(PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: Bn128Add::GAS_COST,
output: buf.to_vec(),
logs: Default::default(),
})
}
}
Expand All @@ -123,14 +120,13 @@ impl Bn128Mul {
}

impl Precompile for Bn128Mul {
fn execute(
input: &[u8],
_target_gas: Option<u64>,
_context: &Context,
_is_static: bool,
) -> PrecompileResult {
fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
use bn::AffineG1;

handle.record_cost(Bn128Mul::GAS_COST)?;

let input = handle.input();

let p = read_point(input, 0)?;
let fr = read_fr(input, 64)?;

Expand All @@ -155,9 +151,7 @@ impl Precompile for Bn128Mul {

Ok(PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: Bn128Mul::GAS_COST,
output: buf.to_vec(),
logs: Default::default(),
})
}
}
Expand All @@ -172,14 +166,12 @@ impl Bn128Pairing {
}

impl Precompile for Bn128Pairing {
fn execute(
input: &[u8],
target_gas: Option<u64>,
_context: &Context,
_is_static: bool,
) -> PrecompileResult {
fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
use bn::{pairing_batch, AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2};

let input = handle.input();
let target_gas = handle.gas_limit();

let (ret_val, gas_cost) = if input.is_empty() {
(U256::one(), Bn128Pairing::BASE_GAS_COST)
} else {
Expand Down Expand Up @@ -282,14 +274,14 @@ impl Precompile for Bn128Pairing {
}
};

handle.record_cost(gas_cost)?;

let mut buf = [0u8; 32];
ret_val.to_big_endian(&mut buf);

Ok(PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: gas_cost,
output: buf.to_vec(),
logs: Default::default(),
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions frame/evm/precompile/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate alloc;

use core::marker::PhantomData;
use fp_evm::{
Context, ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileOutput,
ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput,
PrecompileResult,
};
use frame_support::{
Expand All @@ -41,12 +41,11 @@ where
T::Call: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo + Decode,
<T::Call as Dispatchable>::Origin: From<Option<T::AccountId>>,
{
fn execute(
input: &[u8],
target_gas: Option<u64>,
context: &Context,
_is_static: bool,
) -> PrecompileResult {
fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
let input = handle.input();
let target_gas = handle.gas_limit();
let context = handle.context();

let call = T::Call::decode(&mut &*input).map_err(|_| PrecompileFailure::Error {
exit_status: ExitError::Other("decode failed".into()),
})?;
Expand Down Expand Up @@ -75,11 +74,12 @@ where
let cost = T::GasWeightMapping::weight_to_gas(
post_info.actual_weight.unwrap_or(info.weight),
);

handle.record_cost(cost)?;

Ok(PrecompileOutput {
exit_status: ExitSucceed::Stopped,
cost,
output: Default::default(),
logs: Default::default(),
})
}
Err(_) => Err(PrecompileFailure::Error {
Expand Down
Loading