Skip to content

Commit 472427e

Browse files
darth-cykunxian-xia
authored andcommitted
Fix overspilling of MULTI_OBSERVE constraints due to indicator insufficiency (#7)
1 parent 065d43c commit 472427e

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

extensions/native/circuit/src/poseidon2/air.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
721721
end_idx,
722722
aux_after_start,
723723
aux_before_end,
724+
aux_read_enabled,
724725
read_data,
725726
write_data,
726727
data,
@@ -802,7 +803,7 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
802803
start_timestamp + i_var * AB::F::TWO - start_idx * AB::F::TWO,
803804
&read_data[i],
804805
)
805-
.eval(builder, aux_after_start[i] * aux_before_end[i]);
806+
.eval(builder, multi_observe_row * aux_read_enabled[i]);
806807

807808
self.memory_bridge
808809
.write(
@@ -811,21 +812,29 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
811812
start_timestamp + i_var * AB::F::TWO - start_idx * AB::F::TWO + AB::F::ONE,
812813
&write_data[i],
813814
)
814-
.eval(builder, aux_after_start[i] * aux_before_end[i]);
815+
.eval(builder, multi_observe_row * aux_read_enabled[i]);
815816
}
816817

817818
for i in 0..(CHUNK - 1) {
818819
builder
820+
.when(multi_observe_row)
819821
.when(aux_after_start[i])
820822
.assert_one(aux_after_start[i + 1]);
821823
}
822824

823825
for i in 1..CHUNK {
824826
builder
827+
.when(multi_observe_row)
825828
.when(aux_before_end[i])
826829
.assert_one(aux_before_end[i - 1]);
827830
}
828831

832+
for i in 0..CHUNK {
833+
builder
834+
.when(multi_observe_row)
835+
.assert_eq(aux_after_start[i] * aux_before_end[i], aux_read_enabled[i]);
836+
}
837+
829838
builder
830839
.when(multi_observe_row)
831840
.when(not(is_first))

extensions/native/circuit/src/poseidon2/chip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ where
781781
input_ptr_u32 + input_idx as u32,
782782
multi_observe_cols.read_data[j].as_mut(),
783783
);
784+
multi_observe_cols.aux_read_enabled[j] = F::ONE;
784785
tracing_write_native_inplace(
785786
state.memory,
786787
state_ptr_u32 + j as u32,

extensions/native/circuit/src/poseidon2/columns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub struct MultiObserveCols<T> {
229229
pub end_idx: T,
230230
pub aux_after_start: [T; CHUNK],
231231
pub aux_before_end: [T; CHUNK],
232+
pub aux_read_enabled: [T; CHUNK],
232233

233234
// Transcript observation
234235
pub read_data: [MemoryReadAuxCols<T>; CHUNK],

extensions/native/recursion/tests/recursion.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use openvm_native_compiler::{
1616
prelude::Usize,
1717
};
1818
use openvm_native_recursion::{
19-
challenger::duplex::DuplexChallengerVariable, testing_utils::inner::run_recursive_test,
19+
challenger::{duplex::DuplexChallengerVariable, CanObserveVariable},
20+
testing_utils::inner::run_recursive_test,
2021
};
2122
use openvm_stark_backend::{
2223
config::{Domain, StarkGenericConfig, Val},
@@ -218,7 +219,14 @@ fn build_test_program<C: Config>(builder: &mut Builder<C>) {
218219
let sample_lens: Vec<usize> = vec![10, 2, 1, 3, 20];
219220

220221
let mut rng = create_seeded_rng();
221-
let challenger = DuplexChallengerVariable::new(builder);
222+
let mut challenger = DuplexChallengerVariable::new(builder);
223+
224+
// Observe a setup label
225+
let label_f: Vec<u64> = vec![128, 3098, 192, 394, 1662, 928, 374, 281, 598, 182, 475, 729];
226+
for n in label_f {
227+
let f: Felt<C::F> = builder.constant(C::F::from_canonical_u64(n));
228+
challenger.observe(builder, f);
229+
}
222230

223231
for l in sample_lens {
224232
let sample_input: Array<C, Felt<C::F>> = builder.dyn_array(l);

0 commit comments

Comments
 (0)