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

Commit

Permalink
super circuit keccak dev_load
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Apr 10, 2023
1 parent c05333f commit 0e2744a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 10 additions & 7 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ impl PublicData {
.collect_vec()
}

fn get_pi_bytes(&self, max_txs: usize, max_calldata: usize) -> Vec<u8> {
/// get the serialized public data bytes
pub fn get_pi_bytes(&self, max_txs: usize, max_calldata: usize) -> Vec<u8> {
// Assign block table
let block_values = self.get_block_table_values();
let result = iter::empty()
Expand Down Expand Up @@ -2040,18 +2041,16 @@ impl<F: Field> SubCircuit<F> for PiCircuit<F> {
config.assign_rpi_digest(&mut region, digest, _challenges)?;

// lookup assignment
// length start from 1, therefore with offset has 1 diff
// let real_rpi_length = rpi_bytes_length_acc - 1; // length already point to next
// line, therefore real length need minus 1
// here `-2` because length start from 1
// and rpi_bytes_length_acc point to next row after each raw_bytes assigment
let keccak_offset = rpi_bytes_length_acc - 2;

// keccak is the last line
config.q_rpi_byte_last.enable(&mut region, keccak_offset)?;

// assign last & last +1 to 0.
// assign last + 1 to 0.
// otherwise it will emit CellNotAssigned Error
config.reset_rpi_bytes_row(&mut region, keccak_offset + 1)?;
config.reset_rpi_bytes_row(&mut region, keccak_offset + 2)?;
// also assign empty to last of TxTable
config.assign_empty_txtable_row(&mut region, call_data_offset)?;

Expand Down Expand Up @@ -2260,6 +2259,8 @@ mod pi_circuit_test {

#[test]
fn test_1tx_1maxtx() {
const MAX_TXS: usize = 1;
const MAX_CALLDATA: usize = 32;
let mut rng = ChaChaRng::seed_from_u64(2);
let wallet_a = LocalWallet::new(&mut rng).with_chain_id(MOCK_CHAIN_ID.as_u64());

Expand Down Expand Up @@ -2296,6 +2297,8 @@ mod pi_circuit_test {
let mut builder = BlockData::new_from_geth_data_with_params(
block.clone(),
CircuitsParams {
max_txs: MAX_TXS,
max_calldata: MAX_CALLDATA,
max_rws: 1 << (degree - 1),
..Default::default()
},
Expand All @@ -2311,7 +2314,7 @@ mod pi_circuit_test {
builder.block.eth_block = block.eth_block.clone();
let block = block_convert(&builder.block, &builder.code_db).unwrap();
// MAX_TXS, MAX_TXS align with `CircuitsParams`
let circuit = PiTestCircuit::<Fr, 1, 256>::new_from_block(&block);
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>::new_from_block(&block);
let public_inputs = circuit.0.instance();

let prover = match MockProver::run(degree, &circuit, public_inputs) {
Expand Down
12 changes: 11 additions & 1 deletion zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use std::array;
pub struct SuperCircuitConfig<F: Field> {
block_table: BlockTable,
mpt_table: MptTable,
keccak_table: KeccakTable,
evm_circuit: EvmCircuitConfig<F>,
state_circuit: StateCircuitConfig<F>,
tx_circuit: TxCircuitConfig<F>,
Expand Down Expand Up @@ -202,14 +203,15 @@ impl<F: Field> SubCircuitConfig<F> for SuperCircuitConfig<F> {
bytecode_table,
block_table: block_table.clone(),
copy_table,
keccak_table,
keccak_table: keccak_table.clone(),
exp_table,
},
);

Self {
block_table,
mpt_table,
keccak_table,
evm_circuit,
state_circuit,
copy_circuit,
Expand Down Expand Up @@ -399,6 +401,14 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MOCK_RANDO
Value::known(block.randomness),
)?;

let rpi_bytes = self.pi_circuit.public_data.get_pi_bytes(
block.circuits_params.max_txs,
block.circuits_params.max_calldata,
);
config
.keccak_table
.dev_load(&mut layouter, vec![&rpi_bytes], &challenges)?;

self.synthesize_sub(&config, &challenges, &mut layouter)
}
}
Expand Down

0 comments on commit 0e2744a

Please sign in to comment.