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

Commit

Permalink
Address some comments from pinkie
Browse files Browse the repository at this point in the history
  • Loading branch information
ed255 committed Nov 29, 2022
1 parent f2dca8f commit 2152555
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
3 changes: 3 additions & 0 deletions testool/src/statetest/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ pub fn run_test(
nonce: tx.nonce,
gas: tx.gas_limit,
transaction_index: Some(U64::from(index)),
r: tx.r,
s: tx.s,
v: U64::from(tx.v),
..eth_types::Transaction::default()
})
.collect();
Expand Down
7 changes: 7 additions & 0 deletions zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,13 @@ impl<F: Field> SubCircuit<F> for BytecodeCircuit<F> {
type Config = BytecodeCircuitConfig<F>;

fn new_from_block(block: &witness::Block<F>) -> Self {
// TODO: Find a nicer way to add the extra `128`. Is this to account for
// unusable rows? Then it could be calculated like this:
// fn unusable_rows<F: Field, C: Circuit<F>>() -> usize {
// let mut cs = ConstraintSystem::default();
// C::configure(&mut cs);
// cs.blinding_factors()
// }
let bytecode_size = block.circuits_params.max_bytecode + 128;
let bytecodes: Vec<UnrolledBytecode<F>> = block
.bytecodes
Expand Down
2 changes: 2 additions & 0 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MAX_RWS: u
Value::known(block.randomness),
)?;

self.keccak_circuit
.synthesize_sub(&config.keccak_circuit, &challenges, &mut layouter)?;
self.bytecode_circuit.synthesize_sub(
&config.bytecode_circuit,
&challenges,
Expand Down
31 changes: 4 additions & 27 deletions zkevm-circuits/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ use eth_types::{
{geth_types::Transaction, Address, Field, ToLittleEndian, ToScalar},
};
use halo2_proofs::{
arithmetic::CurveAffine,
circuit::{AssignedCell, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Expression, Fixed},
};
use itertools::Itertools;
use log::error;
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use sign_verify::{AssignedSignatureVerify, SignVerifyChip, SignVerifyConfig};
use std::marker::PhantomData;

Expand Down Expand Up @@ -154,22 +151,11 @@ pub struct TxCircuit<F: Field> {

impl<F: Field> TxCircuit<F> {
/// Return a new TxCircuit
pub fn new(
max_txs: usize,
max_calldata: usize,
aux_generator: Secp256k1Affine,
chain_id: u64,
txs: Vec<Transaction>,
) -> Self {
pub fn new(max_txs: usize, max_calldata: usize, chain_id: u64, txs: Vec<Transaction>) -> Self {
TxCircuit::<F> {
max_txs,
max_calldata,
sign_verify: SignVerifyChip {
aux_generator,
window_size: 2,
max_verif: max_txs,
_marker: PhantomData,
},
sign_verify: SignVerifyChip::new(max_txs),
txs,
chain_id,
}
Expand Down Expand Up @@ -321,13 +307,9 @@ impl<F: Field> SubCircuit<F> for TxCircuit<F> {
type Config = TxCircuitConfig<F>;

fn new_from_block(block: &witness::Block<F>) -> Self {
let mut rng = ChaCha20Rng::seed_from_u64(42);
let aux_generator =
<Secp256k1Affine as CurveAffine>::CurveExt::random(&mut rng).to_affine();
Self::new(
block.circuits_params.max_txs,
block.circuits_params.max_calldata,
aux_generator,
block.context.chain_id.as_u64(),
block
.eth_block
Expand Down Expand Up @@ -418,9 +400,8 @@ mod tx_circuit_tests {
use super::*;
use eth_types::address;
use halo2_proofs::{
arithmetic::CurveAffine,
dev::{MockProver, VerifyFailure},
halo2curves::{bn256::Fr, group::Group},
halo2curves::bn256::Fr,
};
use mock::AddrOrWallet;
use pretty_assertions::assert_eq;
Expand All @@ -432,12 +413,8 @@ mod tx_circuit_tests {
max_txs: usize,
max_calldata: usize,
) -> Result<(), Vec<VerifyFailure>> {
let mut rng = ChaCha20Rng::seed_from_u64(2);
let aux_generator =
<Secp256k1Affine as CurveAffine>::CurveExt::random(&mut rng).to_affine();

// SignVerifyChip -> ECDSAChip -> MainGate instance column
let circuit = TxCircuit::<F>::new(max_txs, max_calldata, aux_generator, chain_id, txs);
let circuit = TxCircuit::<F>::new(max_txs, max_calldata, chain_id, txs);

let prover = match MockProver::run(k, &circuit, vec![vec![]]) {
Ok(prover) => prover,
Expand Down
27 changes: 25 additions & 2 deletions zkevm-circuits/src/tx_circuit/sign_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ use ecdsa::ecdsa::{AssignedEcdsaSig, AssignedPublicKey, EcdsaChip};
use eth_types::sign_types::{pk_bytes_le, pk_bytes_swap_endianness, SignData};
use eth_types::{self, Field};
use halo2_proofs::{
arithmetic::FieldExt,
arithmetic::{CurveAffine, FieldExt},
circuit::{AssignedCell, Cell, Layouter, Value},
halo2curves::secp256k1,
halo2curves::secp256k1::Secp256k1Affine,
halo2curves::{
group::{Curve, Group},
secp256k1,
},
plonk::{Advice, Column, ConstraintSystem, Error, Expression, SecondPhase, Selector},
poly::Rotation,
};
use integer::{AssignedInteger, IntegerChip, IntegerConfig, IntegerInstructions, Range};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;

use itertools::Itertools;
use keccak256::plain::Keccak;
Expand All @@ -47,6 +52,24 @@ pub struct SignVerifyChip<F: Field> {
pub _marker: PhantomData<F>,
}

impl<F: Field> SignVerifyChip<F> {
/// Return a new SignVerifyChip
pub fn new(max_verif: usize) -> Self {
// TODO: Investigate if it is safe to use a random point as aux generator that
// is choosen by the prover. If this is unsafe, we will need to update the
// EccChip to calculate an aux generator using the challange API.
let mut rng = ChaCha20Rng::seed_from_u64(0);
let aux_generator =
<Secp256k1Affine as CurveAffine>::CurveExt::random(&mut rng).to_affine();
Self {
aux_generator,
window_size: 2,
max_verif,
_marker: PhantomData,
}
}
}

const NUMBER_OF_LIMBS: usize = 4;
const BIT_LEN_LIMB: usize = 72;
const BIT_LEN_LAST_LIMB: usize = 256 - (NUMBER_OF_LIMBS - 1) * BIT_LEN_LIMB;
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/witness/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct Block<F> {
/// Inputs to the SHA3 opcode
pub sha3_inputs: Vec<Vec<u8>>,
/// State root of the previous block
pub prev_state_root: Word, // TODO: Make this U256
pub prev_state_root: Word, // TODO: Make this H256
/// Keccak inputs
pub keccak_inputs: Vec<Vec<u8>>,
/// Original Block from geth
Expand Down

0 comments on commit 2152555

Please sign in to comment.