Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit a29cbaa

Browse files
lispcsilathdiiricemelon
authored
v0.7.2: dedup same bytecode row usage in ccc; upgrade to latest zkevm-circuits (#240)
* adjust row limit * towards v0.7.1 * done * minor * minor * fix * fix * Update to `v0.7.2`. * Update * Update prover/src/zkevm/capacity_checker.rs Co-authored-by: Haichen Shen <shenhaichen@gmail.com> * Delete useless import. --------- Co-authored-by: Steven Gu <asongala@163.com> Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
1 parent f8b9de7 commit a29cbaa

File tree

9 files changed

+119
-118
lines changed

9 files changed

+119
-118
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ maingate = { git = "https://github.com/scroll-tech/halo2wrong", branch = "halo2-
1717
[patch."https://github.com/privacy-scaling-explorations/halo2curves.git"]
1818
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
1919

20-
[patch."https://github.com/scroll-tech/snark-verifier"]
21-
snark-verifier = { git = "https://github.com/scroll-tech//snark-verifier", tag = "v0.1.1" }
22-
snark-verifier-sdk = { git = "https://github.com/scroll-tech//snark-verifier", tag = "v0.1.1" }
23-
2420
[profile.test]
2521
opt-level = 3
2622
debug-assertions = true

bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bin"
3-
version = "0.6.4"
3+
version = "0.7.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

prover/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[package]
22
name = "prover"
3-
version = "0.6.4"
3+
version = "0.7.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
99
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
1010

11-
aggregator = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5" }
12-
bus-mapping = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5" }
13-
eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5" }
14-
zkevm-circuits = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5", default-features = false, features = ["test","scroll","scroll-trace","shanghai"] }
15-
mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5" }
16-
mock = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.6.5" }
11+
aggregator = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2" }
12+
bus-mapping = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2" }
13+
eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2" }
14+
zkevm-circuits = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2", default-features = false, features = ["test","scroll","scroll-trace","shanghai"] }
15+
mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2" }
16+
mock = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.7.2" }
1717

1818
snark-verifier = { git = "https://github.com/scroll-tech/snark-verifier", tag = "v0.1.2" }
1919
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", tag = "v0.1.2" }

prover/src/zkevm/capacity_checker.rs

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
use std::collections::HashMap;
2+
3+
use super::circuit::{
4+
MAX_BYTECODE, MAX_CALLDATA, MAX_EXP_STEPS, MAX_KECCAK_ROWS, MAX_MPT_ROWS, MAX_POSEIDON_ROWS,
5+
MAX_RWS, MAX_VERTICLE_ROWS,
6+
};
7+
18
use super::circuit::{
29
block_traces_to_witness_block_with_updated_state, calculate_row_usage_of_witness_block,
310
fill_zktrie_state_from_proofs,
411
};
12+
use eth_types::H256;
513
use itertools::Itertools;
614
use mpt_zktrie::state::ZktrieState;
715
use serde_derive::{Deserialize, Serialize};
@@ -38,41 +46,21 @@ impl RowUsage {
3846
}
3947
// We treat 1M as 100%
4048
pub fn normalize(&self) -> Self {
41-
/*
42-
const MAX_TXS: usize = 100;
43-
const MAX_INNER_BLOCKS: usize = 100;
44-
const MAX_EXP_STEPS: usize = 10_000;
45-
const MAX_CALLDATA: usize = 400_000;
46-
const MAX_BYTECODE: usize = 400_000;
47-
const MAX_MPT_ROWS: usize = 400_000;
48-
const MAX_KECCAK_ROWS: usize = 524_000;
49-
const MAX_RWS: usize = 1_000_000;
50-
const MAX_PRECOMPILE_EC_ADD: usize = 50;
51-
const MAX_PRECOMPILE_EC_MUL: usize = 50;
52-
const MAX_PRECOMPILE_EC_PAIRING: usize = 2;
53-
*/
54-
use super::circuit::{
55-
MAX_BYTECODE, MAX_CALLDATA, MAX_EXP_STEPS, MAX_KECCAK_ROWS, MAX_MPT_ROWS, MAX_RWS,
56-
};
57-
// 14 in total
58-
// "evm", "state", "bytecode", "copy",
59-
// "keccak", "tx", "rlp", "exp", "modexp", "pi",
60-
// "poseidon", "sig", "ecc", "mpt",
6149
let real_available_rows = [
62-
MAX_RWS,
63-
MAX_RWS,
64-
MAX_BYTECODE,
65-
MAX_RWS,
66-
MAX_KECCAK_ROWS,
67-
MAX_CALLDATA,
68-
MAX_CALLDATA,
50+
MAX_RWS, // evm
51+
MAX_RWS, // state
52+
MAX_BYTECODE, // bytecode
53+
MAX_RWS, // copy
54+
MAX_KECCAK_ROWS, // keccak
55+
MAX_CALLDATA, // tx
56+
MAX_CALLDATA, // rlp
6957
7 * MAX_EXP_STEPS, // exp
70-
MAX_KECCAK_ROWS,
71-
MAX_RWS,
72-
MAX_MPT_ROWS, // poseidon
73-
(1 << 20) - 256, // sig
74-
(1 << 20) - 256, // FIXME: pairing may be limit to 1, fix later
75-
MAX_MPT_ROWS,
58+
MAX_KECCAK_ROWS, // modexp
59+
MAX_RWS, // pi
60+
MAX_POSEIDON_ROWS, // poseidon
61+
MAX_VERTICLE_ROWS, // sig
62+
MAX_VERTICLE_ROWS, // ecc
63+
MAX_MPT_ROWS, // mpt
7664
]
7765
.map(|x| (x as f32 * 0.95) as usize);
7866
let details = self
@@ -131,6 +119,8 @@ pub struct CircuitCapacityChecker {
131119
pub acc_row_usage: RowUsage,
132120
pub row_usages: Vec<RowUsage>,
133121
pub state: Option<ZktrieState>,
122+
// poseidon codehash to code len
123+
pub codelen: HashMap<H256, usize>,
134124
}
135125

136126
// Currently TxTrace is same as BlockTrace, with "transactions" and "executionResults" should be of
@@ -151,27 +141,42 @@ impl CircuitCapacityChecker {
151141
row_usages: Vec::new(),
152142
state: None,
153143
light_mode: true,
144+
codelen: HashMap::new(),
154145
}
155146
}
156147
pub fn reset(&mut self) {
157148
self.state = None;
158149
self.acc_row_usage = RowUsage::new();
159150
self.row_usages = Vec::new();
151+
self.codelen = HashMap::new();
160152
}
161153
pub fn estimate_circuit_capacity(
162154
&mut self,
163155
txs: &[TxTrace],
164-
) -> Result<(RowUsage, RowUsage), anyhow::Error> {
156+
) -> Result<RowUsage, anyhow::Error> {
165157
assert!(!txs.is_empty());
166158
if self.state.is_none() {
167159
self.state = Some(ZktrieState::construct(txs[0].storage_trace.root_before));
168160
}
169161
let traces = txs;
170162
let state = self.state.as_mut().unwrap();
171163
fill_zktrie_state_from_proofs(state, traces, self.light_mode)?;
172-
let witness_block =
164+
let (witness_block, codedb) =
173165
block_traces_to_witness_block_with_updated_state(traces, state, self.light_mode)?;
174-
let rows = calculate_row_usage_of_witness_block(&witness_block)?;
166+
let mut rows = calculate_row_usage_of_witness_block(&witness_block)?;
167+
168+
// Dedup bytecode row usage for bytecode circuit / poseidon circuit
169+
for (hash, bytes) in &codedb.0 {
170+
if self.codelen.contains_key(hash) {
171+
assert_eq!(rows[2].name, "bytecode");
172+
rows[2].row_num_real -= bytes.len() + 1;
173+
assert_eq!(rows[10].name, "poseidon");
174+
rows[10].row_num_real -= bytes.len() / (31 * 2) * 9;
175+
} else {
176+
self.codelen.insert(*hash, bytes.len());
177+
}
178+
}
179+
175180
let row_usage_details: Vec<SubCircuitRowUsage> = rows
176181
.into_iter()
177182
.map(|x| SubCircuitRowUsage {
@@ -182,6 +187,6 @@ impl CircuitCapacityChecker {
182187
let tx_row_usage = RowUsage::from_row_usage_details(row_usage_details);
183188
self.row_usages.push(tx_row_usage.clone());
184189
self.acc_row_usage.add(&tx_row_usage);
185-
Ok((self.acc_row_usage.normalize(), tx_row_usage.normalize()))
190+
Ok(self.acc_row_usage.normalize())
186191
}
187192
}

prover/src/zkevm/circuit.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,12 @@ pub use self::builder::{
1515
block_traces_to_witness_block_with_updated_state, calculate_row_usage_of_trace,
1616
calculate_row_usage_of_witness_block, check_batch_capacity, fill_zktrie_state_from_proofs,
1717
normalize_withdraw_proof, storage_trace_to_padding_witness_block, WitnessBlock,
18-
SUB_CIRCUIT_NAMES,
1918
};
20-
21-
// TODO: more smart row capacity checking rather than max_of(row_usage_details) > 1<<20 - 256
22-
// Need to compare with real row nums like MAX_MPT_ROWS/MAX_KECCAK_ROWS etc.
23-
////// params for degree = 20 ////////////
24-
pub const MAX_TXS: usize = 100;
25-
pub const MAX_INNER_BLOCKS: usize = 100;
26-
pub const MAX_EXP_STEPS: usize = 10_000;
27-
pub const MAX_CALLDATA: usize = 400_000;
28-
pub const MAX_BYTECODE: usize = 400_000;
29-
pub const MAX_MPT_ROWS: usize = 400_000;
30-
pub const MAX_KECCAK_ROWS: usize = 524_000;
31-
pub const MAX_RWS: usize = 1_000_000;
32-
pub const MAX_PRECOMPILE_EC_ADD: usize = 50;
33-
pub const MAX_PRECOMPILE_EC_MUL: usize = 50;
34-
pub const MAX_PRECOMPILE_EC_PAIRING: usize = 2;
19+
pub use builder::{
20+
MAX_BYTECODE, MAX_CALLDATA, MAX_EXP_STEPS, MAX_INNER_BLOCKS, MAX_KECCAK_ROWS, MAX_MPT_ROWS,
21+
MAX_POSEIDON_ROWS, MAX_PRECOMPILE_EC_ADD, MAX_PRECOMPILE_EC_MUL, MAX_PRECOMPILE_EC_PAIRING,
22+
MAX_RWS, MAX_TXS, MAX_VERTICLE_ROWS,
23+
};
3524

3625
static CHAIN_ID: Lazy<u64> = Lazy::new(|| read_env_var("CHAIN_ID", 53077));
3726
static AUTO_TRUNCATE: Lazy<bool> = Lazy::new(|| read_env_var("AUTO_TRUNCATE", false));

0 commit comments

Comments
 (0)