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

Commit 774d5ed

Browse files
authored
refactor: disable "test" "mock" features in prover side to get rid of Go (#1347)
* remove some used functions in prover * change state root to H256 * make external-tracer as dev-deps * clean deps * clean deps * clean deps * clean deps * fix deps * fix deps * fmt
1 parent e3c2e63 commit 774d5ed

25 files changed

+116
-158
lines changed

aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license.workspace = true
88

99
eth-types = { path = "../eth-types" }
1010
gadgets = { path = "../gadgets" }
11-
zkevm-circuits = { path = "../zkevm-circuits" }
11+
zkevm-circuits = { path = "../zkevm-circuits", default-features=false, features = ["debug-annotations", "parallel_syn"] }
1212

1313
ark-std.workspace = true
1414
ctor.workspace = true

aggregator/src/chunk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ impl ChunkInfo {
156156
.ctxs
157157
.last_key_value()
158158
.map(|(_, b_ctx)| b_ctx.state_root)
159-
.unwrap_or(H256(block.prev_state_root.to_be_bytes()));
159+
.unwrap_or(block.prev_state_root);
160160

161161
Self {
162162
chain_id: block.chain_id,
163-
prev_state_root: H256(block.prev_state_root.to_be_bytes()),
163+
prev_state_root: block.prev_state_root,
164164
post_state_root,
165165
withdraw_root: H256(block.withdraw_root.to_be_bytes()),
166166
data_hash,

bus-mapping/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ license.workspace = true
66

77
[dependencies]
88
eth-types = { path = "../eth-types" }
9-
external-tracer = { path="../external-tracer" }
109
gadgets = { path = "../gadgets" }
1110
mpt-zktrie = {path = "../zktrie"}
11+
external-tracer = { path="../external-tracer", optional = true }
1212
mock = { path = "../mock", optional = true }
1313

1414
ethers-core.workspace = true
@@ -30,13 +30,15 @@ strum_macros.workspace = true
3030
revm-precompile.workspace = true
3131

3232
[dev-dependencies]
33+
mock = { path = "../mock" }
34+
external-tracer = { path="../external-tracer" }
35+
3336
hex.workspace = true
3437
pretty_assertions.workspace = true
3538
tokio.workspace = true
3639
url.workspace = true
3740
ctor.workspace = true
3841
env_logger.workspace = true
39-
mock = { path = "../mock" }
4042
rand.workspace = true
4143
rayon.workspace = true
4244

@@ -54,4 +56,4 @@ rpc-legacy-tracer = []
5456
# For the trace obtained from erigon node, refund field is missed
5557
# and must be rebuild
5658
fix-refund = ["rpc-legacy-tracer"]
57-
retrace-tx = []
59+
retrace-tx = ["scroll", "external-tracer"]

bus-mapping/src/circuit_input_builder/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
operation::{OperationContainer, RWCounter},
1010
Error,
1111
};
12-
use eth_types::{Address, ToWord, Word, H256};
12+
use eth_types::{Address, Word, H256};
1313
use std::collections::{BTreeMap, HashMap};
1414

1515
/// Context of a [`Block`] which can mutate in a [`Transaction`].
@@ -155,7 +155,7 @@ pub struct Blocks {
155155
/// Blocks inside this chunk
156156
pub blocks: BTreeMap<u64, Block>,
157157
/// State root of the previous block
158-
pub prev_state_root: Word,
158+
pub prev_state_root: H256,
159159
/// Withdraw root
160160
pub withdraw_root: Word,
161161
/// Withdraw roof of the previous block
@@ -237,10 +237,10 @@ impl Blocks {
237237
}
238238

239239
/// State root after all blocks in this chunk
240-
pub fn end_state_root(&self) -> Word {
240+
pub fn end_state_root(&self) -> H256 {
241241
self.blocks
242242
.last_key_value()
243-
.map(|(_, blk)| blk.state_root.to_word())
243+
.map(|(_, blk)| blk.state_root)
244244
.unwrap_or(self.prev_state_root)
245245
}
246246

bus-mapping/src/circuit_input_builder/builder_client.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use eth_types::{
66
Address, EthBlock, GethExecTrace, ToWord, Word, H256, KECCAK_CODE_HASH_EMPTY,
77
};
88
use ethers_providers::JsonRpcClient;
9-
use external_tracer::TraceConfig;
109
use hex::decode_to_slice;
1110

1211
use super::{AccessSet, Block, Blocks, CircuitInputBuilder, CircuitsParams};
@@ -331,6 +330,8 @@ impl<P: JsonRpcClient> BuilderClient<P> {
331330
}
332331

333332
/// Perform all the steps to generate the circuit inputs
333+
#[allow(unused_mut)]
334+
#[allow(unused_variables)]
334335
pub async fn gen_inputs(
335336
&self,
336337
block_num: u64,
@@ -344,13 +345,16 @@ impl<P: JsonRpcClient> BuilderClient<P> {
344345
let (mut eth_block, mut geth_traces, history_hashes, prev_state_root) =
345346
self.get_block(block_num).await?;
346347

347-
let builder = if cfg!(feature = "retrace-tx") {
348+
#[cfg(feature = "retrace-tx")]
349+
let builder = {
348350
let trace_config = self
349351
.get_trace_config(&eth_block, geth_traces.iter(), false)
350352
.await?;
351353

352354
self.trace_to_builder(&eth_block, &trace_config)?
353-
} else {
355+
};
356+
#[cfg(not(feature = "retrace-tx"))]
357+
let builder = {
354358
let (proofs, codes) = self.get_pre_state(geth_traces.iter())?;
355359
let proofs = self.complete_prestate(&eth_block, proofs).await?;
356360
let (state_db, code_db) = Self::build_state_code_db(proofs, codes);
@@ -424,13 +428,16 @@ impl<P: JsonRpcClient> BuilderClient<P> {
424428

425429
eth_block.transactions = vec![tx.clone()];
426430

427-
let builder = if cfg!(feature = "retrace-tx") {
431+
#[cfg(feature = "retrace-tx")]
432+
let builder = {
428433
let trace_config = self
429434
.get_trace_config(&eth_block, iter::once(&geth_trace), true)
430435
.await?;
431436

432437
self.trace_to_builder(&eth_block, &trace_config)?
433-
} else {
438+
};
439+
#[cfg(not(feature = "retrace-tx"))]
440+
let builder = {
434441
let (proofs, codes) = self.get_pre_state(iter::once(&geth_trace))?;
435442
let proofs = self.complete_prestate(&eth_block, proofs).await?;
436443
let (state_db, code_db) = Self::build_state_code_db(proofs, codes);
@@ -447,12 +454,13 @@ impl<P: JsonRpcClient> BuilderClient<P> {
447454
Ok(builder)
448455
}
449456

457+
#[cfg(feature = "retrace-tx")]
450458
async fn get_trace_config(
451459
&self,
452460
eth_block: &EthBlock,
453461
geth_traces: impl Iterator<Item = &GethExecTrace>,
454462
complete_prestate: bool,
455-
) -> Result<TraceConfig, Error> {
463+
) -> Result<external_tracer::TraceConfig, Error> {
456464
let (proofs, codes) = self.get_pre_state(geth_traces)?;
457465
let proofs = if complete_prestate {
458466
self.complete_prestate(eth_block, proofs).await?
@@ -466,7 +474,7 @@ impl<P: JsonRpcClient> BuilderClient<P> {
466474
//let difficulty = eth_block.difficulty;
467475
let difficulty = Word::zero();
468476

469-
Ok(TraceConfig {
477+
Ok(external_tracer::TraceConfig {
470478
chain_id: self.chain_id,
471479
history_hashes: vec![eth_block.parent_hash.to_word()],
472480
block_constants: BlockConstants {
@@ -510,11 +518,11 @@ impl<P: JsonRpcClient> BuilderClient<P> {
510518
})
511519
}
512520

513-
#[cfg(feature = "scroll")]
521+
#[cfg(feature = "retrace-tx")]
514522
fn trace_to_builder(
515523
&self,
516524
_eth_block: &EthBlock,
517-
trace_config: &TraceConfig,
525+
trace_config: &external_tracer::TraceConfig,
518526
) -> Result<CircuitInputBuilder, Error> {
519527
let block_trace = external_tracer::l2trace(trace_config)?;
520528
let mut builder =
@@ -525,7 +533,8 @@ impl<P: JsonRpcClient> BuilderClient<P> {
525533
Ok(builder)
526534
}
527535

528-
#[cfg(not(feature = "scroll"))]
536+
/*
537+
// Seems useless?
529538
fn trace_to_builder(
530539
&self,
531540
eth_block: &EthBlock,
@@ -545,4 +554,5 @@ impl<P: JsonRpcClient> BuilderClient<P> {
545554
builder.handle_block(eth_block, &geth_traces)?;
546555
Ok(builder)
547556
}
557+
*/
548558
}

bus-mapping/src/circuit_input_builder/l2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl CircuitInputBuilder {
172172
}
173173

174174
let mut builder_block = circuit_input_builder::Blocks::init(chain_id, circuits_params);
175-
builder_block.prev_state_root = old_root.to_word();
175+
builder_block.prev_state_root = old_root;
176176
builder_block.start_l1_queue_index = l2_trace.start_l1_queue_index;
177177
let mut builder = Self {
178178
sdb,

bus-mapping/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl BlockData {
4040
let mut block = Blocks::init(self.chain_id, Default::default());
4141
block.blocks.insert(header.number.as_u64(), header);
4242
// FIXME: better fetch a real state root instead of a mock one
43-
block.prev_state_root = MOCK_OLD_STATE_ROOT.into();
43+
block.prev_state_root = H256::from_low_u64_be(MOCK_OLD_STATE_ROOT);
4444
block.circuits_params = self.circuits_params;
4545
CircuitInputBuilder::new(self.sdb.clone(), self.code_db.clone(), &block)
4646
}

prover/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license.workspace = true
88
halo2_proofs.workspace = true
99

1010
aggregator = { path = "../aggregator" }
11-
bus-mapping = { path = "../bus-mapping" }
11+
bus-mapping = { path = "../bus-mapping", default-features = false }
1212
eth-types = { path = "../eth-types" }
1313
mpt-zktrie = { path = "../zktrie" }
1414
zkevm-circuits = { path = "../zkevm-circuits", default-features = false }

prover/src/io.rs

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use anyhow;
22
use halo2_proofs::{
3-
halo2curves::bn256::{Fq, Fr, G1Affine},
3+
halo2curves::bn256::{Fr, G1Affine},
44
plonk::{Circuit, VerifyingKey},
55
SerdeFormat,
66
};
7-
use num_bigint::BigUint;
87
use snark_verifier::util::arithmetic::PrimeField;
98
use snark_verifier_sdk::Snark;
109
use std::{
@@ -93,53 +92,6 @@ pub fn deserialize_vk<C: Circuit<Fr>>(raw_vk: &[u8]) -> VerifyingKey<G1Affine> {
9392
.unwrap()
9493
}
9594

96-
pub fn write_verify_circuit_vk(folder: &mut PathBuf, verify_circuit_vk: &[u8]) {
97-
folder.push("verify_circuit.vkey");
98-
let mut fd = std::fs::File::create(folder.as_path()).unwrap();
99-
folder.pop();
100-
fd.write_all(verify_circuit_vk).unwrap()
101-
}
102-
103-
pub fn field_to_bn(f: &Fq) -> BigUint {
104-
BigUint::from_bytes_le(&f.to_bytes())
105-
}
106-
107-
pub fn serialize_commitments(buf: &[Vec<G1Affine>]) -> Vec<u8> {
108-
let mut result = Vec::<u8>::new();
109-
let mut fd = Cursor::new(&mut result);
110-
let to_bytes_be = |x: &BigUint| {
111-
let mut buf = x.to_bytes_le();
112-
buf.resize(32, 0u8);
113-
buf.reverse();
114-
buf
115-
};
116-
for v in buf {
117-
for commitment in v {
118-
let x = field_to_bn(&commitment.x);
119-
let y = field_to_bn(&commitment.y);
120-
let be = to_bytes_be(&x)
121-
.into_iter()
122-
.chain(to_bytes_be(&y).into_iter())
123-
.collect::<Vec<_>>();
124-
fd.write_all(&be).unwrap()
125-
}
126-
}
127-
result
128-
}
129-
130-
pub fn serialize_verify_circuit_final_pair(pair: &(G1Affine, G1Affine, Vec<Fr>)) -> Vec<u8> {
131-
let mut result = Vec::<u8>::new();
132-
let mut fd = Cursor::new(&mut result);
133-
fd.write_all(&pair.0.x.to_bytes()).unwrap();
134-
fd.write_all(&pair.0.y.to_bytes()).unwrap();
135-
fd.write_all(&pair.1.x.to_bytes()).unwrap();
136-
fd.write_all(&pair.1.y.to_bytes()).unwrap();
137-
pair.2.iter().for_each(|scalar| {
138-
fd.write_all(&scalar.to_bytes()).unwrap();
139-
});
140-
result
141-
}
142-
14395
pub fn write_snark(file_path: &str, snark: &Snark) {
14496
log::debug!("write_snark to {file_path}");
14597
let mut fd = std::fs::File::create(file_path).unwrap();
@@ -175,15 +127,3 @@ pub fn load_instances(buf: &[u8]) -> Vec<Vec<Vec<Fr>>> {
175127
})
176128
.collect()
177129
}
178-
179-
pub fn load_instances_flat(buf: &[u8]) -> Vec<Vec<Vec<Fr>>> {
180-
let mut ret = vec![];
181-
let cursor = &mut std::io::Cursor::new(buf);
182-
let mut scalar_bytes = <Fr as PrimeField>::Repr::default();
183-
184-
while cursor.read_exact(scalar_bytes.as_mut()).is_ok() {
185-
ret.push(Fr::from_bytes(&scalar_bytes).unwrap());
186-
}
187-
188-
vec![vec![ret]]
189-
}

prover/src/zkevm/capacity_checker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bus_mapping::circuit_input_builder::{self, CircuitInputBuilder};
33
use eth_types::{
44
l2_types::BlockTrace,
55
state_db::{CodeDB, StateDB},
6-
ToWord, H256,
6+
H256,
77
};
88
use halo2_proofs::halo2curves::bn256::Fr;
99
use itertools::Itertools;
@@ -155,8 +155,7 @@ impl CircuitCapacityChecker {
155155
.as_ref()
156156
.map(|state| state.root())
157157
.map(|root| H256(*root))
158-
.unwrap_or(trace.header.state_root)
159-
.to_word();
158+
.unwrap_or(trace.header.state_root);
160159
// notice the trace has included all code required for builidng witness block,
161160
// so we do not need to pick them from previous one, but we still keep the
162161
// old codedb in previous run for some dedup work

zkevm-circuits/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ halo2_proofs.workspace = true
1111
num.workspace = true
1212
sha3.workspace = true
1313
array-init = "2.0.0"
14-
bus-mapping = { path = "../bus-mapping" }
14+
bus-mapping = { path = "../bus-mapping", default-features=false }
1515
either = "1.9"
1616
eth-types = { path = "../eth-types" }
1717
ff.workspace = true
1818
gadgets = { path = "../gadgets" }
1919
ethers-core.workspace = true
20-
ethers-signers = { workspace = true, optional = true }
20+
ethers-signers = { workspace = true }
2121
halo2-base.workspace = true
2222
halo2-ecc.workspace = true
2323
mock = { path = "../mock", optional = true }
@@ -55,7 +55,7 @@ paste = "1.0"
5555

5656
[features]
5757
default = ["test", "test-circuits", "debug-annotations", "parallel_syn"]
58-
test = ["ethers-signers", "mock", "bus-mapping/test"]
58+
test = ["mock", "bus-mapping/test"]
5959

6060
scroll = ["bus-mapping/scroll", "eth-types/scroll", "mock?/scroll", "zktrie", "poseidon-codehash"]
6161

zkevm-circuits/src/evm_circuit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ impl<F: Field> EvmCircuit<F> {
278278
num_rows += 1;
279279
num_rows
280280
}
281+
282+
pub fn get_test_cicuit_from_block(block: Block) -> Self {
283+
let fixed_table_tags = detect_fixed_table_tags(&block);
284+
EvmCircuit::<F>::new_dev(block, fixed_table_tags)
285+
}
281286
}
282287

283288
const FIXED_TABLE_ROWS_NO_BITWISE: usize = 3659;

zkevm-circuits/src/evm_circuit/test.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,3 @@ pub(crate) fn rand_bytes_array<const N: usize>() -> [u8; N] {
2828
pub(crate) fn rand_word() -> Word {
2929
Word::from_big_endian(&rand_bytes_array::<32>())
3030
}
31-
32-
impl<F: Field> EvmCircuit<F> {
33-
pub fn get_test_cicuit_from_block(block: Block) -> Self {
34-
let fixed_table_tags = detect_fixed_table_tags(&block);
35-
EvmCircuit::<F>::new_dev(block, fixed_table_tags)
36-
}
37-
}

zkevm-circuits/src/mpt_circuit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl SubCircuitConfig<Fr> for MptCircuitConfig<Fr> {
8686
}
8787
}
8888

89-
#[cfg(any(feature = "test", test))]
9089
impl SubCircuit<Fr> for MptCircuit<Fr> {
9190
type Config = MptCircuitConfig<Fr>;
9291

zkevm-circuits/src/pi_circuit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,8 @@ impl<F: Field> PiCircuit<F> {
17771777
block: &Block,
17781778
) -> Self {
17791779
let chain_id = block.chain_id;
1780-
let prev_state_root_in_trie = H256(block.mpt_updates.old_root().to_be_bytes());
1781-
let prev_state_root_in_header = H256(block.prev_state_root.to_be_bytes());
1780+
let prev_state_root_in_trie = block.mpt_updates.old_root();
1781+
let prev_state_root_in_header = block.prev_state_root;
17821782
assert_eq!(prev_state_root_in_trie, prev_state_root_in_header);
17831783
let public_data = PublicData {
17841784
max_txs,

zkevm-circuits/src/poseidon_circuit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ impl<F: Field> SubCircuitConfig<F> for PoseidonCircuitConfig<F> {
5252
}
5353
}
5454

55-
#[cfg(any(feature = "test", test))]
5655
impl<F: Field> SubCircuit<F> for PoseidonCircuit<F> {
5756
type Config = PoseidonCircuitConfig<F>;
5857

0 commit comments

Comments
 (0)