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

Commit 0403a04

Browse files
Rm deadcode of EVM circuit (#1525)
### Description - Removed #[allow(dead_code)] and `#![allow(unused_imports)]`. - Removed most of the dead code. Kept a few with the "_" initial name. - Reorganize dev modules and feature flags for "zkevm-circuits" crate. - ~~"test" flag is only used when test utils are shared within "zkevm-circuits"~~ "test" flag is gone. - "test-util" flag is used when utils are shared with testool crate. - "test-circuits" flag is reserved for test circuits that are shared with integration tests. ### Issue Link ### Type of change - [x] New feature (non-breaking change which adds functionality) ### Rationale These are the reason I keep a method: - The method is a sensible API and is tested. Although it is unused but it makes sense to keep it. The `remainder` method of the Constant Division Gadget is such an example. - Variants in Enums. We use the `match` macro for them so it is important we don't miss any variant. It makes sense to keep them even when we don't use them. - Work in progress and recent works. Cell manager and _error_depth are examples. I remove a method or a gadget for these reasons. - If it has been there for a long time but never used. - Default removing them to question us hard if the gadget really sparks joy. batched_is_zero and binary number gadgets are such cases. ### How Has This Been Tested? ``` cargo build --all-features cargo test // just for build, without running the full tests ```
1 parent 6bcb1d0 commit 0403a04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+325
-1334
lines changed

.github/workflows/test-features.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
- zkevm-circuits
3636
feature:
3737
- default
38-
- test
3938
- test-circuits
39+
- test-util
4040
- warn-unimplemented
4141
steps:
4242
- uses: actions/checkout@v2

circuit-benchmarks/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
99
[dependencies]
1010
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
1111
ark-std = { version = "0.3", features = ["print-trace"] }
12-
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"]}
12+
zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] }
1313
bus-mapping = { path = "../bus-mapping", features = ["test"] }
1414
rand_xorshift = "0.3"
1515
rand = "0.8"

integration-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde_json = "1.0.66"
1313
serde = { version = "1.0.130", features = ["derive"] }
1414
bus-mapping = { path = "../bus-mapping" , features = ["test"] }
1515
eth-types = { path = "../eth-types" }
16-
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"] }
16+
zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] }
1717
tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] }
1818
url = "2.2.2"
1919
pretty_assertions = "1.0.0"

testool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ strum_macros = "0.24"
2929
thiserror = "1.0"
3030
toml = "0.5"
3131
yaml-rust = "0.4.5"
32-
zkevm-circuits = { path="../zkevm-circuits", features=["test"] }
32+
zkevm-circuits = { path="../zkevm-circuits", features=["test-util"] }
3333
rand_chacha = "0.3"
3434
rand = "0.8"
3535
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }

zkevm-circuits/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ serde_json = "1.0.78"
4949

5050
[features]
5151
default = []
52-
test = ["ethers-signers", "mock", "bus-mapping/test"]
52+
# We export some test circuits for other crates to consume
5353
test-circuits = []
54+
# Test utilities for testool crate to consume
55+
test-util = ["dep:mock"]
5456
warn-unimplemented = ["eth-types/warn-unimplemented"]
5557
stats = ["warn-unimplemented", "dep:cli-table"]
5658

zkevm-circuits/src/bytecode_circuit.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
pub mod bytecode_unroller;
55
/// Bytecode circuit
66
pub mod circuit;
7-
pub(crate) mod param;
87

9-
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
8+
#[cfg(any(test, feature = "test-circuits"))]
109
mod dev;
1110
/// Bytecode circuit tester
12-
#[cfg(any(feature = "test", test))]
11+
#[cfg(test)]
1312
mod test;
14-
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
13+
#[cfg(feature = "test-circuits")]
1514
pub use dev::BytecodeCircuit as TestBytecodeCircuit;

