File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,18 @@ impl Poseidon2 {
2525
2626 fn perform_duplex (&mut self ) {
2727 // add the cache into sponge state
28- for i in 0 ..RATE {
29- // We effectively zero-pad the cache by only adding to the state
30- // cache that is less than the specified `cache_size`
31- if i < self .cache_size {
28+ if std::runtime:: is_unconstrained () {
29+ for i in 0 ..self .cache_size {
3230 self .state [i ] += self .cache [i ];
3331 }
32+ } else {
33+ for i in 0 ..RATE {
34+ // We effectively zero-pad the cache by only adding to the state
35+ // cache that is less than the specified `cache_size`
36+ if i < self .cache_size {
37+ self .state [i ] += self .cache [i ];
38+ }
39+ }
3440 }
3541 self .state = crate ::poseidon2_permutation (self .state , 4 );
3642 }
@@ -63,10 +69,16 @@ impl Poseidon2 {
6369 let two_pow_64 = 18446744073709551616 ;
6470 let iv : Field = (in_len as Field ) * two_pow_64 ;
6571 let mut sponge = Poseidon2 ::new (iv );
66- for i in 0 .. input . len () {
67- if i < in_len {
72+ if std::runtime:: is_unconstrained () {
73+ for i in 0 .. in_len {
6874 sponge .absorb (input [i ]);
6975 }
76+ } else {
77+ for i in 0 ..input .len () {
78+ if i < in_len {
79+ sponge .absorb (input [i ]);
80+ }
81+ }
7082 }
7183 sponge .squeeze ()
7284 }
You can’t perform that action at this time.
0 commit comments