Skip to content

Commit 07ad739

Browse files
committed
fix edge case: make the proof work even if there is no Poseidon calls during execution
1 parent a92ba9e commit 07ad739

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lean_prover/src/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ pub fn get_base_dims(
1717
log_public_memory: usize,
1818
private_memory_len: usize,
1919
bytecode_ending_pc: usize,
20-
poseidon_counts: (usize, usize),
20+
(n_poseidons_16, n_poseidons_24): (usize, usize),
2121
n_rows_table_dot_products: usize,
2222
(p16_gkr_layers, p24_gkr_layers): (
2323
&PoseidonGKRLayers<16, N_COMMITED_CUBES_P16>,
2424
&PoseidonGKRLayers<24, N_COMMITED_CUBES_P24>,
2525
),
2626
) -> Vec<ColDims<F>> {
27-
let (n_poseidons_16, n_poseidons_24) = poseidon_counts;
27+
let n_poseidons_16 = n_poseidons_16.max(1 << LOG_MIN_POSEIDONS_16);
28+
let n_poseidons_24 = n_poseidons_24.max(1 << LOG_MIN_POSEIDONS_24);
29+
2830
let p16_default_cubes = default_cube_layers::<F, 16, N_COMMITED_CUBES_P16>(p16_gkr_layers);
2931
let p24_default_cubes = default_cube_layers::<F, 24, N_COMMITED_CUBES_P24>(p24_gkr_layers);
3032

crates/lean_prover/src/prove_execution.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub fn prove_execution(
6767
let log_n_cycles = log2_strict_usize(n_cycles);
6868
assert!(full_trace.iter().all(|col| col.len() == 1 << log_n_cycles));
6969

70-
let log_n_p16 = log2_ceil_usize(n_poseidons_16);
71-
let log_n_p24 = log2_ceil_usize(n_poseidons_24);
70+
let log_n_p16 = log2_ceil_usize(n_poseidons_16).max(LOG_MIN_POSEIDONS_16);
71+
let log_n_p24 = log2_ceil_usize(n_poseidons_24).max(LOG_MIN_POSEIDONS_24);
7272

7373
precompute_dft_twiddles::<F>(1 << 24);
7474

@@ -334,7 +334,7 @@ pub fn prove_execution(
334334
&WitnessPoseidon16::default_addresses_field_repr(POSEIDON_16_NULL_HASH_PTR),
335335
fingerprint_challenge,
336336
))
337-
.exp_u64((n_poseidons_16.next_power_of_two() - n_poseidons_16) as u64);
337+
.exp_u64(((1 << log_n_p16) - n_poseidons_16) as u64);
338338

339339
let corrected_prod_p24 = grand_product_p24_res
340340
/ (grand_product_challenge_global
@@ -343,7 +343,7 @@ pub fn prove_execution(
343343
&WitnessPoseidon24::default_addresses_field_repr(POSEIDON_24_NULL_HASH_PTR),
344344
fingerprint_challenge,
345345
))
346-
.exp_u64((n_poseidons_24.next_power_of_two() - n_poseidons_24) as u64);
346+
.exp_u64(((1 << log_n_p24) - n_poseidons_24) as u64);
347347

348348
let corrected_dot_product = grand_product_dot_product_res
349349
/ ((grand_product_challenge_global

crates/lean_prover/src/verify_execution.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub fn verify_execution(
6868

6969
let log_public_memory = log2_strict_usize(public_memory.len());
7070
let log_memory = log2_ceil_usize(public_memory.len() + private_memory_len);
71-
let log_n_p16 = log2_ceil_usize(n_poseidons_16);
72-
let log_n_p24 = log2_ceil_usize(n_poseidons_24);
71+
let log_n_p16 = log2_ceil_usize(n_poseidons_16).max(LOG_MIN_POSEIDONS_16);
72+
let log_n_p24 = log2_ceil_usize(n_poseidons_24).max(LOG_MIN_POSEIDONS_24);
7373

7474
if !(MIN_LOG_MEMORY_SIZE..=MAX_LOG_MEMORY_SIZE).contains(&log_memory) {
7575
return Err(ProofError::InvalidProof);
@@ -159,7 +159,7 @@ pub fn verify_execution(
159159
&WitnessPoseidon16::default_addresses_field_repr(POSEIDON_16_NULL_HASH_PTR),
160160
fingerprint_challenge,
161161
))
162-
.exp_u64((n_poseidons_16.next_power_of_two() - n_poseidons_16) as u64);
162+
.exp_u64(((1 << log_n_p16) - n_poseidons_16) as u64);
163163

164164
let corrected_prod_p24 = grand_product_p24_res
165165
/ (grand_product_challenge_global
@@ -168,7 +168,7 @@ pub fn verify_execution(
168168
&WitnessPoseidon24::default_addresses_field_repr(POSEIDON_24_NULL_HASH_PTR),
169169
fingerprint_challenge,
170170
))
171-
.exp_u64((n_poseidons_24.next_power_of_two() - n_poseidons_24) as u64);
171+
.exp_u64(((1 << log_n_p24) - n_poseidons_24) as u64);
172172

173173
let corrected_dot_product = grand_product_dot_product_res
174174
/ ((grand_product_challenge_global

crates/lean_prover/witness_generation/src/execution_trace.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::instruction_encoder::field_representation;
44
use crate::{
55
COL_INDEX_FP, COL_INDEX_MEM_ADDRESS_A, COL_INDEX_MEM_ADDRESS_B, COL_INDEX_MEM_ADDRESS_C,
66
COL_INDEX_MEM_VALUE_A, COL_INDEX_MEM_VALUE_B, COL_INDEX_MEM_VALUE_C, COL_INDEX_PC,
7-
N_TOTAL_COLUMNS,
7+
LOG_MIN_POSEIDONS_16, LOG_MIN_POSEIDONS_24, N_TOTAL_COLUMNS,
88
};
99
use lean_vm::*;
1010
use p3_field::Field;
@@ -108,14 +108,18 @@ pub fn get_execution_trace(
108108
..
109109
} = execution_result;
110110

111-
poseidons_16.extend(vec![
112-
WitnessPoseidon16::poseidon_of_zero();
113-
n_poseidons_16.next_power_of_two() - n_poseidons_16
114-
]);
115-
poseidons_24.extend(vec![
116-
WitnessPoseidon24::poseidon_of_zero();
117-
n_poseidons_24.next_power_of_two() - n_poseidons_24
118-
]);
111+
poseidons_16.resize(
112+
n_poseidons_16
113+
.next_power_of_two()
114+
.max(1 << LOG_MIN_POSEIDONS_16),
115+
WitnessPoseidon16::poseidon_of_zero(),
116+
);
117+
poseidons_24.resize(
118+
n_poseidons_24
119+
.next_power_of_two()
120+
.max(1 << LOG_MIN_POSEIDONS_24),
121+
WitnessPoseidon24::poseidon_of_zero(),
122+
);
119123

120124
let n_compressions_16;
121125
(poseidons_16, n_compressions_16) = put_poseidon16_compressions_at_the_end(&poseidons_16); // TODO avoid reallocation

crates/lean_prover/witness_generation/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ impl InAirColumnIndex for usize {
6161
}
6262
}
6363
}
64+
65+
// Zero padding will be added to each at least, if this minimum is not reached
66+
// (ensuring AIR / GKR work fine, with SIMD, without too much edge cases)
67+
pub const LOG_MIN_POSEIDONS_16: usize = 8;
68+
pub const LOG_MIN_POSEIDONS_24: usize = 8;

crates/lookup/src/product_gkr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where
3737
{
3838
assert!(log2_strict_usize(final_layer.len()) >= 1);
3939
if final_layer.len() == 2 {
40-
prover_state.add_extension_scalars(&final_layer);
40+
prover_state.add_extension_scalars(final_layer);
4141
let product = final_layer[0] * final_layer[1];
4242
let point = MultilinearPoint(vec![prover_state.sample()]);
4343
let claim = Evaluation {
@@ -71,7 +71,7 @@ where
7171
};
7272
assert_eq!(last_layer.len(), 2);
7373
let product = last_layer[0] * last_layer[1];
74-
prover_state.add_extension_scalars(&last_layer);
74+
prover_state.add_extension_scalars(last_layer);
7575

7676
let point = MultilinearPoint(vec![prover_state.sample()]);
7777
let mut claim = Evaluation {

0 commit comments

Comments
 (0)