Skip to content

Commit

Permalink
use revm_precompile::u64_to_address
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Mar 22, 2024
1 parent 506dad6 commit 59432d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
12 changes: 0 additions & 12 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,3 @@ pub mod secp256r1;
pub mod bls12_381;

mod addresses;

/// Const function for making an address by concatenating the bytes from two given numbers.
///
/// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used
/// as a convenience for specifying the addresses of the various precompiles.
#[inline]
const fn u64_to_address(x: u64) -> Address {
let x = x.to_be_bytes();
Address::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7],
])
}
8 changes: 3 additions & 5 deletions crates/precompile/src/secp256r1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::addresses::P256VERIFY_ADDRESS;
use p256::ecdsa::{signature::hazmat::PrehashVerifier, Signature, VerifyingKey};
use revm_precompile::{Precompile, PrecompileWithAddress};
use revm_precompile::{u64_to_address, Precompile, PrecompileWithAddress};
use revm_primitives::{Bytes, PrecompileError, PrecompileResult, B256};

/// secp256r1 precompiles
Expand All @@ -9,10 +9,8 @@ pub fn precompiles() -> impl Iterator<Item = PrecompileWithAddress> {
}

/// [EIP-7212](https://eips.ethereum.org/EIPS/eip-7212#specification) secp256r1 precompile.
const P256VERIFY: PrecompileWithAddress = PrecompileWithAddress(
crate::u64_to_address(P256VERIFY_ADDRESS),
Precompile::Standard(p256_verify),
);
const P256VERIFY: PrecompileWithAddress =
PrecompileWithAddress(u64_to_address(P256VERIFY_ADDRESS), Precompile::Standard(p256_verify));

/// The input is encoded as follows:
/// | signed msg hash | r | s | pk x | pk y |
Expand Down

0 comments on commit 59432d3

Please sign in to comment.