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

[proof-chunk] Instantiate circuits with Chunk from bus-mapping #1690

Conversation

CeciliaZ030
Copy link
Contributor

@CeciliaZ030 CeciliaZ030 commented Nov 28, 2023

Description

Instantiate circuits with Block and specified Chunk from bus-mapping. Refactor CircuitInputBuilder to generate given number of Chunks with fixed or dynamic params. Note that one instance of the circuit corresponds to one chunk instead of one block.
Screen Shot 2023-12-08 at 11 37 30 PM

Issue Link

#1696

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Contents

  • Initialize the CircuitInputBuilder with either FixedCParam or just specify the total number of chunk and dynamically derive parameter after a dry run.
  • In handle_tx split the chunk whenever the local rwc exceeds the target amount, specifically by setting the EndChunk and proceed to the next BeginChunk if needed.
  • Commit the ChunkCtx for each chunk at the end, which tracks the global Rw range & local rwc later used in the State circuits.
  • After the block is handled, generate witness for a specific chunk with builder.chunk_convert(idx), analogous to builder.block_convert().
  • Config the circuit with both block and chunk, which leads to API changes in SubCircuit<F: Field> trait including new_from_block(&block, &chunk) and min_num_rows_block(&block, &chunk).

Workflow

For CircuitInputBuilder chunk is needed to build all circuits:

let builder = BlockData::new_from_geth_data(geth_data.clone())
        .new_circuit_input_builder()
        .handle_block(&eth_block, &geth_traces)
        .expect("handle_block");
    
let block = block_convert(&builder);   
let chunk = chunk_convert(&builder, 0);
   
let circuit = SuperCircuit::new_from_block(&block, &chunk);

For CircuitTestBuilder modifier is applied to both block and chunk, and you can run with fixed or dynamic params:

CircuitTestBuilder::new_from_test_ctx(
        TestContext::<2, 1>::simple_ctx_with_bytecode(bytecode).unwrap(),
    )
    .modifier(Box::new(move |block, chunk| {
        // do something..
    }))
    .run_dynamic_chunk(4, 2);
CircuitTestBuilder::new_from_block(block)
    .params(FixedCParams {
        total_chunks: 2,
        max_rws: 60,
        ..Default::default()
    })
    .run_chunk(1);

Default run() still works since it runs one chunk internally.

CircuitTestBuilder::new_from_block(block).run()

new from block with chunk
cecilia-wip
@github-actions github-actions bot added crate-bus-mapping Issues related to the bus-mapping workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member crate-integration-tests Issues related to the integration-tests workspace member labels Nov 28, 2023
@CeciliaZ030 CeciliaZ030 changed the title connect prev and cur fingerprint generated frm rw tables Instantiate circuits with Chunk from bus-mapping Nov 28, 2023
@hero78119 hero78119 changed the title Instantiate circuits with Chunk from bus-mapping [proof-chunk] Instantiate circuits with Chunk from bus-mapping Nov 28, 2023
Copy link
Member

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
First round quick passed and just few feedbacks

  • it will be more clear to have PR description for what items has been covered in this PR along with TODO items.
  • By quick overview I think current scope of PR is
    • define chunk structure in bus-mapping
    • convert chunk structure to chunk witness and bypass to circuit
      I think current chunk structure might need to be further tuning when chunking flow are introduced, which seems to be in downstream work by @einar-taiko ? May I know whats plan to combining both works ?

zkevm-circuits/src/witness/chunk.rs Outdated Show resolved Hide resolved
bus-mapping/src/circuit_input_builder.rs Show resolved Hide resolved
bus-mapping/src/circuit_input_builder.rs Outdated Show resolved Hide resolved
bus-mapping/src/circuit_input_builder.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added T-bench Type: benchmark improvements crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member labels Dec 2, 2023
@github-actions github-actions bot added crate-mock Issues related to the mock workspace member crate-eth-types Issues related to the eth-types workspace member labels Dec 3, 2023
@github-actions github-actions bot removed crate-mock Issues related to the mock workspace member crate-eth-types Issues related to the eth-types workspace member labels Dec 3, 2023
@CeciliaZ030
Copy link
Contributor Author

Latest chunked scope

Red: directly chunked data are Rw -> state_circuit and ExecStep -> evm_circuit

  • Chunked Vec<Rw> are kept in struct Chunk<F>
  • Txs & Steps are chunked in execution.rs, see below:
let chunk_txs = block.txs.get(chunk.initial_tx - 1..chunk.end_tx)
let chunk_steps = chunk_txs.iter().map(|tx| tx.steps()).collect()

Blue: chunking CopyEvent cause by lookup into state table: copy_circuit.rs
Green: using chunked Transaction from evm_circuit for configuring tuples of (Tx, Call, Step), but tx_circuit is not affected.
Screen Shot 2024-01-12 at 3 16 26 AM

@hero78119
Copy link
Member

Thanks for the contribution @CeciliaZ030
Will merge it first and leave other improvement to future PR

@hero78119 hero78119 merged commit c017424 into privacy-scaling-explorations:proof-chunk Feb 1, 2024
13 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-bus-mapping Issues related to the bus-mapping workspace member crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-gadgets Issues related to the gadgets workspace member crate-integration-tests Issues related to the integration-tests workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[proof-chunk] witness chunking in bus-mapping
2 participants