Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LindaGuiga committed May 3, 2024
1 parent 42dbb96 commit 367a77d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ serde-big-array = "0.5.1"
thiserror = "1.0.49"

# plonky2-related dependencies
plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" }
plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" }
plonky2_maybe_rayon = "0.2.0"
plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" }
starky = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" }
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: 2 additions & 0 deletions evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ fn test_init_exc_stop() {
interpreter.set_is_kernel(true);
interpreter.clock = 0;

// Set the program counter and `is_kernel` at the end of the execution. They
// have offsets 6 and 7 resepectively in segment `RegistersStates`.
let regs_to_set = [
(
MemoryAddress {
Expand Down
81 changes: 43 additions & 38 deletions evm_arithmetization/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,44 +1977,7 @@ where
proof,
);
if is_dummy {
let mut dummy_pis = proof.public_inputs.clone();
// We must change the registers before and memory before.
dummy_pis.copy_within(
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE
..TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2,
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE,
);
// Mem before := Mem after
dummy_pis.copy_within(
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2
+ len_mem_cap * NUM_HASH_OUT_ELTS
..TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2
+ 2 * len_mem_cap * NUM_HASH_OUT_ELTS,
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2,
);
let dummy_pis = Self::get_dummy_pis(&proof.public_inputs, len_mem_cap);

let mut dummy_pis_map = HashMap::new();
for (idx, &pi) in dummy_pis.iter().enumerate() {
Expand All @@ -2033,6 +1996,48 @@ where
agg_inputs.set_proof_with_pis_target(&agg_child.real_proof, proof);
}

fn get_dummy_pis(pis: &[F], len_mem_cap: usize) -> Vec<F> {
let mut dummy_pis = pis.to_vec();
// We must change the registers before and memory before.
dummy_pis.copy_within(
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE
..TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2,
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE,
);
// Mem before := Mem after
dummy_pis.copy_within(
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2
+ len_mem_cap * NUM_HASH_OUT_ELTS
..TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2
+ 2 * len_mem_cap * NUM_HASH_OUT_ELTS,
TrieRootsTarget::SIZE * 2
+ BlockMetadataTarget::SIZE
+ BlockHashesTarget::SIZE
+ ExtraBlockDataTarget::SIZE
+ RegistersDataTarget::SIZE * 2,
);
dummy_pis
}

/// Create a final block proof, once all transactions of a given block have
/// been combined into a single aggregation proof.
///
Expand Down
26 changes: 15 additions & 11 deletions evm_arithmetization/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,20 +824,24 @@ impl TrieRootsTarget {
}

/// If `condition`, asserts that `tr0 == tr1`.
pub(crate) fn assert_equal_if<F: RichField + Extendable<D>, const D: usize>(
pub(crate) fn conditionally_assert_eq<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
condition: BoolTarget,
tr0: Self,
tr1: Self,
) {
for i in 0..8 {
builder.assert_equal_if(condition.target, tr0.state_root[i], tr1.state_root[i]);
builder.assert_equal_if(
builder.conditional_assert_eq(condition.target, tr0.state_root[i], tr1.state_root[i]);
builder.conditional_assert_eq(
condition.target,
tr0.transactions_root[i],
tr1.transactions_root[i],
);
builder.assert_equal_if(condition.target, tr0.receipts_root[i], tr1.receipts_root[i]);
builder.conditional_assert_eq(
condition.target,
tr0.receipts_root[i],
tr1.receipts_root[i],
);
}
}
}
Expand Down Expand Up @@ -1205,14 +1209,14 @@ impl RegistersDataTarget {
rd0: Self,
rd1: Self,
) {
builder.assert_equal_if(condition.target, rd0.program_counter, rd1.program_counter);
builder.assert_equal_if(condition.target, rd0.is_kernel, rd1.is_kernel);
builder.assert_equal_if(condition.target, rd0.stack_len, rd1.stack_len);
builder.conditional_assert_eq(condition.target, rd0.program_counter, rd1.program_counter);
builder.conditional_assert_eq(condition.target, rd0.is_kernel, rd1.is_kernel);
builder.conditional_assert_eq(condition.target, rd0.stack_len, rd1.stack_len);
for i in 0..8 {
builder.assert_equal_if(condition.target, rd0.stack_top[i], rd1.stack_top[i]);
builder.conditional_assert_eq(condition.target, rd0.stack_top[i], rd1.stack_top[i]);
}
builder.assert_equal_if(condition.target, rd0.context, rd1.context);
builder.assert_equal_if(condition.target, rd0.gas_used, rd1.gas_used);
builder.conditional_assert_eq(condition.target, rd0.context, rd1.context);
builder.conditional_assert_eq(condition.target, rd0.gas_used, rd1.gas_used);
}
}

Expand Down Expand Up @@ -1291,7 +1295,7 @@ impl MemCapTarget {
) {
for i in 0..mc0.mem_cap.0.len() {
for j in 0..NUM_HASH_OUT_ELTS {
builder.assert_equal_if(
builder.conditional_assert_eq(
condition.target,
mc0.mem_cap.0[i].elements[j],
mc1.mem_cap.0[i].elements[j],
Expand Down

0 comments on commit 367a77d

Please sign in to comment.