Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e1bc6d8
Refactor StateCircuit + add lexicographic ordering constraints
Apr 5, 2022
edc633a
Implement first_access method and fix stack change constraint
Apr 5, 2022
8671e8a
Cleanup and comment out failing constraint
Apr 5, 2022
ca8e2ec
Fix failing tests by correctly getting limbs in be order in lexicogra…
Apr 5, 2022
1b59c57
fix clippy
Apr 7, 2022
e7c47c4
Rename test files for clippy
Apr 7, 2022
450a202
Cleanup benchmarks
Apr 7, 2022
79bff4a
fix build
Apr 7, 2022
e39b198
Assign diff_inverse correctly
Apr 7, 2022
ea9c4f8
Fix instance function and convert it to a method
Apr 11, 2022
25750df
Fix storage_key_be_limbs method
Apr 11, 2022
f8e6676
Add degree test
Apr 11, 2022
691ea89
Have StateCircuit use Vec<Rw> instead of RwMap
Apr 13, 2022
04847ec
Compute first_access correctly
Apr 13, 2022
374cf71
wip, but tests pass
Apr 13, 2022
c491a3a
Fix diff_2 assignment
Apr 13, 2022
a3a5ce5
cleanup
Apr 13, 2022
36293e5
Use verify_at_rows to speed up tests and derive EnumIter
Apr 14, 2022
37c0644
Add cleanup and explain diff_1 and diff_2
Apr 15, 2022
12cb311
cleanup
Apr 28, 2022
96bee8c
fmt
Apr 28, 2022
247c591
Add newline to fix cargo fmt
Apr 28, 2022
5a69934
Fix degree test and TxLog table assignment
Apr 29, 2022
a96321f
Cleanup and change index type to u8 from usize
Apr 29, 2022
808c7fe
Rename to diff_1->upper_limb_difference and diff_2->lower_limb_differ…
Apr 29, 2022
dd6126a
Explain assignment in comments
May 2, 2022
243a012
fix conflicts
lispc May 4, 2022
14c0f29
lint
lispc May 9, 2022
2295a4e
fix rebase
May 9, 2022
fb920b8
fix build and tests from rebase
May 10, 2022
19e25dc
make change to rerun tests
May 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions circuit-benchmarks/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,9 @@ fn main() {
.unwrap_or_else(|_| "11".to_string())
.parse()
.expect("Cannot parse DEGREE env var as usize");
let memory_address_max: usize = var("MEMORY_ADDRESS_MAX")
.unwrap_or_else(|_| "2000".to_string())
.parse()
.expect("Cannot parse MEMORY_ADDRESS_MAX env var as usize");
let stack_address_max: usize = var("STACK_ADDRESS_MAX")
.unwrap_or_else(|_| "1300".to_string())
.parse()
.expect("Cannot parse STACK_ADDRESS_MAX env var as usize");

// Add state_circuit module to `lib.rs`
let consts = format!(
"pub(crate) const DEGREE: usize = {};
pub(crate) const MEMORY_ADDRESS_MAX: usize = {};
pub(crate) const STACK_ADDRESS_MAX: usize = {};
",
degree, memory_address_max, stack_address_max
);
let consts = format!("pub(crate) const DEGREE: usize = {};\n", degree);

let mut state_file =
File::create("src/bench_params.rs").expect("Error generating bench_params.rs file");
Expand Down
14 changes: 2 additions & 12 deletions circuit-benchmarks/src/state_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[cfg(test)]
mod tests {
use crate::bench_params::{DEGREE, MEMORY_ADDRESS_MAX, STACK_ADDRESS_MAX};
use crate::bench_params::DEGREE;
use ark_std::{end_timer, start_timer};
use halo2_proofs::plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, SingleVerifier};
use halo2_proofs::{
Expand All @@ -14,20 +14,10 @@ mod tests {
use rand_xorshift::XorShiftRng;
use zkevm_circuits::state_circuit::StateCircuit;

const RW_COUNTER_MAX: usize = 1 << DEGREE;
const ROWS_MAX: usize = 1 << DEGREE;

#[cfg_attr(not(feature = "benches"), ignore)]
#[test]
fn bench_state_circuit_prover() {
let empty_circuit = StateCircuit::<
Fr,
true,
RW_COUNTER_MAX,
MEMORY_ADDRESS_MAX,
STACK_ADDRESS_MAX,
ROWS_MAX,
>::default();
let empty_circuit = StateCircuit::<Fr>::default();

// Initialize the polynomial commitment parameters
let rng = XorShiftRng::from_seed([
Expand Down
21 changes: 6 additions & 15 deletions integration-tests/tests/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,21 @@ async fn test_state_circuit_block(block_num: u64) {
let storage_ops = builder.block.container.sorted_storage();
trace!("storage_ops: {:#?}", storage_ops);

const DEGREE: usize = 16;
const MEMORY_ADDRESS_MAX: usize = 2000;
const STACK_ADDRESS_MAX: usize = 1024;

const RW_COUNTER_MAX: usize = 1 << DEGREE;
const ROWS_MAX: usize = 1 << DEGREE;
const DEGREE: usize = 17;

let rw_map = RwMap::from(&OperationContainer {
memory: memory_ops,
stack: stack_ops,
storage: storage_ops,
..Default::default()
});
let circuit = StateCircuit::<
Fr,
true,
RW_COUNTER_MAX,
MEMORY_ADDRESS_MAX,
STACK_ADDRESS_MAX,
ROWS_MAX,
>::new(Fr::rand(), &rw_map);

let randomness = Fr::rand();
let circuit = StateCircuit::<Fr>::new(randomness, rw_map);
let power_of_randomness = circuit.instance();

use halo2_proofs::pairing::bn256::Fr as Fp;
let prover = MockProver::<Fp>::run(DEGREE as u32, &circuit, vec![]).unwrap();
let prover = MockProver::<Fp>::run(DEGREE as u32, &circuit, power_of_randomness).unwrap();
prover.verify().expect("state_circuit verification failed");
}

Expand Down
1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ log = "0.4.14"
rand = "0.8.4"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.78"
strum = "0.24"
tokio = { version = "1.16.1", features = ["macros", "rt-multi-thread"] }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"] }
21 changes: 3 additions & 18 deletions prover/src/compute_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use halo2_proofs::{
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::str::FromStr;
use strum::IntoEnumIterator;
use zkevm_circuits::evm_circuit::{
table::FixedTableTag, test::TestCircuit, witness::block_convert,
};
Expand Down Expand Up @@ -37,7 +38,7 @@ pub async fn compute_proof(
let block = block_convert(&builder.block, &builder.code_db);
{
// generate evm_circuit proof
let circuit = TestCircuit::<Fr>::new(block.clone(), FixedTableTag::iterator().collect());
let circuit = TestCircuit::<Fr>::new(block.clone(), FixedTableTag::iter().collect());

// TODO: can this be pre-generated to a file?
// related
Expand All @@ -60,23 +61,7 @@ pub async fn compute_proof(

{
// generate state_circuit proof
//
// TODO: this should be configurable
const MEMORY_ADDRESS_MAX: usize = 2000;
const STACK_ADDRESS_MAX: usize = 1300;
const MEMORY_ROWS_MAX: usize = 16384;
const STACK_ROWS_MAX: usize = 16384;
const STORAGE_ROWS_MAX: usize = 16384;
const GLOBAL_COUNTER_MAX: usize = MEMORY_ROWS_MAX + STACK_ROWS_MAX + STORAGE_ROWS_MAX;

let circuit = StateCircuit::<
Fr,
true,
GLOBAL_COUNTER_MAX,
MEMORY_ADDRESS_MAX,
STACK_ADDRESS_MAX,
GLOBAL_COUNTER_MAX,
>::new(block.randomness, &block.rws);
let circuit = StateCircuit::new(block.randomness, block.rws);

// TODO: same quest like in the first scope
let vk = keygen_vk(params, &circuit)?;
Expand Down
2 changes: 2 additions & 0 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ eth-types = { path = "../eth-types" }
gadgets = { path = "../gadgets" }
ethers-core = "0.6"
serde_json = "1.0.66"
strum = "0.24"
strum_macros = "0.24"
rand_xorshift = "0.3"
rand = "0.8"
itertools = "0.10.3"
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ impl<F: Field> EvmCircuit<F> {

#[cfg(any(feature = "test", test))]
pub mod test {

use crate::{
evm_circuit::{
table::FixedTableTag,
Expand All @@ -165,6 +164,7 @@ pub mod test {
distributions::uniform::{SampleRange, SampleUniform},
random, thread_rng, Rng,
};
use strum::IntoEnumIterator;

pub(crate) fn rand_range<T, R>(range: R) -> T
where
Expand Down Expand Up @@ -500,6 +500,6 @@ pub mod test {
pub fn run_test_circuit_complete_fixed_table<F: Field>(
block: Block<F>,
) -> Result<(), Vec<VerifyFailure>> {
run_test_circuit(block, FixedTableTag::iterator().collect())
run_test_circuit(block, FixedTableTag::iter().collect())
}
}
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/copy_to_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub mod test {
tx_id,
log_id,
field_tag: TxLogFieldTag::Data,
index: idx,
index: idx.try_into().unwrap(),
value: Word::from(byte),
});
rw_offset += 1;
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
};
use eth_types::{evm_types::MAX_REFUND_QUOTIENT_OF_GAS_USED, Field, ToScalar};
use halo2_proofs::plonk::Error;
use strum::EnumCount;

#[derive(Clone, Debug)]
pub(crate) struct EndTxGadget<F> {
Expand Down Expand Up @@ -255,7 +256,7 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
} else {
let rw = &block.rws[(
RwTableTag::TxReceipt,
(tx.id - 1) * TxReceiptFieldTag::amount() - 1,
(tx.id - 1) * TxReceiptFieldTag::COUNT - 1,
)];
rw.receipt_value()
};
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ mod test {
tx_id,
log_id: log_id.try_into().unwrap(),
field_tag: TxLogFieldTag::Topic,
index: idx,
index: idx.try_into().unwrap(),
value: *topic,
});
}
Expand Down
Loading