Skip to content

Commit

Permalink
add circuit_params.max_mpt_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed Apr 17, 2023
1 parent e8bcb23 commit 700e93c
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub struct CircuitsParams {
/// In this case it will contain as many rows for all steps + 1 row
/// for EndBlock.
pub max_evm_rows: usize,
/// Max amount of rows that the CopyCircuit can have.
pub max_mpt_rows: usize,
/// Pad the keccak circuit with this number of invocations to a static
/// capacity. Number of keccak_f that the Keccak circuit will support.
/// When 0, the Keccak circuit number of rows will be dynamically
Expand All @@ -96,6 +98,7 @@ impl Default for CircuitsParams {
// TODO: Check whether this value is correct or we should increase/decrease based on
// this lib tests
max_copy_rows: 1000,
max_mpt_rows: 1000,
max_exp_steps: 1000,
max_bytecode: 512,
max_evm_rows: 0,
Expand Down
1 change: 1 addition & 0 deletions circuit-benchmarks/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mod tests {
max_rws: 256,
max_copy_rows: 256,
max_exp_steps: 256,
max_mpt_rows: 512,
max_bytecode: 512,
max_evm_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
Expand Down
1 change: 1 addition & 0 deletions circuit-benchmarks/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod tests {
max_txs: 500,
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_mpt_rows: 3_000_000,
max_bytecode: 3_000_000,
max_keccak_rows: 0, // FIXME: can this be none?
max_exp_steps: 100_000,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const CIRCUITS_PARAMS: CircuitsParams = CircuitsParams {
max_rws: MAX_RWS,
max_txs: MAX_TXS,
max_calldata: MAX_CALLDATA,
max_mpt_rows: MAX_CALLDATA,
max_inner_blocks: 64,
max_bytecode: MAX_BYTECODE,
max_copy_rows: MAX_COPY_ROWS,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async fn test_circuit_input_builder_block(block_num: u64) {
max_inner_blocks: 64,
max_bytecode: 4000,
max_copy_rows: 16384,
max_mpt_rows: 4000,
max_evm_rows: 0,
max_exp_steps: 1000,
max_keccak_rows: 0,
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/tests/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const CIRCUITS_PARAMS: CircuitsParams = CircuitsParams {
max_calldata: 30000,
max_inner_blocks: 64,
max_bytecode: 30000,
max_mpt_rows: 30000,
max_keccak_rows: 0,
max_exp_steps: 1000,
max_evm_rows: 0,
Expand All @@ -47,6 +48,7 @@ async fn test_mock_prove_tx() {
max_copy_rows: 100000,
max_txs: 10,
max_calldata: 40000,
max_mpt_rows: 40000,
max_inner_blocks: 64,
max_bytecode: 40000,
max_keccak_rows: 0,
Expand Down Expand Up @@ -114,6 +116,7 @@ async fn test_circuit_all_block() {
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_bytecode: 3_000_000,
max_mpt_rows: 2_000_000,
max_keccak_rows: 0,
max_exp_steps: 100_000,
max_evm_rows: 0,
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 @@ -315,6 +315,7 @@ pub fn run_test(
max_rws: 0,
max_calldata: 5000,
max_bytecode: 5000,
max_mpt_rows: 5000,
max_copy_rows: 55000,
max_evm_rows: 0,
max_exp_steps: 5000,
Expand All @@ -341,6 +342,7 @@ pub fn run_test(
max_calldata: MAX_CALLDATA,
max_rws: 256,
max_copy_rows: 256,
max_mpt_rows: 256,
max_exp_steps: 256,
max_bytecode: 512,
max_evm_rows: 0,
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/mpt_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<F: Field + Hashable> SubCircuit<F> for MptCircuit<F> {
(
// notice we do not use the accompanied hash circuit so just assign any size
100usize,
Some(block.circuits_params.max_rws),
Some(block.circuits_params.max_mpt_rows),
),
&block.mpt_updates.proof_types,
);
Expand Down
12 changes: 7 additions & 5 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ impl PublicData {
.filter(|tx| tx.block_number == *block_num)
.count() as u16;
let parent_hash = block.eth_block.parent_hash;
log::debug!(
"block.history_hashes.len() = {}, parent_hash = {}",
block.history_hashes.len(),
parent_hash
);
if !block.history_hashes.is_empty() || !parent_hash.is_zero() {
log::debug!(
"block.history_hashes.len() = {}, parent_hash = {}",
block.history_hashes.len(),
parent_hash
);
}
// TODO: use reasonable method to get this data
let num_l1_msgs = 0_u16; // 0 for now

Expand Down
9 changes: 6 additions & 3 deletions zkevm-circuits/src/state_circuit/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ where
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let challenges = challenges.values(&layouter);
config
.mpt_table
.load(&mut layouter, &self.updates, challenges.evm_word())?;
config.mpt_table.load(
&mut layouter,
&self.updates,
self.n_rows,
challenges.evm_word(),
)?;
self.synthesize_sub(&config, &challenges, &mut layouter)
}
}
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ impl<
config.mpt_table.load(
&mut layouter,
&self.state_circuit.updates,
block.circuits_params.max_mpt_rows,
challenges.evm_word(),
)?;

Expand Down
5 changes: 5 additions & 0 deletions zkevm-circuits/src/super_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ fn serial_test_super_circuit_1tx_1max_tx() {
max_copy_rows: 256,
max_exp_steps: 256,
max_bytecode: 512,
max_mpt_rows: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
Expand All @@ -226,6 +227,7 @@ fn serial_test_super_circuit_1tx_deploy_2max_tx() {
max_calldata: MAX_CALLDATA,
max_rws: MAX_RWS,
max_copy_rows: MAX_COPY_ROWS,
max_mpt_rows: 512,
max_bytecode: 512,
max_keccak_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
Expand Down Expand Up @@ -253,6 +255,7 @@ fn serial_test_super_circuit_1tx_2max_tx() {
max_copy_rows: 256,
max_exp_steps: 256,
max_bytecode: 512,
max_mpt_rows: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
Expand All @@ -279,6 +282,7 @@ fn serial_test_super_circuit_2tx_4max_tx() {
max_rws: MAX_RWS,
max_copy_rows: MAX_COPY_ROWS,
max_bytecode: 512,
max_mpt_rows: 512,
max_keccak_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
max_exp_steps: 256,
Expand All @@ -303,6 +307,7 @@ fn serial_test_super_circuit_2tx_2max_tx() {
max_calldata: MAX_CALLDATA,
max_rws: 256,
max_copy_rows: 256,
max_mpt_rows: 512,
max_exp_steps: 256,
max_bytecode: 512,
max_evm_rows: 0,
Expand Down
28 changes: 17 additions & 11 deletions zkevm-circuits/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@ pub struct TxTable {
impl TxTable {
/// Construct a new TxTable
pub fn construct<F: Field>(meta: &mut ConstraintSystem<F>) -> Self {
let q_enable = meta.fixed_column();
let tag = meta.fixed_column();
Self {
q_enable: meta.fixed_column(),
q_enable,
tx_id: meta.advice_column(),
tag: meta.fixed_column(),
tag,
index: meta.advice_column(),
value: meta.advice_column_in(SecondPhase),
}
Expand Down Expand Up @@ -294,12 +296,7 @@ impl TxTable {
calldata_assignments.extend(tx_calldata.iter());
}
// Assign Tx calldata
let dummy_row = [Value::known(F::zero()); 4];
for row in calldata_assignments
.into_iter()
.chain(repeat(dummy_row))
.take(max_calldata)
{
for row in calldata_assignments.into_iter() {
assign_row(
&mut region,
offset,
Expand Down Expand Up @@ -765,22 +762,31 @@ impl MptTable {
&self,
layouter: &mut impl Layouter<F>,
updates: &MptUpdates,
max_mpt_rows: usize,
randomness: Value<F>,
) -> Result<(), Error> {
layouter.assign_region(
|| "mpt table zkevm",
|mut region| self.load_with_region(&mut region, updates, randomness),
|mut region| self.load_with_region(&mut region, updates, max_mpt_rows, randomness),
)
}

pub(crate) fn load_with_region<F: Field>(
&self,
region: &mut Region<'_, F>,
updates: &MptUpdates,
max_mpt_rows: usize,
randomness: Value<F>,
) -> Result<(), Error> {
for (offset, row) in updates.table_assignments(randomness).iter().enumerate() {
self.assign(region, offset, row)?;
let dummy_row = MptUpdateRow([Value::known(F::zero()); 7]);
for (offset, row) in updates
.table_assignments(randomness)
.into_iter()
.chain(repeat(dummy_row))
.take(max_mpt_rows)
.enumerate()
{
self.assign(region, offset, &row)?;
}
Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions zkevm-circuits/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,12 @@ impl<F: Field> TxCircuitConfig<F> {
offset,
|| Value::known(rlp_data),
)?;
region.assign_fixed(
|| "q_enable",
self.q_enable,
offset,
|| Value::known(F::one()),
)?;
region.assign_fixed(|| "tag", self.tx_table.tag, offset, || Value::known(tag))?;
tag_chip.assign(region, offset, &CallData)?;
// no need to assign tx_id_is_zero_chip for real prover as tx_id = 0
Expand Down

0 comments on commit 700e93c

Please sign in to comment.