zkevm-circuits/src/bytecode_circuit/circuit.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ use halo2_proofs::{
2525
use log::trace;
2626
use std::vec;
2727

28-
use super::{
29-
bytecode_unroller::{unroll, UnrolledBytecode},
30-
param::PUSH_TABLE_WIDTH,
31-
};
28+
use super::bytecode_unroller::{unroll, UnrolledBytecode};
29+
30+
const PUSH_TABLE_WIDTH: usize = 2;
3231

3332
#[derive(Debug, Clone, Default)]
3433
/// Row for assignment

zkevm-circuits/src/bytecode_circuit/param.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

zkevm-circuits/src/bytecode_circuit/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#![allow(unused_imports)]
21
use crate::{
32
bytecode_circuit::{bytecode_unroller::*, circuit::BytecodeCircuit},
43
table::BytecodeFieldTag,
5-
util::{is_push, keccak, unusable_rows, Challenges, SubCircuit},
4+
util::{is_push, keccak, unusable_rows, SubCircuit},
65
};
76
use bus_mapping::evm::OpcodeId;
87
use eth_types::{Bytecode, Field, Word};

zkevm-circuits/src/copy_circuit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! etc.
44
pub(crate) mod util;
55

6-
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
6+
#[cfg(any(test, feature = "test-circuits"))]
77
mod dev;
88
#[cfg(test)]
99
mod test;
10-
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
10+
#[cfg(feature = "test-circuits")]
1111
pub use dev::CopyCircuit as TestCopyCircuit;
1212

1313
use bus_mapping::{

zkevm-circuits/src/evm_circuit.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub mod step;
1212
pub mod table;
1313
pub(crate) mod util;
1414

15-
#[cfg(any(feature = "test", test))]
15+
#[cfg(test)]
1616
pub(crate) mod test;
1717
use self::step::HasExecutionState;
18-
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
18+
#[cfg(feature = "test-circuits")]
1919
pub use self::EvmCircuit as TestEvmCircuit;
2020

2121
pub use crate::witness;
@@ -184,7 +184,8 @@ impl<F: Field> EvmCircuit<F> {
184184
}
185185
}
186186

187-
pub fn new_dev(block: Block<F>, fixed_table_tags: Vec<FixedTableTag>) -> Self {
187+
pub fn get_test_cicuit_from_block(block: Block<F>) -> Self {
188+
let fixed_table_tags = detect_fixed_table_tags(&block);
188189
Self {
189190
block: Some(block),
190191
fixed_table_tags,
@@ -290,7 +291,7 @@ pub(crate) fn detect_fixed_table_tags<F: Field>(block: &Block<F>) -> Vec<FixedTa
290291
.collect()
291292
}
292293

293-
#[cfg(any(feature = "test", test))]
294+
#[cfg(any(feature = "test-util", test))]
294295
pub(crate) mod cached {
295296
use super::*;
296297
use halo2_proofs::halo2curves::bn256::Fr;

zkevm-circuits/src/evm_circuit/execution.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ pub struct ExecutionConfig<F> {
311311
error_oog_code_store: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorOutOfGasCodeStore }>>,
312312
error_invalid_jump: Box<ErrorInvalidJumpGadget<F>>,
313313
error_invalid_opcode: Box<ErrorInvalidOpcodeGadget<F>>,
314+
#[allow(dead_code, reason = "under active development")]
314315
error_depth: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorDepth }>>,
316+
#[allow(dead_code, reason = "under active development")]
315317
error_contract_address_collision:
316318
Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorContractAddressCollision }>>,
317319
error_invalid_creation_code: Box<ErrorInvalidCreationCodeGadget<F>>,

zkevm-circuits/src/evm_circuit/execution/begin_tx.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub(crate) struct BeginTxGadget<F> {
4747
tx_callee_address: WordCell<F>,
4848
call_callee_address: AccountAddress<F>,
4949
tx_is_create: Cell<F>,
50-
tx_value: Word32Cell<F>,
5150
tx_call_data_length: Cell<F>,
5251
tx_call_data_gas_cost: Cell<F>,
5352
tx_call_data_word_length: ConstantDivisionGadget<F, N_BYTES_U64>,
@@ -480,7 +479,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
480479
tx_callee_address,
481480
call_callee_address,
482481
tx_is_create,
483-
tx_value,
484482
tx_call_data_length,
485483
tx_call_data_gas_cost,
486484
tx_call_data_word_length,

zkevm-circuits/src/evm_circuit/execution/create.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ mod test {
689689
use lazy_static::lazy_static;
690690
use mock::{eth, TestContext};
691691

692-
const CALLEE_ADDRESS: Address = Address::repeat_byte(0xff);
693692
lazy_static! {
694693
static ref CALLER_ADDRESS: Address = address!("0x00bbccddee000000000000000000000000002400");
695694
}

zkevm-circuits/src/evm_circuit/execution/end_block.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ pub(crate) struct EndBlockGadget<F> {
2727
max_txs: Cell<F>,
2828
}
2929

30-
const EMPTY_BLOCK_N_RWS: u64 = 0;
31-
3230
impl<F: Field> ExecutionGadget<F> for EndBlockGadget<F> {
3331
const NAME: &'static str = "EndBlock";
3432

zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,6 @@ mod test {
243243
.run();
244244
}
245245

246-
// internal call test
247-
struct Stack {
248-
gas: u64,
249-
value: Word,
250-
cd_offset: u64,
251-
cd_length: u64,
252-
rd_offset: u64,
253-
rd_length: u64,
254-
}
255-
256246
fn callee(code: Bytecode) -> Account {
257247
let code = code.to_vec();
258248
let is_empty = code.is_empty();
@@ -265,53 +255,6 @@ mod test {
265255
}
266256
}
267257

268-
fn caller(opcode: OpcodeId, stack: Stack, caller_is_success: bool) -> Account {
269-
let is_call = opcode == OpcodeId::CALL;
270-
let terminator = if caller_is_success {
271-
OpcodeId::RETURN
272-
} else {
273-
OpcodeId::REVERT
274-
};
275-
276-
// Call twice for testing both cold and warm access
277-
let mut bytecode = bytecode! {
278-
PUSH32(Word::from(stack.rd_length))
279-
PUSH32(Word::from(stack.rd_offset))
280-
PUSH32(Word::from(stack.cd_length))
281-
PUSH32(Word::from(stack.cd_offset))
282-
};
283-
if is_call {
284-
bytecode.push(32, stack.value);
285-
}
286-
bytecode.append(&bytecode! {
287-
PUSH32(Address::repeat_byte(0xff).to_word())
288-
PUSH32(Word::from(stack.gas))
289-
.write_op(opcode)
290-
PUSH32(Word::from(stack.rd_length))
291-
PUSH32(Word::from(stack.rd_offset))
292-
PUSH32(Word::from(stack.cd_length))
293-
PUSH32(Word::from(stack.cd_offset))
294-
});
295-
if is_call {
296-
bytecode.push(32, stack.value);
297-
}
298-
bytecode.append(&bytecode! {
299-
PUSH32(Address::repeat_byte(0xff).to_word())
300-
PUSH32(Word::from(stack.gas))
301-
.write_op(opcode)
302-
PUSH1(0)
303-
PUSH1(0)
304-
.write_op(terminator)
305-
});
306-
307-
Account {
308-
address: Address::repeat_byte(0xfe),
309-
balance: Word::from(10).pow(20.into()),
310-
code: bytecode.to_vec().into(),
311-
..Default::default()
312-
}
313-
}
314-
315258
// jump or jumpi error happen in internal call
316259
fn test_internal_jump_error(is_jumpi: bool) {
317260
let mut caller_bytecode = bytecode! {

zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,7 @@ mod test {
367367
#[derive(Default)]
368368
struct TestingData {
369369
key: U256,
370-
value: U256,
371-
value_prev: U256,
372370
original_value: U256,
373-
is_warm: bool,
374371
gas_cost: u64,
375372
bytecode: Bytecode,
376373
}
@@ -443,10 +440,7 @@ mod test {
443440

444441
Self {
445442
key,
446-
value,
447-
value_prev,
448443
original_value,
449-
is_warm,
450444
gas_cost,
451445
bytecode,
452446
}

zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
},
1818
};
1919
use eth_types::{evm_types::OpcodeId, Field, ToLittleEndian};
20-
use halo2_proofs::plonk::Error;
20+
use halo2_proofs::{circuit::Value, plonk::Error};
2121

2222
#[derive(Clone, Debug)]
2323
pub(crate) struct ErrorOOGStaticMemoryGadget<F> {
@@ -99,6 +99,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGStaticMemoryGadget<F> {
9999
step: &ExecStep,
100100
) -> Result<(), Error> {
101101
let opcode = step.opcode().unwrap();
102+
self.opcode
103+
.assign(region, offset, Value::known(F::from(opcode.as_u64())))?;
102104

103105
// Inputs/Outputs
104106
let address = block.get_rws(step, 0).stack_value();

zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,10 @@ impl<F: Field> ExecutionGadget<F> for ErrorWriteProtectionGadget<F> {
144144
mod test {
145145
use crate::test_util::CircuitTestBuilder;
146146
use eth_types::{
147-
address, bytecode, bytecode::Bytecode, evm_types::OpcodeId, geth_types::Account, Address,
148-
ToWord, Word, U64,
147+
address, bytecode, bytecode::Bytecode, geth_types::Account, Address, ToWord, Word, U64,
149148
};
150149
use mock::TestContext;
151150

152-
// internal call test
153-
struct Stack {
154-
gas: u64,
155-
value: Word,
156-
cd_offset: u64,
157-
cd_length: u64,
158-
rd_offset: u64,
159-
rd_length: u64,
160-
}
161-
162151
fn callee(code: Bytecode) -> Account {
163152
let code = code.to_vec();
164153
let is_empty = code.is_empty();
@@ -172,52 +161,6 @@ mod test {
172161
}
173162
}
174163

175-
fn caller(opcode: OpcodeId, stack: Stack, caller_is_success: bool) -> Account {
176-
let is_call = opcode == OpcodeId::CALL;
177-
let terminator = if caller_is_success {
178-
OpcodeId::RETURN
179-
} else {
180-
OpcodeId::REVERT
181-
};
182-
183-
let mut bytecode = bytecode! {
184-
PUSH32(Word::from(stack.rd_length))
185-
PUSH32(Word::from(stack.rd_offset))
186-
PUSH32(Word::from(stack.cd_length))
187-
PUSH32(Word::from(stack.cd_offset))
188-
};
189-
if is_call {
190-
bytecode.push(32, stack.value);
191-
}
192-
bytecode.append(&bytecode! {
193-
PUSH32(Address::repeat_byte(0xff).to_word())
194-
PUSH32(Word::from(stack.gas))
195-
.write_op(opcode)
196-
PUSH32(Word::from(stack.rd_length))
197-
PUSH32(Word::from(stack.rd_offset))
198-
PUSH32(Word::from(stack.cd_length))
199-
PUSH32(Word::from(stack.cd_offset))
200-
});
201-
if is_call {
202-
bytecode.push(32, stack.value);
203-
}
204-
bytecode.append(&bytecode! {
205-
PUSH32(Address::repeat_byte(0xff).to_word())
206-
PUSH32(Word::from(stack.gas))
207-
.write_op(opcode)
208-
PUSH1(0)
209-
PUSH1(0)
210-
.write_op(terminator)
211-
});
212-
213-
Account {
214-
address: Address::repeat_byte(0xfe),
215-
balance: Word::from(10).pow(20.into()),
216-
code: bytecode.to_vec().into(),
217-
..Default::default()
218-
}
219-
}
220-
221164
#[test]
222165
fn test_write_protection() {
223166
// test sstore with write protection error

zkevm-circuits/src/evm_circuit/execution/jump.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ mod test {
137137
test_ok(rand_range(34..1 << 11));
138138
}
139139

140+
#[test]
141+
fn invalid_jump_err() {
142+
test_invalid_jump(34);
143+
}
144+
140145
#[test]
141146
#[ignore]
142147
fn jump_gadget_rand_huge_bytecode() {

zkevm-circuits/src/evm_circuit/table.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,4 @@ impl<F: Field> Lookup<F> {
423423
.collect(),
424424
}
425425
}
426-
427-
pub(crate) fn degree(&self) -> usize {
428-
self.input_exprs()
429-
.iter()
430-
.map(|expr| expr.degree())
431-
.max()
432-
.unwrap()
433-
}
434426
}

0 commit comments

Comments
 (0)