Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
feat: fixed all errors coming from sig_circuit merging
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Jan 27, 2024
1 parent 772ae18 commit 3dc90c3
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 99 deletions.
7 changes: 7 additions & 0 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub struct FixedCParams {
/// calculated, so the same circuit will not be able to prove different
/// witnesses.
pub max_keccak_rows: usize,
/// This number indicate what 100% usage means, for example if we can support up to 2
/// ecPairing inside circuit, and max_vertical_circuit_rows is set to 1_000_000,
/// then if there is 1 ecPairing in the input, we will return 500_000 as the "row usage"
/// for the ec circuit.
pub max_vertical_circuit_rows: usize,
}

/// Unset Circuits Parameters
Expand Down Expand Up @@ -117,6 +122,7 @@ impl Default for FixedCParams {
max_bytecode: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_vertical_circuit_rows: 0,
}
}
}
Expand Down Expand Up @@ -450,6 +456,7 @@ impl CircuitInputBuilder<DynamicCParams> {
max_bytecode,
max_evm_rows,
max_keccak_rows,
max_vertical_circuit_rows: 0,
}
};
let mut cib = CircuitInputBuilder::<FixedCParams> {
Expand Down
1 change: 1 addition & 0 deletions bus-mapping/src/evm/opcodes/precompiles/ecrecover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub(crate) fn opt_data(
sig_v,
),
pk: recovered_pk,
msg: aux_data.input_bytes.clone().into(),
msg_hash: {
let msg_hash = BigUint::from_bytes_be(&aux_data.msg_hash.to_be_bytes());
let msg_hash = msg_hash.mod_floor(&*SECP256K1_Q);
Expand Down
1 change: 1 addition & 0 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl Transaction {
Ok(SignData {
signature: (sig_r, sig_s, v),
pk,
msg,
msg_hash,
})
}
Expand Down
9 changes: 8 additions & 1 deletion eth-types/src/sign_types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! secp256k1 signature types and helper functions.

use crate::{ToBigEndian, Word};
use ethers_core::{types::Address, utils::keccak256};
use ethers_core::{
types::{Address, Bytes},
utils::keccak256,
};
use halo2_proofs::{
arithmetic::{CurveAffine, Field},
halo2curves::{
Expand Down Expand Up @@ -50,6 +53,8 @@ pub struct SignData {
pub signature: (secp256k1::Fq, secp256k1::Fq, u8),
/// Secp256k1 public key
pub pk: Secp256k1Affine,
/// Message being hashed before signing.
pub msg: Bytes,
/// Hash of the message that is being signed
pub msg_hash: secp256k1::Fq,
}
Expand All @@ -71,13 +76,15 @@ lazy_static! {
let sk = secp256k1::Fq::ONE;
let pk = generator * sk;
let pk = pk.to_affine();
let msg = Bytes::new();
let msg_hash = secp256k1::Fq::ONE;
let randomness = secp256k1::Fq::ONE;
let (sig_r, sig_s, sig_v) = sign(randomness, sk, msg_hash);

SignData {
signature: (sig_r, sig_s, sig_v),
pk,
msg,
msg_hash,
}
};
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const MAX_EVM_ROWS: usize = 10000;
const MAX_EXP_STEPS: usize = 1000;

const MAX_KECCAK_ROWS: usize = 38000;
/// MAX_VERTICAL_CIRCUIT_ROWS
const MAX_VERTICAL_CIRCUIT_ROWS: usize = 0;

const CIRCUITS_PARAMS: FixedCParams = FixedCParams {
max_rws: MAX_RWS,
Expand All @@ -77,6 +79,7 @@ const CIRCUITS_PARAMS: FixedCParams = FixedCParams {
max_evm_rows: MAX_EVM_ROWS,
max_exp_steps: MAX_EXP_STEPS,
max_keccak_rows: MAX_KECCAK_ROWS,
max_vertical_circuit_rows: MAX_VERTICAL_CIRCUIT_ROWS,
};

const EVM_CIRCUIT_DEGREE: u32 = 18;
Expand Down
2 changes: 2 additions & 0 deletions testool/src/statetest/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ pub fn run_test(
max_evm_rows: 0,
max_exp_steps: 5000,
max_keccak_rows: 0,
max_vertical_circuit_rows: 0,
};
let block_data = BlockData::new_from_geth_data_with_params(geth_data, circuits_params);

Expand Down Expand Up @@ -375,6 +376,7 @@ pub fn run_test(
max_bytecode: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_vertical_circuit_rows: 0,
};
let (k, circuit, instance, _builder) =
SuperCircuit::<Fr>::build(geth_data, circuits_params, Fr::from(0x100)).unwrap();
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/root_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn test_root_circuit() {
max_bytecode: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_vertical_circuit_rows: 0,
};
let (k, circuit, instance, _) =
SuperCircuit::<_>::build(block_1tx(), circuits_params, TEST_MOCK_RANDOMNESS.into())
Expand Down
Loading

0 comments on commit 3dc90c3

Please sign in to comment.