Skip to content

Commit

Permalink
Update ripemd160 precompile (paritytech#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
5meta4 authored Dec 15, 2020
1 parent e79564a commit dbe7bf6
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 32 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion node/standalone/Cargo.lock

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

2 changes: 0 additions & 2 deletions runtime/precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
[dependencies]
log = "0.4.8"
rustc-hex = { version = "2.0.1", default-features = false }
ripemd160 = { version = "0.9", default-features = false }

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand All @@ -18,5 +17,4 @@ default = [ "std" ]
std = [
"sp-std/std",
"sp-core/std",
"ripemd160/std",
]
30 changes: 4 additions & 26 deletions runtime/precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use sp_std::prelude::*;
use sp_core::H160;
use pallet_evm::{ExitError, ExitSucceed, Precompile};
use pallet_evm::{Precompile, Precompiles};

pub struct ExperimentalMoonbeamPrecompiles;

Expand All @@ -43,7 +43,7 @@ fn ensure_linear_cost(
// prepends "deadbeef" to any data provided
struct DeadbeefPrecompiled;

impl pallet_evm::Precompile for DeadbeefPrecompiled {
impl Precompile for DeadbeefPrecompiled {
fn execute(
input: &[u8],
target_gas: Option<usize>
Expand Down Expand Up @@ -79,7 +79,7 @@ fn get_precompiled_func_from_address(address: &H160) -> Option<PrecompiledCallab
None
}

impl pallet_evm::Precompiles for ExperimentalMoonbeamPrecompiles {
impl Precompiles for ExperimentalMoonbeamPrecompiles {
fn execute(
address: H160,
input: &[u8],
Expand All @@ -99,33 +99,11 @@ impl pallet_evm::Precompiles for ExperimentalMoonbeamPrecompiles {
}
}



use ripemd160::Digest;
/// The ripemd precompile.
pub struct Ripemd160;

impl Precompile for Ripemd160 {
fn execute(
input: &[u8],
target_gas: Option<usize>,
) -> core::result::Result<(ExitSucceed, Vec<u8>, usize), ExitError> {
let cost = ensure_linear_cost(target_gas, input.len(), 600, 120)?;

let mut v32 = [0u8; 32];
v32[12..32].copy_from_slice(&ripemd160::Ripemd160::digest(input));
Ok((ExitSucceed::Returned, v32.to_vec(), cost))
}
}


pub type MoonbeamPrecompiles =
(
pallet_evm::precompiles::ECRecover,
pallet_evm::precompiles::Sha256,
// Reset to pallet_evm ripemd160 once
// https://github.com/paritytech/substrate/pull/7296 is included
Ripemd160,
pallet_evm::precompiles::Ripemd160,
pallet_evm::precompiles::Identity,
);

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! runtime_parachain {
impl_name: create_runtime_str!("moonbase-alphanet"),
authoring_version: 3,
spec_version: 5,
impl_version: 0,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
};
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! runtime_standalone {
impl_name: create_runtime_str!("moonbeam-standalone"),
authoring_version: 3,
spec_version: 5,
impl_version: 0,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
};
Expand Down

0 comments on commit dbe7bf6

Please sign in to comment.