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

Commit

Permalink
fix pi-circuit in integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Apr 6, 2023
1 parent 9c5eed1 commit 0f15455
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
7 changes: 0 additions & 7 deletions circuit-benchmarks/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod tests {
use ark_std::{end_timer, start_timer};
use eth_types::Word;
use halo2_proofs::{
arithmetic::Field,
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof},
poly::{
Expand All @@ -20,7 +19,6 @@ mod tests {
},
};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use rand_xorshift::XorShiftRng;
use std::env::var;
use zkevm_circuits::{
Expand All @@ -45,15 +43,10 @@ mod tests {
.parse()
.expect("Cannot parse DEGREE env var as u32");

let mut rng = ChaCha20Rng::seed_from_u64(2);
let randomness = Fr::random(&mut rng);
let rand_rpi = Fr::random(&mut rng);
let public_data = generate_publicdata::<MAX_TXS, MAX_CALLDATA>();
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>(PiCircuit::<Fr>::new(
MAX_TXS,
MAX_CALLDATA,
randomness,
rand_rpi,
public_data,
));
let public_inputs = circuit.0.instance();
Expand Down
7 changes: 2 additions & 5 deletions zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,7 @@ pub(crate) mod from_bytes {
/// Returns the random linear combination of the inputs.
/// Encoding is done as follows: v_0 * R^0 + v_1 * R^1 + ...
pub(crate) mod rlc {
use std::{
fmt::Debug,
ops::{Add, Mul},
};
use std::ops::{Add, Mul};

use crate::util::Expr;
use halo2_proofs::{arithmetic::FieldExt, plonk::Expression};
Expand Down Expand Up @@ -575,7 +572,7 @@ pub(crate) mod rlc {
where
I: IntoIterator<Item = V>,
<I as IntoIterator>::IntoIter: DoubleEndedIterator,
V: Clone + Add<Output = V> + Mul<Output = V> + Debug,
V: Clone + Add<Output = V> + Mul<Output = V>,
{
let mut values = values.into_iter().rev();
let init = values.next().expect("values should not be empty");
Expand Down
33 changes: 17 additions & 16 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const EMPTY_TX_ROW_COUNT: usize = 1;
const EMPTY_BLOCK_ROW_COUNT: usize = 1;
const N_BYTES_ONE: usize = 1;

type AssignedByteCells<F> = (AssignedCell<F, F>, AssignedCell<F, F>, AssignedCell<F, F>);

/// Values of the block table (as in the spec)
#[derive(Clone, Default, Debug)]
pub struct BlockValues {
Expand Down Expand Up @@ -258,7 +260,7 @@ impl PublicData {
let txs = self.txs();
let all_calldata = txs
.iter()
.flat_map(|tx| tx.call_data.0.as_ref().iter().map(|byte| *byte))
.flat_map(|tx| tx.call_data.0.as_ref().iter().copied())
.collect_vec();
let calldata_count = all_calldata.len();
// concat call data with call data padding
Expand Down Expand Up @@ -1112,7 +1114,7 @@ impl<F: Field> PiCircuitConfig<F> {
rpi_bytes_length_acc,
challenges,
)?;
rpi_value_rlc_cells.push(rpi_value_rlc_cell.clone());
rpi_value_rlc_cells.push(rpi_value_rlc_cell);

assert!(rpi_value_rlc_cells.len() == tx_table_cells.len());

Expand Down Expand Up @@ -1154,7 +1156,7 @@ impl<F: Field> PiCircuitConfig<F> {
rpi_bytes: &mut [u8],
is_final: bool,
gas_cost: F,
) -> Result<(AssignedCell<F, F>, AssignedCell<F, F>), Error> {
) -> Result<(), Error> {
let tx_id = F::from(tx_id as u64);
let tx_id_inv = tx_id.invert().unwrap_or(F::zero());
let tx_id_diff = F::from(tx_id_next as u64) - tx_id;
Expand Down Expand Up @@ -1224,19 +1226,18 @@ impl<F: Field> PiCircuitConfig<F> {
)?;

// calldata value also need to be in copy constraint
let (rpi_bytes_keccakrlc_cell, rpi_value_rlc_cell, rpi_bytes_length_acc_cell) = self
.assign_raw_bytes(
region,
tx_value_bytes,
rpi_bytes_keccakrlc,
rpi_bytes,
rpi_bytes_length_acc,
challenges,
)?;
let (_, rpi_value_rlc_cell, _) = self.assign_raw_bytes(
region,
tx_value_bytes,
rpi_bytes_keccakrlc,
rpi_bytes,
rpi_bytes_length_acc,
challenges,
)?;

region.constrain_equal(rpi_value_rlc_cell.cell(), tx_value_cell.cell())?;

Ok((rpi_bytes_keccakrlc_cell, rpi_bytes_length_acc_cell))
Ok(())
}

/// assign raw bytes
Expand All @@ -1248,8 +1249,8 @@ impl<F: Field> PiCircuitConfig<F> {
rpi_bytes: &mut [u8],
rpi_bytes_length_acc: &mut usize,
challenges: &Challenges<Value<F>>,
) -> Result<(AssignedCell<F, F>, AssignedCell<F, F>, AssignedCell<F, F>), Error> {
assert!(value_bytes.len() > 0);
) -> Result<AssignedByteCells<F>, Error> {
assert!(!value_bytes.is_empty());

let evm_rand = challenges.evm_word();
let keccak_rand = challenges.keccak_input();
Expand Down Expand Up @@ -2067,7 +2068,7 @@ impl<F: Field> SubCircuit<F> for PiCircuit<F> {
keccak_offset,
|| rpi_digest_bytes_rlc,
)?;
vec![(rpi_digest_bytes_rlc_cell, rpi_digest_rlc_acc_lookup.clone())]
vec![(rpi_digest_bytes_rlc_cell, rpi_digest_rlc_acc_lookup)]
.iter()
.try_for_each(|(left, right)| {
region.constrain_equal(left.cell(), right.cell())
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ impl<F: Field> LookupTable<F> for BlockTable {

fn annotations(&self) -> Vec<String> {
vec![
String::from("block_table_tag"),
String::from("block_table_index"),
String::from("block_table_value"),
String::from("blocktable_tag"),
String::from("blocktable_index"),
String::from("blocktable_value"),
]
}
}
Expand Down

0 comments on commit 0f15455

Please sign in to comment.