Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add secp256r1 support #1351

Merged
merged 72 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2d238e3
update SignData with generic type
DreamWuGit Jun 27, 2024
f430f3d
update PrecompileEvent::SignData
DreamWuGit Jun 27, 2024
29f7c34
update some SignDatas
DreamWuGit Jun 27, 2024
1b7d0f2
add sig circuit signatures_r1
DreamWuGit Jun 27, 2024
9c59cf3
change tx circuit regarding signdata
DreamWuGit Jun 27, 2024
ca79ecc
sig table adds p256 signatures
DreamWuGit Jun 28, 2024
fb1d74a
add ecdsa_r1_config
DreamWuGit Jun 28, 2024
435c392
add FpChipR1 type
DreamWuGit Jul 1, 2024
bdff1f7
fix comment
DreamWuGit Jul 1, 2024
aad86aa
Merge branch 'develop' into feat/secp256r1
DreamWuGit Jul 1, 2024
ffd9263
rename FpChip
DreamWuGit Jul 2, 2024
7272aa1
add assign_ecdsa_generic method
DreamWuGit Jul 3, 2024
01e6f94
fix assign_ecdsa_generic issue
DreamWuGit Jul 3, 2024
71d64fe
update sign_data_decomposition_generic
DreamWuGit Jul 4, 2024
be10b33
make pk_bytes_le_generic helper
DreamWuGit Jul 4, 2024
0d72669
apply sign_data_decomposition_generic
DreamWuGit Jul 5, 2024
266fc75
add assign_sig_verify_generic
DreamWuGit Jul 5, 2024
9c35569
apply assign_sig_verify_generic
DreamWuGit Jul 7, 2024
65a80f3
ecdsa_r1_config.range load lookup
DreamWuGit Jul 9, 2024
1ebd7bf
update existing sig circuit tests
DreamWuGit Jul 10, 2024
cf4ccef
add helper sign_generic
DreamWuGit Jul 10, 2024
b469244
rename sign_generic to sign and remove old method
DreamWuGit Jul 10, 2024
e6d5784
add new test p256_sign_verify
DreamWuGit Jul 11, 2024
15476f3
add random msg_hash test
DreamWuGit Jul 11, 2024
116a56b
add sign_verify and rename old
DreamWuGit Jul 11, 2024
fea64c4
sign_verify fill with k1 & r1 test data
DreamWuGit Jul 11, 2024
29ea9b2
msg_hash == 0 case
DreamWuGit Jul 12, 2024
748ec0b
sync develop branch
DreamWuGit Oct 9, 2024
54207ec
fix merge error
DreamWuGit Oct 9, 2024
4650850
update cargo for halo2-lib version
DreamWuGit Oct 10, 2024
d26cdb8
replace FqChipK1
DreamWuGit Oct 10, 2024
faf30bd
two chips use one RangeConfig & remove
DreamWuGit Oct 11, 2024
b9c76ec
keccak lookup for r1 pk hash
DreamWuGit Oct 11, 2024
0204f98
fix keccak input bytes
DreamWuGit Oct 11, 2024
24916f3
misc update
DreamWuGit Oct 12, 2024
5ac53a2
add temp debug info
DreamWuGit Oct 14, 2024
92f8040
revert temp two RangeChip
DreamWuGit Oct 15, 2024
14d0184
p256 not check v & y oddness match
DreamWuGit Oct 17, 2024
76df7bf
add helper is_p256_precompile
DreamWuGit Oct 17, 2024
9e63de1
add p256 crate test
DreamWuGit Oct 17, 2024
0fd1512
add verify sig helper
DreamWuGit Oct 19, 2024
9092084
tests against p256 branch
DreamWuGit Oct 24, 2024
cb98f49
comment out p256 crate test
DreamWuGit Oct 24, 2024
8300bf7
update halo2-lib branch & ecc_circuit::decompose_ec_mul_op
DreamWuGit Oct 25, 2024
2c77320
remove debug info
DreamWuGit Oct 25, 2024
262dc23
max_verify into max_verify_k1&max_verify_r1
DreamWuGit Oct 25, 2024
45c4487
update test per max_verify
DreamWuGit Oct 26, 2024
40f5d6c
pad default sigdata
DreamWuGit Oct 27, 2024
b12de56
fix pad sig lookup
DreamWuGit Oct 28, 2024
96c48a5
pad default
DreamWuGit Oct 28, 2024
b3e0d6e
Merge branch 'develop' into feat/secp256r1
DreamWuGit Oct 28, 2024
212e1b0
update types
DreamWuGit Oct 28, 2024
01bd0d1
Merge branch 'feat/secp256r1' of https://github.com/scroll-tech/zkevm…
DreamWuGit Oct 28, 2024
ab99141
clippy & comment
DreamWuGit Oct 28, 2024
cd7d774
modify test
DreamWuGit Oct 28, 2024
402b1c6
remove unused codes of sig circuit
DreamWuGit Oct 28, 2024
78d85e8
adjust MAX_NUM_SIG_K1&R1
DreamWuGit Oct 28, 2024
a045cda
Update utils.rs
lispc Oct 29, 2024
859ef81
Update sig_circuit.rs
lispc Oct 29, 2024
980b8d9
Update utils.rs
lispc Oct 29, 2024
a9c5b20
Update utils.rs
lispc Oct 29, 2024
4853bcb
Update utils.rs
lispc Oct 29, 2024
8116b60
const limbits, num_limbs
DreamWuGit Oct 29, 2024
267d759
increase COLUMN_NUM_LIMIT
DreamWuGit Oct 29, 2024
355e337
use accurate CELLS_PER_SIG, adjust min_num
DreamWuGit Oct 29, 2024
a864510
handle padding in get_sign_data_p256
DreamWuGit Oct 29, 2024
991bee2
try keccak
DreamWuGit Oct 29, 2024
1566e61
disable assigned_keccak_values_r1 & clean
DreamWuGit Oct 30, 2024
e920030
enable assigned_keccak_values_r1
DreamWuGit Oct 30, 2024
6158319
clippy
DreamWuGit Oct 30, 2024
dc4bfd9
clippy
DreamWuGit Oct 30, 2024
308ede9
fix fmt
DreamWuGit Oct 30, 2024
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
37 changes: 35 additions & 2 deletions Cargo.lock

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

