Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continuations: Remove the need for dummy segments #245

Merged
merged 38 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
02a2849
Implement single-segment aggregations
hratoanina Apr 24, 2024
65d8771
Change log test
hratoanina Apr 25, 2024
6141e52
Don't generate dummy segment data
hratoanina Apr 25, 2024
b7c0fe0
Fix dummy proof setting
hratoanina Apr 25, 2024
5b22d34
Make dummy proof out of dummy circuit
hratoanina Apr 25, 2024
db9a8f2
Try to generate dummy proof
hratoanina Apr 26, 2024
26d02b6
Add import
hratoanina Apr 26, 2024
187e96e
Add pis to dummy proof
hratoanina Apr 26, 2024
f8806fd
Update method name
hratoanina Apr 26, 2024
2a2d4a4
Fix PV connection
Nashtare Apr 29, 2024
4c00a54
Fix wire set twice
LindaGuiga Apr 29, 2024
2891246
Update ranges
Nashtare Apr 29, 2024
7c9f63a
Merge remote-tracking branch 'origin/feat/continuations' into no_dumm…
Nashtare Apr 29, 2024
0804c38
Add getter and handle single segment
Nashtare Apr 30, 2024
ee16349
Dummy segments, new version
hratoanina May 21, 2024
73fdf94
Fix AggChildWithDummy
LindaGuiga May 21, 2024
2941d72
Update to latest version of zkevm_no_dummy_segment
LindaGuiga May 21, 2024
483de98
Add is_dummy to ProverOutputData, remove the special logic for dummy …
LindaGuiga May 21, 2024
bc3933b
Update proof_gen
LindaGuiga May 23, 2024
540949e
Merge branch 'feat/continuations' into no_dummy_segment_no_pis
LindaGuiga May 24, 2024
58d1e6a
Cleanup and add missing connections in create_segment_aggregation_cir…
LindaGuiga May 24, 2024
37fdf73
Merge branch 'feat/continuations' into no_dummy_segment_no_pis
LindaGuiga May 28, 2024
8205e53
Merge branch 'feat/continuations' into no_dummy_segment_no_pis
LindaGuiga May 30, 2024
08dd0ab
Create generate_next_segment and make_dummy_segment
LindaGuiga May 29, 2024
5578e8b
Add debug log
LindaGuiga May 29, 2024
717d29c
Have teh SegmentDataIterator in zk_evm and change prove_all_segments …
LindaGuiga May 30, 2024
3261e62
Remove dummy segment in SegmentDataIterator
LindaGuiga May 31, 2024
a289b7a
Clippy and cleanup
LindaGuiga May 31, 2024
6eee424
Merge branch 'feat/continuations' into no_dummy_segment_no_pis
LindaGuiga Jun 5, 2024
60f67a8
Apply comments
LindaGuiga Jun 6, 2024
0153a62
Remove segments from AggregatableTxnProofs
LindaGuiga Jun 6, 2024
0f5c185
Rename SegmentAggregatableProof variant
hratoanina Jun 6, 2024
cfd1fcf
Fix generate_segment_agg_proof
LindaGuiga Jun 7, 2024
e3d7220
Merge branch 'feat/continuations' into no_dummy_segment_no_pis
LindaGuiga Jun 7, 2024
354db88
Merge branch 'continuations-next-segment' into no_dummy_segment_no_pis
hratoanina Jun 10, 2024
87fa930
Apply comments
LindaGuiga Jun 11, 2024
1380841
Use reference for GenerationInputs in SegmentDataIterator
LindaGuiga Jun 13, 2024
b9c1ce7
Reintroduce changes to TxnAggregatableProof for zero-bin compatibility
LindaGuiga Jun 14, 2024
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
21 changes: 15 additions & 6 deletions evm_arithmetization/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ use crate::proof::{
FinalPublicValues, MemCapTarget, PublicValues, PublicValuesTarget, RegistersDataTarget,
TrieRoots, TrieRootsTarget, TARGET_HASH_SIZE,
};
use crate::prover::{check_abort_signal, generate_all_data_segments, prove, GenerationSegmentData};
use crate::prover::{
check_abort_signal, generate_all_data_segments, prove, GenerationSegmentData,
SegmentDataIterator,
};
use crate::recursive_verifier::{
add_common_recursion_gates, add_virtual_public_values, get_memory_extra_looking_sum_circuit,
recursive_stark_circuit, set_public_value_targets, PlonkWrapperCircuit, PublicInputs,
Expand Down Expand Up @@ -1560,15 +1563,21 @@ where
timing: &mut TimingTree,
abort_signal: Option<Arc<AtomicBool>>,
) -> anyhow::Result<Vec<ProverOutputData<F, C, D>>> {
let mut all_data_segments =
generate_all_data_segments::<F>(Some(max_cpu_len_log), &generation_inputs)?;
let mut proofs = Vec::with_capacity(all_data_segments.len());
for mut data in all_data_segments {
let mut it_segment_data = SegmentDataIterator {
inputs: generation_inputs.clone(),
partial_next_data: None,
max_cpu_len_log: Some(max_cpu_len_log),
nb_segments: 0,
};

let mut proofs = vec![];

for mut next_data in it_segment_data {
let proof = self.prove_segment(
all_stark,
config,
generation_inputs.clone(),
&mut data,
&mut next_data.1,
timing,
abort_signal.clone(),
)?;
Expand Down
89 changes: 88 additions & 1 deletion evm_arithmetization/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::{anyhow, Result};
use itertools::Itertools;
use once_cell::sync::Lazy;
use plonky2::field::extension::Extendable;
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::polynomial::PolynomialValues;
use plonky2::field::types::Field;
use plonky2::fri::oracle::PolynomialBatch;
Expand All @@ -25,7 +26,7 @@ use starky::stark::Stark;
use crate::all_stark::{AllStark, Table, NUM_TABLES};
use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::interpreter::{set_registers_and_run, ExtraSegmentData, Interpreter};
use crate::generation::state::GenerationState;
use crate::generation::state::{GenerationState, State};
use crate::generation::{generate_traces, GenerationInputs};
use crate::get_challenges::observe_public_values;
use crate::memory::segments::Segment;
Expand Down Expand Up @@ -522,6 +523,92 @@ fn build_segment_data<F: RichField>(
}
}

pub struct SegmentDataIterator {
pub partial_next_data: Option<GenerationSegmentData>,
pub inputs: GenerationInputs,
Nashtare marked this conversation as resolved.
Show resolved Hide resolved
pub max_cpu_len_log: Option<usize>,
Nashtare marked this conversation as resolved.
Show resolved Hide resolved
pub nb_segments: usize,
LindaGuiga marked this conversation as resolved.
Show resolved Hide resolved
}

type F = GoldilocksField;
impl Iterator for SegmentDataIterator {
type Item = (GenerationInputs, GenerationSegmentData);

fn next(&mut self) -> Option<Self::Item> {
let cur_and_next_data = generate_next_segment::<F>(
self.max_cpu_len_log,
&self.inputs,
self.partial_next_data.clone(),
);

if cur_and_next_data.is_some() {
let (data, next_data) = cur_and_next_data.expect(
"Data cannot be
`None`",
LindaGuiga marked this conversation as resolved.
Show resolved Hide resolved
);
self.nb_segments += 1;
self.partial_next_data = next_data;
Some((self.inputs.clone(), data))
} else {
None
}
}
}

/// Returns the data for the current segment, as well as the data -- except
/// registers_after -- for the next segment.
pub(crate) fn generate_next_segment<F: RichField>(
max_cpu_len_log: Option<usize>,
inputs: &GenerationInputs,
partial_segment_data: Option<GenerationSegmentData>,
) -> Option<(GenerationSegmentData, Option<GenerationSegmentData>)> {
let mut interpreter = Interpreter::<F>::new_with_generation_inputs(
KERNEL.global_labels["init"],
vec![],
inputs,
max_cpu_len_log,
);

// Get the (partial) current segment data, if it is provided. Otherwise,
// initialize it.
let mut segment_data = if let Some(partial) = partial_segment_data {
if partial.registers_after.program_counter == KERNEL.global_labels["halt"] {
return None;
}
interpreter
.get_mut_generation_state()
.set_segment_data(&partial);
interpreter.generation_state.memory = partial.memory.clone();
Nashtare marked this conversation as resolved.
Show resolved Hide resolved
partial
} else {
build_segment_data(0, None, None, None, &interpreter)
};

let segment_index = segment_data.segment_index;

// Run the interpreter to get `registers_after` and the partial data for the
// next segment.
let run_result = set_registers_and_run(segment_data.registers_after, &mut interpreter);

if let Ok((updated_registers, mem_after)) = run_result {
LindaGuiga marked this conversation as resolved.
Show resolved Hide resolved
// Set `registers_after` correctly and push the data.
let before_registers = segment_data.registers_after;

let partial_segment_data = Some(build_segment_data(
segment_index + 1,
Some(updated_registers),
Some(updated_registers),
mem_after,
&interpreter,
));

segment_data.registers_after = updated_registers;
Some((segment_data, partial_segment_data))
} else {
None
}
}

/// Returns a vector containing the data required to generate all the segments
/// of a transaction.
pub fn generate_all_data_segments<F: RichField>(
Expand Down