Skip to content

Commit

Permalink
Merge pull request rust-ethereum#14 from PureStake/jeremy-precompile-…
Browse files Browse the repository at this point in the history
…handle

PrecompileHandle trait
  • Loading branch information
sorpaas authored May 20, 2022
2 parents 0662af4 + d24b525 commit 4f7e566
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
6 changes: 1 addition & 5 deletions ethcore-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,7 @@ impl Implementation for EcRecover {
let message = libsecp256k1::Message::parse(&hash);
let recovery_id = libsecp256k1::RecoveryId::parse(bit);
if let Ok(recovery_id) = recovery_id {
if let Ok(p) = libsecp256k1::recover(
&message,
&signature.unwrap(),
&recovery_id,
) {
if let Ok(p) = libsecp256k1::recover(&message, &signature.unwrap(), &recovery_id) {
let r = keccak(&p.serialize()[1..65]);
output.write(0, &[0; 12]);
output.write(12, &r.as_bytes()[12..]);
Expand Down
2 changes: 1 addition & 1 deletion evm
Submodule evm updated from dff73a to 01bcbd
26 changes: 11 additions & 15 deletions jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use evm::executor::stack::{
use evm::{Config, Context, ExitError, ExitSucceed};
use lazy_static::lazy_static;
use libsecp256k1::SecretKey;
use sha3::{Digest, Keccak256};
use primitive_types::{H160, H256, U256};
use serde::Deserialize;
use sha3::{Digest, Keccak256};
use std::collections::BTreeMap;
use std::convert::TryInto;

Expand All @@ -30,7 +30,7 @@ impl Test {
let public = libsecp256k1::PublicKey::from_secret_key(&secret.unwrap());
let mut res = [0u8; 64];
res.copy_from_slice(&public.serialize()[1..65]);

H160::from(H256::from_slice(Keccak256::digest(&res).as_slice()))
}

Expand Down Expand Up @@ -97,12 +97,7 @@ lazy_static! {

macro_rules! precompile_entry {
($map:expr, $builtins:expr, $index:expr) => {
let x: fn(
&[u8],
Option<u64>,
&Context,
bool,
) -> Result<PrecompileOutput, PrecompileFailure> =
let x: PrecompileFn =
|input: &[u8], gas_limit: Option<u64>, _context: &Context, _is_static: bool| {
let builtin = $builtins.get(&H160::from_low_u64_be($index)).unwrap();
Self::exec_as_precompile(builtin, input, gas_limit)
Expand Down Expand Up @@ -167,7 +162,7 @@ impl JsonPrecompile {
builtin: &ethcore_builtin::Builtin,
input: &[u8],
gas_limit: Option<u64>,
) -> Result<PrecompileOutput, PrecompileFailure> {
) -> Result<(PrecompileOutput, u64), PrecompileFailure> {
let cost = builtin.cost(input, 0);

if let Some(target_gas) = gas_limit {
Expand All @@ -180,12 +175,13 @@ impl JsonPrecompile {

let mut output = Vec::new();
match builtin.execute(input, &mut parity_bytes::BytesRef::Flexible(&mut output)) {
Ok(()) => Ok(PrecompileOutput {
exit_status: ExitSucceed::Stopped,
output,
cost: cost.as_u64(),
logs: Vec::new(),
}),
Ok(()) => Ok((
PrecompileOutput {
exit_status: ExitSucceed::Stopped,
output,
},
cost.as_u64(),
)),
Err(e) => Err(PrecompileFailure::Error {
exit_status: ExitError::Other(e.into()),
}),
Expand Down

0 comments on commit 4f7e566

Please sign in to comment.