Skip to content

Commit 065d43c

Browse files
authored
remove read_sponge_state columns (#13)
1 parent d994e78 commit 065d43c

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{array::from_fn, borrow::Borrow, sync::Arc};
22

3+
use itertools::Itertools;
34
use openvm_circuit::{
45
arch::{ExecutionBridge, ExecutionState},
56
system::memory::{offline_checker::MemoryBridge, MemoryAddress, CHUNK},
@@ -724,7 +725,6 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
724725
write_data,
725726
data,
726727
should_permute,
727-
read_sponge_state,
728728
write_sponge_state,
729729
write_final_idx,
730730
final_idx,
@@ -856,29 +856,30 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
856856
end_idx,
857857
);
858858

859-
let full_sponge_input = from_fn::<_, { CHUNK * 2 }, _>(|i| local.inner.inputs[i]);
860859
let full_sponge_output = from_fn::<_, { CHUNK * 2 }, _>(|i| {
861860
local.inner.ending_full_rounds[BABY_BEAR_POSEIDON2_HALF_FULL_ROUNDS - 1].post[i]
862861
});
863862

864-
self.memory_bridge
865-
.read(
866-
MemoryAddress::new(self.address_space, state_ptr),
867-
full_sponge_input,
868-
start_timestamp + (end_idx - start_idx) * AB::F::TWO,
869-
&read_sponge_state,
870-
)
871-
.eval(builder, multi_observe_row * should_permute);
872-
873863
self.memory_bridge
874864
.write(
875865
MemoryAddress::new(self.address_space, state_ptr),
876866
full_sponge_output,
877-
start_timestamp + (end_idx - start_idx) * AB::F::TWO + AB::F::ONE,
867+
start_timestamp + (end_idx - start_idx) * AB::F::TWO,
878868
&write_sponge_state,
879869
)
880870
.eval(builder, multi_observe_row * should_permute);
881871

872+
// enforce that prev_data is permutation input
873+
write_sponge_state
874+
.prev_data()
875+
.iter()
876+
.zip_eq(local.inner.inputs.iter())
877+
.for_each(|(a, b)| {
878+
builder
879+
.when(multi_observe_row * should_permute)
880+
.assert_eq(*a, *b);
881+
});
882+
882883
/*
883884
self.memory_bridge
884885
.write(
@@ -897,7 +898,10 @@ impl<AB: InteractionBuilder, const SBOX_REGISTERS: usize> Air<AB>
897898
builder
898899
.when(next.multi_observe_row)
899900
.when(not(next_multi_observe_specific.is_first))
900-
.assert_eq(next_multi_observe_specific.curr_len, multi_observe_specific.curr_len + end_idx - start_idx);
901+
.assert_eq(
902+
next_multi_observe_specific.curr_len,
903+
multi_observe_specific.curr_len + end_idx - start_idx,
904+
);
901905

902906
// Boundary conditions
903907
builder

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ where
676676
if len >= (CHUNK - pos) {
677677
chunks.push((pos.clone(), CHUNK.clone()));
678678
len -= CHUNK - pos;
679-
final_timestamp_inc += 2 * (CHUNK - pos + 1);
679+
final_timestamp_inc += 2 * (CHUNK - pos) + 1;
680680
pos = 0;
681681
} else {
682682
chunks.push((pos.clone(), pos + len));
@@ -766,11 +766,7 @@ where
766766
multi_observe_cols.end_idx = F::from_canonical_usize(chunk_end);
767767

768768
multi_observe_cols.is_first = F::ZERO;
769-
multi_observe_cols.is_last = if i == num_chunks - 1 {
770-
F::ONE
771-
} else {
772-
F::ZERO
773-
};
769+
multi_observe_cols.is_last = if i == num_chunks - 1 { F::ONE } else { F::ZERO };
774770
multi_observe_cols.curr_len = F::from_canonical_usize(input_idx);
775771

776772
for j in chunk_start..CHUNK {
@@ -796,13 +792,10 @@ where
796792
cur_timestamp += 2;
797793
}
798794

795+
let permutation_input: [F; 16] =
796+
memory_read_native(state.memory.data(), state_ptr_u32);
799797
if chunk_end >= CHUNK {
800798
multi_observe_cols.should_permute = F::ONE;
801-
let permutation_input: [F; 16] = tracing_read_native_helper(
802-
state.memory,
803-
state_ptr_u32,
804-
multi_observe_cols.read_sponge_state.as_mut(),
805-
);
806799
cols.inner.inputs.clone_from_slice(&permutation_input);
807800
let output = self.subchip.permute(permutation_input);
808801
tracing_write_native_inplace(
@@ -811,12 +804,10 @@ where
811804
std::array::from_fn(|i| output[i]),
812805
&mut multi_observe_cols.write_sponge_state,
813806
);
814-
cur_timestamp += 2;
807+
cur_timestamp += 1;
815808
} else {
816809
multi_observe_cols.should_permute = F::ZERO;
817-
let sponge_state: [F; 16] =
818-
memory_read_native(state.memory.data(), state_ptr_u32);
819-
cols.inner.inputs.clone_from_slice(&sponge_state);
810+
cols.inner.inputs.clone_from_slice(&permutation_input);
820811
}
821812
}
822813
} else {
@@ -1219,11 +1210,6 @@ impl<F: PrimeField32, const SBOX_REGISTERS: usize> NativePoseidon2Filler<F, SBOX
12191210
mem_fill_helper(
12201211
mem_helper,
12211212
start_timestamp_u32,
1222-
multi_observe_cols.read_sponge_state.as_mut(),
1223-
);
1224-
mem_fill_helper(
1225-
mem_helper,
1226-
start_timestamp_u32 + 1,
12271213
multi_observe_cols.write_sponge_state.as_mut(),
12281214
);
12291215
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ pub struct MultiObserveCols<T> {
237237

238238
// Permutation
239239
pub should_permute: T,
240-
pub read_sponge_state: MemoryReadAuxCols<T>,
241240
pub write_sponge_state: MemoryWriteAuxCols<T, { CHUNK * 2 }>,
242241

243242
// Final write back and registers

0 commit comments

Comments
 (0)