@@ -100,11 +100,6 @@ impl<E: PoseidonEngine> QuinticSBox<E> {
100100 }
101101}
102102
103- // pub fn poseidon_tree_hash<E: PoseidonEngine<SBox = QuinticSBox<E> >, CS>(
104- // mut cs: CS,
105- // elements: &[AllocatedNum<E>],
106- // params: &E::Params
107-
108103pub fn poseidon_hash < E : PoseidonEngine < SBox = QuinticSBox < E > > , CS > (
109104 mut cs : CS ,
110105 input : & [ AllocatedNum < E > ] ,
@@ -311,6 +306,12 @@ fn poseidon_mimc_round<E: PoseidonEngine<SBox = QuinticSBox<E> >, CS>(
311306 round += 1 ;
312307 }
313308
309+ // up to this point we always made a well-formed LC that later was collapsed into
310+ // a signel variable after non-linearity application
311+ // now we need to make linear combinations of linear combinations, so basically make
312+ // filtering and joining. It's actually possible to just separate MSD matrix into
313+ // three in later optimizations
314+
314315 // now we need to apply full SBox of the last full round, then do linear
315316 // transformation and add first round constants before going through partial rounds
316317 {
@@ -329,6 +330,9 @@ fn poseidon_mimc_round<E: PoseidonEngine<SBox = QuinticSBox<E> >, CS>(
329330 add_round_constants :: < E , CS > ( params, & mut linear_transformation_results[ ..] , 0 , false ) ;
330331 state = linear_transformation_results;
331332
333+ // up to this point linear combinations are well-formed and have number
334+ // of terms equal to the number of variables in the state
335+
332336 round += 1 ;
333337 }
334338
@@ -462,7 +466,7 @@ mod test {
462466 let mut rng = XorShiftRng :: from_seed ( [ 0x3dbe6259 , 0x8d313d76 , 0x3237db17 , 0xe5bc0654 ] ) ;
463467 let params = Bn256PoseidonParams :: new :: < BlakeHasher > ( ) ;
464468 let input: Vec < Fr > = ( 0 ..params. t ( ) ) . map ( |_| rng. gen ( ) ) . collect ( ) ;
465- let expected = poseidon:: poseidon_hash :: < Bn256 > ( & params, & input[ ..] ) ;
469+ let expected = poseidon:: poseidon_mimc :: < Bn256 > ( & params, & input[ ..] ) ;
466470
467471 {
468472 let mut cs = TestConstraintSystem :: < Bn256 > :: new ( ) ;
@@ -482,7 +486,7 @@ mod test {
482486 ) . unwrap ( ) ;
483487
484488 assert ! ( cs. is_satisfied( ) ) ;
485- assert ! ( res. len( ) == 1 ) ;
489+ assert ! ( res. len( ) == ( params . t ( ) as usize ) ) ;
486490
487491 assert_eq ! ( res[ 0 ] . get_value( ) . unwrap( ) , expected[ 0 ] ) ;
488492 }
0 commit comments