30 changes: 28 additions & 2 deletions bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ use halo2_proofs::{
};
use strum_macros::EnumIter;

use halo2_proofs::halo2curves::{
// secp256k1 curve
secp256k1::{Fp as Fp_K1, Fq as Fq_K1, Secp256k1Affine},
// p256 curve
secp256r1::{Fp as Fp_R1, Fq as Fq_R1, Secp256r1Affine},
Coordinates,
//CurveAffine,
};

/// An execution step of the EVM.
#[derive(Clone, Debug)]
pub struct ExecStep {
Expand Down Expand Up @@ -843,7 +852,7 @@ pub struct PrecompileEvents {

impl PrecompileEvents {
/// Get all ecrecover events.
pub fn get_ecrecover_events(&self) -> Vec<SignData> {
pub fn get_ecrecover_events(&self) -> Vec<SignData<Fq_K1, Secp256k1Affine>> {
self.events
.iter()
.filter_map(|e| {
Expand Down Expand Up @@ -926,13 +935,28 @@ impl PrecompileEvents {
.cloned()
.collect()
}

/// Get all p256 verify events.
pub fn get_p256_verify_events(&self) -> Vec<SignData<Fq_R1, Secp256r1Affine>> {
self.events
.iter()
.filter_map(|e: &PrecompileEvent| {
if let PrecompileEvent::P256Verify(sign_data) = e {
Some(sign_data)
} else {
None
}
})
.cloned()
.collect()
}
}

/// I/O from a precompiled contract call.
#[derive(Clone, Debug)]
pub enum PrecompileEvent {
/// Represents the I/O from Ecrecover call.
Ecrecover(SignData),
Ecrecover(SignData<Fq_K1, Secp256k1Affine>),
/// Represents the I/O from EcAdd call.
EcAdd(EcAddOp),
/// Represents the I/O from EcMul call.
Expand All @@ -943,6 +967,8 @@ pub enum PrecompileEvent {
ModExp(BigModExp),
/// Represents the I/O from SHA256 call.
SHA256(SHA256),
/// Represents the I/O from P256Verify call.
P256Verify(SignData<Fq_R1, Secp256r1Affine>),
}

impl Default for PrecompileEvent {
Expand Down
14 changes: 9 additions & 5 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use ethers_core::types::{
transaction::eip2718::TypedTransaction, Eip1559TransactionRequest, Eip2930TransactionRequest,
NameOrAddress, TransactionRequest, H256,
};
use halo2curves::{group::ff::PrimeField, secp256k1::Fq};
use halo2curves::{
group::ff::PrimeField,
secp256k1::{Fq as Fq_K1, Secp256k1Affine},
};
use num::Integer;
use num_bigint::BigUint;
use serde::{Serialize, Serializer};
Expand Down Expand Up @@ -357,12 +360,13 @@ impl From<&Transaction> for TransactionRequest {
}

impl Transaction {
/// secp256k1 method:
/// Return the SignData associated with this Transaction.
pub fn sign_data(&self) -> Result<SignData, Error> {
pub fn sign_data(&self) -> Result<SignData<Fq_K1, Secp256k1Affine>, Error> {
let sig_r_le = self.r.to_le_bytes();
let sig_s_le = self.s.to_le_bytes();
let sig_r = ct_option_ok_or(Fq::from_repr(sig_r_le), Error::Signature)?;
let sig_s = ct_option_ok_or(Fq::from_repr(sig_s_le), Error::Signature)?;
let sig_r = ct_option_ok_or(Fq_K1::from_repr(sig_r_le), Error::Signature)?;
let sig_s = ct_option_ok_or(Fq_K1::from_repr(sig_s_le), Error::Signature)?;
let msg = self.rlp_unsigned_bytes.clone().into();
let msg_hash: [u8; 32] = Keccak256::digest(&msg)
.as_slice()
Expand All @@ -375,7 +379,7 @@ impl Transaction {
let msg_hash = BigUint::from_bytes_be(msg_hash.as_slice());
let msg_hash = msg_hash.mod_floor(&*SECP256K1_Q);
let msg_hash_le = biguint_to_32bytes_le(msg_hash);
let msg_hash = ct_option_ok_or(Fq::from_repr(msg_hash_le), Error::Signature)?;
let msg_hash = ct_option_ok_or(Fq_K1::from_repr(msg_hash_le), Error::Signature)?;
Ok(SignData {
signature: (sig_r, sig_s, v),
pk,
Expand Down
Loading
Loading