@@ -156,24 +156,30 @@ pub(crate) fn eval<
156156) {
157157 air. p3_poseidon2 . eval ( builder) ;
158158
159+ // SPONGE CONSTRAINTS
159160 let next_no_reset = AB :: Expr :: ONE - next. reset . clone ( ) ;
160161 for i in 0 ..( CAPACITY * D ) {
161162 // The first row has capacity zeroed.
162163 builder
164+ . when ( local. is_sponge . clone ( ) )
163165 . when_first_row ( )
164166 . assert_zero ( local. poseidon2 . inputs [ RATE * D + i] . clone ( ) ) ;
165167
166168 // When resetting the state, we just have to clear the capacity. The rate will be overwritten by the input.
167169 builder
170+ . when ( local. is_sponge . clone ( ) )
168171 . when ( local. reset . clone ( ) )
169172 . assert_zero ( local. poseidon2 . inputs [ RATE * D + i] . clone ( ) ) ;
170173
171174 // If the next row doesn't reset, propagate the capacity.
172- builder. when ( next_no_reset. clone ( ) ) . assert_zero (
173- next. poseidon2 . inputs [ RATE * D + i] . clone ( )
174- - local. poseidon2 . ending_full_rounds [ HALF_FULL_ROUNDS - 1 ] . post [ RATE * D + i]
175- . clone ( ) ,
176- ) ;
175+ builder
176+ . when ( local. is_sponge . clone ( ) )
177+ . when ( next_no_reset. clone ( ) )
178+ . assert_zero (
179+ next. poseidon2 . inputs [ RATE * D + i] . clone ( )
180+ - local. poseidon2 . ending_full_rounds [ HALF_FULL_ROUNDS - 1 ] . post [ RATE * D + i]
181+ . clone ( ) ,
182+ ) ;
177183 }
178184
179185 let mut next_absorb = [ AB :: Expr :: ZERO ; RATE ] ;
@@ -187,10 +193,14 @@ pub(crate) fn eval<
187193 for index in 0 ..( RATE * D ) {
188194 let i = index / D ;
189195 let j = index % D ;
190- builder. when ( next_no_absorb[ i] . clone ( ) ) . assert_zero (
191- next. poseidon2 . inputs [ i * D + j] . clone ( )
192- - local. poseidon2 . ending_full_rounds [ HALF_FULL_ROUNDS - 1 ] . post [ i * D + j] . clone ( ) ,
193- ) ;
196+ builder
197+ . when ( local. is_sponge . clone ( ) )
198+ . when ( next_no_absorb[ i] . clone ( ) )
199+ . assert_zero (
200+ next. poseidon2 . inputs [ i * D + j] . clone ( )
201+ - local. poseidon2 . ending_full_rounds [ HALF_FULL_ROUNDS - 1 ] . post [ i * D + j]
202+ . clone ( ) ,
203+ ) ;
194204 }
195205
196206 let mut current_absorb = [ AB :: Expr :: ZERO ; RATE ] ;
@@ -201,11 +211,15 @@ pub(crate) fn eval<
201211 }
202212 let current_no_absorb =
203213 array:: from_fn :: < _ , RATE , _ > ( |i| AB :: Expr :: ONE - current_absorb[ i] . clone ( ) ) ;
214+ builder. assert_eq (
215+ local. is_sponge . clone ( ) * local. reset . clone ( ) ,
216+ local. sponge_reset . clone ( ) ,
217+ ) ;
204218 // During a reset, the rate elements not being absorbed are zeroed.
205219 for ( i, col) in current_no_absorb. iter ( ) . enumerate ( ) . take ( RATE ) {
206220 let arr = array:: from_fn :: < _ , D , _ > ( |j| local. poseidon2 . inputs [ i * D + j] . clone ( ) . into ( ) ) ;
207221 builder
208- . when ( local. reset . clone ( ) * col. clone ( ) )
222+ . when ( local. sponge_reset . clone ( ) * col. clone ( ) )
209223 . assert_zeros ( arr) ;
210224 }
211225
@@ -215,6 +229,11 @@ pub(crate) fn eval<
215229 // * local.rate[i] comes from input lookups.
216230 // - If is_squeeze = 1:
217231 // * local.rate is sent to output lookups.
232+
233+ // COMPRESSION CONSTRAINTS
234+ // TODO: Add all lookups:
235+ // - local input state comes from input lookups.
236+ // - send local output state to output lookups.
218237}
219238
220239impl <
0 commit comments