Skip to content

Commit

Permalink
continuations: Remove the need for dummy segments (#245)
Browse files Browse the repository at this point in the history
* Implement single-segment aggregations

* Change log test

* Don't generate dummy segment data

* Fix dummy proof setting

* Make dummy proof out of dummy circuit

* Try to generate dummy proof

* Add import

* Add pis to dummy proof

* Update method name

* Fix PV connection

* Fix wire set twice

* Update ranges

* Add getter and handle single segment

* Dummy segments, new version

* Fix AggChildWithDummy

* Update to latest version of zkevm_no_dummy_segment

* Add is_dummy to ProverOutputData, remove the special logic for dummy segments, re-export dummy_proof in proof_gen and cleanup

* Update proof_gen

* Cleanup and add missing connections in create_segment_aggregation_circuit

* Create generate_next_segment and make_dummy_segment

* Add debug log

* Have teh SegmentDataIterator in zk_evm and change prove_all_segments to use it

* Remove dummy segment in SegmentDataIterator

* Clippy and cleanup

* Apply comments

* Remove segments from AggregatableTxnProofs

* Rename SegmentAggregatableProof variant

* Fix generate_segment_agg_proof

* Apply comments

* Use reference for GenerationInputs in SegmentDataIterator

* Reintroduce changes to TxnAggregatableProof for zero-bin compatibility

---------

Co-authored-by: Hamy Ratoanina <hamy.ratoanina@toposware.com>
Co-authored-by: Robin Salen <salenrobin@gmail.com>
Co-authored-by: hratoanina <hratoanina@polygon.technology>
  • Loading branch information
4 people authored Jul 1, 2024
1 parent 14dc5c2 commit 1bcf891
Show file tree
Hide file tree
Showing 18 changed files with 678 additions and 253 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ serde = "1.0.166"
serde_json = "1.0.96"
serde-big-array = "0.5.1"
thiserror = "1.0.49"
hashbrown = "0.14.0"

# plonky2-related dependencies
plonky2 = "0.2.2"
plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" }
plonky2_maybe_rayon = "0.2.0"
plonky2_util = "0.2.0"
starky = "0.4.0"
plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" }
starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" }


[workspace.package]
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ rlp = { workspace = true }
rlp-derive = { workspace = true }
serde = { workspace = true, features = ["derive"] }
static_assertions = "1.1.0"
hashbrown = { version = "0.14.0" }
hashbrown = { workspace = true }
tiny-keccak = "2.0.2"
serde_json = { workspace = true }
serde-big-array = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<F: Field> Interpreter<F> {
}

pub(crate) fn run(&mut self) -> Result<(RegistersState, Option<MemoryState>), anyhow::Error> {
let (final_registers, final_mem) = self.run_cpu(self.max_cpu_len_log, self.is_dummy)?;
let (final_registers, final_mem) = self.run_cpu(self.max_cpu_len_log)?;

#[cfg(debug_assertions)]
{
Expand Down
3 changes: 1 addition & 2 deletions evm_arithmetization/src/cpu/kernel/tests/bignum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use itertools::Itertools;
use num::{BigUint, One, Zero};
use num_bigint::RandBigInt;
use plonky2::field::goldilocks_field::GoldilocksField as F;
use plonky2_util::ceil_div_usize;
use rand::Rng;

use crate::cpu::kernel::aggregator::KERNEL;
Expand Down Expand Up @@ -90,7 +89,7 @@ fn max_bignum(bit_size: usize) -> BigUint {
}

fn bignum_len(a: &BigUint) -> usize {
ceil_div_usize(a.bits() as usize, BIGNUM_LIMB_BITS)
(a.bits() as usize).div_ceil(BIGNUM_LIMB_BITS)
}

fn run_test(fn_label: &str, memory: Vec<U256>, stack: Vec<U256>) -> Result<(Vec<U256>, Vec<U256>)> {
Expand Down
46 changes: 40 additions & 6 deletions evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ use crate::generation::state::State;
use crate::generation::TrieInputs;
use crate::generation::NUM_EXTRA_CYCLES_AFTER;
use crate::generation::NUM_EXTRA_CYCLES_BEFORE;
use crate::memory::segments::Segment;
use crate::proof::BlockMetadata;
use crate::proof::RegistersData;
use crate::proof::RegistersIdx;
use crate::proof::TrieRoots;
use crate::witness::memory::MemoryAddress;
use crate::witness::state::RegistersState;
use crate::{proof::BlockHashes, GenerationInputs, Node};

Expand Down Expand Up @@ -89,19 +93,49 @@ fn test_init_exc_stop() {
"Incorrect registers for dummy run."
);

let main_offset = KERNEL.global_labels["main"];
let mut interpreter: Interpreter<F> =
Interpreter::new_dummy_with_generation_inputs(initial_offset, vec![], &inputs);
let exc_stop_offset = KERNEL.global_labels["exc_stop"];

let pc_u256 = U256::from(interpreter.get_registers().program_counter);
let exit_info = pc_u256 + (U256::one() << 32);
interpreter.push(exit_info).unwrap();
interpreter.get_mut_registers().program_counter = exc_stop_offset;
interpreter.halt_offsets = vec![KERNEL.global_labels["halt_final"]];
interpreter.set_is_kernel(true);
interpreter.clock = 0;

// Set the program counter and `is_kernel` at the end of the execution. The
// `registers_before` and `registers_after` are stored contiguously in the
// `RegistersState` segment. We need to update `registers_after` here, hence the
// offset by `RegistersData::SIZE`.
let regs_to_set = [
(
MemoryAddress {
context: 0,
segment: Segment::RegistersStates.unscale(),
virt: RegistersData::SIZE + RegistersIdx::ProgramCounter as usize,
},
pc_u256,
),
(
MemoryAddress {
context: 0,
segment: Segment::RegistersStates.unscale(),
virt: RegistersData::SIZE + RegistersIdx::IsKernel as usize,
},
U256::one(),
),
];
interpreter.set_memory_multi_addresses(&regs_to_set);

interpreter.run().expect("Running dummy exc_stop failed.");

// The "-1" comes from the fact that we stop 1 cycle before the max, to allow
// for one padding row, which is needed for CPU STARK.
// The "-2" comes from the fact that:
// - we stop 1 cycle before the max, to allow for one padding row, which is
// needed for CPU STARK.
// - we need one additional cycle to enter `exc_stop`.
assert_eq!(
interpreter.get_clock(),
NUM_EXTRA_CYCLES_BEFORE + NUM_EXTRA_CYCLES_AFTER - 1,
NUM_EXTRA_CYCLES_AFTER - 2,
"NUM_EXTRA_CYCLES_AFTER is set incorrectly."
);
}
3 changes: 1 addition & 2 deletions evm_arithmetization/src/cpu/kernel/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::fmt::Debug;

use ethereum_types::U256;
use plonky2_util::ceil_div_usize;

/// Enumerate the length `W` windows of `vec`, and run `maybe_replace` on each
/// one.
Expand All @@ -28,7 +27,7 @@ where
}

pub(crate) fn u256_to_trimmed_be_bytes(u256: &U256) -> Vec<u8> {
let num_bytes = ceil_div_usize(u256.bits(), 8);
let num_bytes = u256.bits().div_ceil(8);
// `byte` is little-endian, so we manually reverse it.
(0..num_bytes).rev().map(|i| u256.byte(i)).collect()
}
Expand Down
Loading

0 comments on commit 1bcf891

Please sign in to comment.