11use openvm_native_compiler_derive:: iter_zip;
22use openvm_stark_backend:: p3_field:: FieldAlgebra ;
33
4- use crate :: ir:: Variable ;
5-
64use super :: { Array , ArrayLike , Builder , Config , DslIr , Ext , Felt , MemIndex , Ptr , Usize , Var } ;
5+ use crate :: ir:: Variable ;
76
87pub const DIGEST_SIZE : usize = 8 ;
98pub const HASH_RATE : usize = 8 ;
109pub const PERMUTATION_WIDTH : usize = 16 ;
1110
1211impl < C : Config > Builder < C > {
1312 /// Extends native VM ability to observe multiple base elements in one opcode operation
14- /// Absorbs elements sequentially at the RATE portion of sponge state and performs as many permutations as necessary.
15- /// Returns the index position of the next input_ptr.
16- ///
13+ /// Absorbs elements sequentially at the RATE portion of sponge state and performs as many
14+ /// permutations as necessary. Returns the index position of the next input_ptr.
15+ ///
1716 /// [Reference](https://docs.rs/p3-poseidon2/latest/p3_poseidon2/struct.Poseidon2.html)
1817 pub fn poseidon2_multi_observe (
1918 & mut self ,
20- sponge_state : & Array < C , Felt < C :: F > > ,
19+ sponge_state : & Array < C , Felt < C :: F > > ,
2120 input_ptr : Ptr < C :: N > ,
2221 arr : & Array < C , Felt < C :: F > > ,
2322 ) -> Usize < C :: N > {
@@ -28,26 +27,24 @@ impl<C: Config> Builder<C> {
2827 Array :: Fixed ( _) => {
2928 panic ! ( "Poseidon2 permutation is not allowed on fixed arrays" ) ;
3029 }
31- Array :: Dyn ( sponge_ptr, _) => {
32- match arr {
33- Array :: Fixed ( _) => {
34- panic ! ( "Base elements input must be dynamic" ) ;
35- }
36- Array :: Dyn ( ptr, len) => {
37- let init_pos: Var < C :: N > = Var :: uninit ( self ) ;
38- self . assign ( & init_pos, input_ptr. address - sponge_ptr. address ) ;
39-
40- self . operations . push ( DslIr :: Poseidon2MultiObserve (
41- * sponge_ptr,
42- init_pos,
43- * ptr,
44- len. clone ( ) ,
45- ) ) ;
46-
47- Usize :: Var ( init_pos)
48- }
30+ Array :: Dyn ( sponge_ptr, _) => match arr {
31+ Array :: Fixed ( _) => {
32+ panic ! ( "Base elements input must be dynamic" ) ;
4933 }
50- }
34+ Array :: Dyn ( ptr, len) => {
35+ let init_pos: Var < C :: N > = Var :: uninit ( self ) ;
36+ self . assign ( & init_pos, input_ptr. address - sponge_ptr. address ) ;
37+
38+ self . operations . push ( DslIr :: Poseidon2MultiObserve (
39+ * sponge_ptr,
40+ init_pos,
41+ * ptr,
42+ len. clone ( ) ,
43+ ) ) ;
44+
45+ Usize :: Var ( init_pos)
46+ }
47+ } ,
5148 }
5249 }
5350
0 commit comments