Skip to content

Commit 6a2f79b

Browse files
authored
Merge branch 'develop' into feat/eip-7212
2 parents aebd3db + 28a8eb5 commit 6a2f79b

File tree

18 files changed

+1161
-216
lines changed

18 files changed

+1161
-216
lines changed

Cargo.lock

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bus-mapping/src/circuit_input_builder/execution.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ use halo2_proofs::{
2626
};
2727
use strum_macros::EnumIter;
2828

29+
use halo2_proofs::halo2curves::{
30+
// secp256k1 curve
31+
secp256k1::{Fq as Fq_K1, Secp256k1Affine},
32+
// p256 curve
33+
secp256r1::{Fq as Fq_R1, Secp256r1Affine},
34+
//CurveAffine,
35+
};
36+
2937
/// An execution step of the EVM.
3038
#[derive(Clone, Debug)]
3139
pub struct ExecStep {
@@ -843,7 +851,7 @@ pub struct PrecompileEvents {
843851

844852
impl PrecompileEvents {
845853
/// Get all ecrecover events.
846-
pub fn get_ecrecover_events(&self) -> Vec<SignData> {
854+
pub fn get_ecrecover_events(&self) -> Vec<SignData<Fq_K1, Secp256k1Affine>> {
847855
self.events
848856
.iter()
849857
.filter_map(|e| {
@@ -926,13 +934,28 @@ impl PrecompileEvents {
926934
.cloned()
927935
.collect()
928936
}
937+
938+
/// Get all p256 verify events.
939+
pub fn get_p256_verify_events(&self) -> Vec<SignData<Fq_R1, Secp256r1Affine>> {
940+
self.events
941+
.iter()
942+
.filter_map(|e: &PrecompileEvent| {
943+
if let PrecompileEvent::P256Verify(sign_data) = e {
944+
Some(sign_data)
945+
} else {
946+
None
947+
}
948+
})
949+
.cloned()
950+
.collect()
951+
}
929952
}
930953

931954
/// I/O from a precompiled contract call.
932955
#[derive(Clone, Debug)]
933956
pub enum PrecompileEvent {
934957
/// Represents the I/O from Ecrecover call.
935-
Ecrecover(SignData),
958+
Ecrecover(SignData<Fq_K1, Secp256k1Affine>),
936959
/// Represents the I/O from EcAdd call.
937960
EcAdd(EcAddOp),
938961
/// Represents the I/O from EcMul call.
@@ -943,6 +966,8 @@ pub enum PrecompileEvent {
943966
ModExp(BigModExp),
944967
/// Represents the I/O from SHA256 call.
945968
SHA256(SHA256),
969+
/// Represents the I/O from P256Verify call.
970+
P256Verify(SignData<Fq_R1, Secp256r1Affine>),
946971
}
947972

948973
impl Default for PrecompileEvent {

eth-types/src/geth_types.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use ethers_core::types::{
1111
transaction::eip2718::TypedTransaction, Eip1559TransactionRequest, Eip2930TransactionRequest,
1212
NameOrAddress, TransactionRequest, H256,
1313
};
14-
use halo2curves::{group::ff::PrimeField, secp256k1::Fq};
14+
use halo2curves::{
15+
group::ff::PrimeField,
16+
secp256k1::{Fq as Fq_K1, Secp256k1Affine},
17+
};
1518
use num::Integer;
1619
use num_bigint::BigUint;
1720
use serde::{Serialize, Serializer};
@@ -357,12 +360,13 @@ impl From<&Transaction> for TransactionRequest {
357360
}
358361

359362
impl Transaction {
363+
/// secp256k1 method:
360364
/// Return the SignData associated with this Transaction.
361-
pub fn sign_data(&self) -> Result<SignData, Error> {
365+
pub fn sign_data(&self) -> Result<SignData<Fq_K1, Secp256k1Affine>, Error> {
362366
let sig_r_le = self.r.to_le_bytes();
363367
let sig_s_le = self.s.to_le_bytes();
364-
let sig_r = ct_option_ok_or(Fq::from_repr(sig_r_le), Error::Signature)?;
365-
let sig_s = ct_option_ok_or(Fq::from_repr(sig_s_le), Error::Signature)?;
368+
let sig_r = ct_option_ok_or(Fq_K1::from_repr(sig_r_le), Error::Signature)?;
369+
let sig_s = ct_option_ok_or(Fq_K1::from_repr(sig_s_le), Error::Signature)?;
366370
let msg = self.rlp_unsigned_bytes.clone().into();
367371
let msg_hash: [u8; 32] = Keccak256::digest(&msg)
368372
.as_slice()
@@ -375,7 +379,7 @@ impl Transaction {
375379
let msg_hash = BigUint::from_bytes_be(msg_hash.as_slice());
376380
let msg_hash = msg_hash.mod_floor(&*SECP256K1_Q);
377381
let msg_hash_le = biguint_to_32bytes_le(msg_hash);
378-
let msg_hash = ct_option_ok_or(Fq::from_repr(msg_hash_le), Error::Signature)?;
382+
let msg_hash = ct_option_ok_or(Fq_K1::from_repr(msg_hash_le), Error::Signature)?;
379383
Ok(SignData {
380384
signature: (sig_r, sig_s, v),
381385
pk,

0 commit comments

Comments
 (0)