Skip to content

Commit

Permalink
upgrade mpt circuit (scroll-tech#982)
Browse files Browse the repository at this point in the history
* upgrade mpt circuit

* Set minimum of 2049 rows for mpt circuit

* Increase max_mpt_rows

* Update mpt_circuit.rs

* add checks for mpt rows

---------

Co-authored-by: Mason Liang <[email protected]>
  • Loading branch information
lispc and Mason Liang authored Sep 27, 2023
1 parent 21f887d commit 428d8fc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 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.

4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ 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.
/// Max amount of rows that the MptCircuit 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.
Expand Down Expand Up @@ -136,7 +136,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: 2000,
max_mpt_rows: 1000,
max_mpt_rows: 2049,
max_exp_steps: 1000,
max_bytecode: 512,
max_evm_rows: 0,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TEST_MOCK_RANDOMNESS: u64 = 0x100;
/// MAX_TXS
const MAX_TXS: usize = 4;
/// MAX_CALLDATA
const MAX_CALLDATA: usize = 512;
const MAX_CALLDATA: usize = 2049;
/// MAX_RLP_ROWS
const MAX_RLP_ROWS: usize = 1000;
/// MAX_RWS
Expand Down
2 changes: 1 addition & 1 deletion testool/src/statetest/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ fn get_params_for_super_circuit_test() -> CircuitsParams {
max_calldata: MAX_CALLDATA,
max_rws: 256,
max_copy_rows: 256,
max_mpt_rows: 256,
max_mpt_rows: 2049,
max_exp_steps: 256,
max_bytecode: 512,
max_evm_rows: 0,
Expand Down
14 changes: 13 additions & 1 deletion zkevm-circuits/src/mpt_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ impl SubCircuit<Fr> for MptCircuit<Fr> {
type Config = MptCircuitConfig<Fr>;

fn new_from_block(block: &witness::Block<Fr>) -> Self {
// 0 means "dynamic"
if block.circuits_params.max_mpt_rows != 0 {
// Fixed byte-bit-index lookup needs 2049 rows.
if block.circuits_params.max_mpt_rows < 2049 {
panic!(
"invalid max_mpt_rows {}",
block.circuits_params.max_mpt_rows
);
}
}
let traces: Vec<_> = block
.mpt_updates
.proof_types
Expand All @@ -112,8 +122,10 @@ impl SubCircuit<Fr> for MptCircuit<Fr> {
(
// For an empty storage proof, we may need to lookup the canonical representations of
// three different keys. Each lookup requires 32 rows.
// The key bit lookup within the mpt circuit requires a minimum of 8 * 256 rows. The +1
// comes from the fact that the mpt circuit starts assigning at offset = 1.
3 * 32 * block.mpt_updates.len(),
block.circuits_params.max_mpt_rows,
block.circuits_params.max_mpt_rows.max(8 * 256 + 1),
)
}

Expand Down
12 changes: 6 additions & 6 deletions zkevm-circuits/src/super_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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_mpt_rows: 2049,
max_poseidon_rows: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
Expand Down Expand Up @@ -267,7 +267,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: 1024,
max_mpt_rows: 2049,
max_poseidon_rows: 1024,
max_bytecode: 512,
max_keccak_rows: 0,
Expand Down Expand Up @@ -298,7 +298,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_mpt_rows: 2049,
max_poseidon_rows: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
Expand Down Expand Up @@ -328,7 +328,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_mpt_rows: 2049,
max_poseidon_rows: 512,
max_keccak_rows: 0,
max_inner_blocks: MAX_INNER_BLOCKS,
Expand Down Expand Up @@ -356,7 +356,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_mpt_rows: 2049,
max_poseidon_rows: 512,
max_exp_steps: 256,
max_bytecode: 512,
Expand All @@ -382,7 +382,7 @@ fn precomiple_super_circuits_params(max_txs: usize, max_calldata: usize) -> Circ
max_rws: MAX_RWS,
max_copy_rows: MAX_COPY_ROWS,
max_bytecode: 16384,
max_mpt_rows: 2048,
max_mpt_rows: 2049,
max_poseidon_rows: 8192,
max_evm_rows: 0,
// modexp ref this to decide its ability, we
Expand Down
2 changes: 1 addition & 1 deletion zktrie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
mpt-circuits = { package = "halo2-mpt-circuits", git = "https://github.com/scroll-tech/mpt-circuit.git", tag = "v0.6.5" }
mpt-circuits = { package = "halo2-mpt-circuits", git = "https://github.com/scroll-tech/mpt-circuit.git", tag = "v0.7.0" }
zktrie = { git = "https://github.com/scroll-tech/zktrie.git", branch = "v0.6" }
hash-circuit = { package = "poseidon-circuit", git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "scroll-dev-0901"}
eth-types = { path = "../eth-types" }
Expand Down

0 comments on commit 428d8fc

Please sign in to comment.