1- use std:: time:: Instant ;
1+ use std:: { sync :: Arc , time:: Instant } ;
22
33use ark_crypto_primitives:: {
44 crh:: { CRHScheme , TwoToOneCRHScheme } ,
@@ -20,6 +20,7 @@ use whir::{
2020 HashCounter ,
2121 } ,
2222 } ,
23+ ntt:: { RSDefault , ReedSolomon } ,
2324 parameters:: {
2425 default_max_pow, DeduplicationStrategy , FoldingFactor , MerkleProofStrategy ,
2526 MultivariateParameters , ProtocolParameters , SoundnessType ,
@@ -89,109 +90,76 @@ fn main() {
8990 args. pow_bits = Some ( default_max_pow ( args. num_variables , args. rate ) ) ;
9091 }
9192
92- let mut rng = ark_std:: test_rng ( ) ;
93-
94- match ( field, merkle) {
95- ( AvailableFields :: Goldilocks1 , AvailableMerkle :: Blake3 ) => {
96- use fields:: Field64 as F ;
97-
98- let ( leaf_hash_params, two_to_one_params) =
99- default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
100- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
101- }
93+ runner ( & args, field, merkle) ;
94+ }
10295
103- ( AvailableFields :: Goldilocks1 , AvailableMerkle :: Keccak256 ) => {
96+ fn runner ( args : & Args , field : AvailableFields , merkle : AvailableMerkle ) {
97+ // Type reflection on field
98+ match field {
99+ AvailableFields :: Goldilocks1 => {
104100 use fields:: Field64 as F ;
105-
106- let ( leaf_hash_params, two_to_one_params) =
107- default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
108- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
101+ runner_merkle :: < F > ( args, merkle) ;
109102 }
110-
111- ( AvailableFields :: Goldilocks2 , AvailableMerkle :: Blake3 ) => {
103+ AvailableFields :: Goldilocks2 => {
112104 use fields:: Field64_2 as F ;
113-
114- let ( leaf_hash_params, two_to_one_params) =
115- default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
116- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
105+ runner_merkle :: < F > ( args, merkle) ;
117106 }
118-
119- ( AvailableFields :: Goldilocks2 , AvailableMerkle :: Keccak256 ) => {
120- use fields:: Field64_2 as F ;
121-
122- let ( leaf_hash_params, two_to_one_params) =
123- default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
124- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
125- }
126-
127- ( AvailableFields :: Goldilocks3 , AvailableMerkle :: Blake3 ) => {
107+ AvailableFields :: Goldilocks3 => {
128108 use fields:: Field64_3 as F ;
129-
130- let ( leaf_hash_params, two_to_one_params) =
131- default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
132- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
133- }
134-
135- ( AvailableFields :: Goldilocks3 , AvailableMerkle :: Keccak256 ) => {
136- use fields:: Field64_3 as F ;
137-
138- let ( leaf_hash_params, two_to_one_params) =
139- default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
140- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
109+ runner_merkle :: < F > ( args, merkle) ;
141110 }
142-
143- ( AvailableFields :: Field128 , AvailableMerkle :: Blake3 ) => {
111+ AvailableFields :: Field128 => {
144112 use fields:: Field128 as F ;
145-
146- let ( leaf_hash_params, two_to_one_params) =
147- default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
148- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
113+ runner_merkle :: < F > ( args, merkle) ;
149114 }
150-
151- ( AvailableFields :: Field128 , AvailableMerkle :: Keccak256 ) => {
152- use fields:: Field128 as F ;
153-
154- let ( leaf_hash_params, two_to_one_params) =
155- default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
156- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
157- }
158-
159- ( AvailableFields :: Field192 , AvailableMerkle :: Blake3 ) => {
115+ AvailableFields :: Field192 => {
160116 use fields:: Field192 as F ;
161-
162- let ( leaf_hash_params, two_to_one_params) =
163- default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
164- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
117+ runner_merkle :: < F > ( args, merkle) ;
165118 }
166-
167- ( AvailableFields :: Field192 , AvailableMerkle :: Keccak256 ) => {
168- use fields:: Field192 as F ;
169-
170- let ( leaf_hash_params, two_to_one_params) =
171- default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
172- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
119+ AvailableFields :: Field256 => {
120+ use fields:: Field256 as F ;
121+ runner_merkle :: < F > ( args, merkle) ;
173122 }
123+ }
124+ }
174125
175- ( AvailableFields :: Field256 , AvailableMerkle :: Blake3 ) => {
176- use fields:: Field256 as F ;
126+ fn runner_merkle < F : FftField + CanonicalSerialize > ( args : & Args , merkle : AvailableMerkle ) {
127+ let mut rng = ark_std:: test_rng ( ) ;
128+
129+ let reed_solomon = Arc :: new ( RSDefault ) ;
130+ let basefield_reed_solomon = reed_solomon. clone ( ) ;
177131
132+ // Type reflection on merkle
133+ match merkle {
134+ AvailableMerkle :: Blake3 => {
178135 let ( leaf_hash_params, two_to_one_params) =
179136 default_config :: < F , Blake3LeafHash < F > , Blake3Compress > ( & mut rng) ;
180- run_whir :: < F , Blake3MerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
137+ run_whir :: < F , Blake3MerkleTreeParams < F > > (
138+ args,
139+ reed_solomon,
140+ basefield_reed_solomon,
141+ leaf_hash_params,
142+ two_to_one_params,
143+ ) ;
181144 }
182-
183- ( AvailableFields :: Field256 , AvailableMerkle :: Keccak256 ) => {
184- use fields:: Field256 as F ;
185-
145+ AvailableMerkle :: Keccak256 => {
186146 let ( leaf_hash_params, two_to_one_params) =
187147 default_config :: < F , KeccakLeafHash < F > , KeccakCompress > ( & mut rng) ;
188- run_whir :: < F , KeccakMerkleTreeParams < F > > ( & args, leaf_hash_params, two_to_one_params) ;
148+ run_whir :: < F , KeccakMerkleTreeParams < F > > (
149+ args,
150+ reed_solomon,
151+ basefield_reed_solomon,
152+ leaf_hash_params,
153+ two_to_one_params,
154+ ) ;
189155 }
190156 }
191157}
192158
193159fn run_whir < F , MerkleConfig > (
194160 args : & Args ,
161+ reed_solomon : Arc < dyn ReedSolomon < F > > ,
162+ basefield_reed_solomon : Arc < dyn ReedSolomon < F :: BasePrimeField > > ,
195163 leaf_hash_params : <<MerkleConfig as Config >:: LeafHash as CRHScheme >:: Parameters ,
196164 two_to_one_params : <<MerkleConfig as Config >:: TwoToOneHash as TwoToOneCRHScheme >:: Parameters ,
197165) where
@@ -204,16 +172,30 @@ fn run_whir<F, MerkleConfig>(
204172{
205173 match args. protocol_type {
206174 WhirType :: PCS => {
207- run_whir_pcs :: < F , MerkleConfig > ( args, leaf_hash_params, two_to_one_params) ;
175+ run_whir_pcs :: < F , MerkleConfig > (
176+ args,
177+ reed_solomon,
178+ basefield_reed_solomon,
179+ leaf_hash_params,
180+ two_to_one_params,
181+ ) ;
208182 }
209183 WhirType :: LDT => {
210- run_whir_as_ldt :: < F , MerkleConfig > ( args, leaf_hash_params, two_to_one_params) ;
184+ run_whir_as_ldt :: < F , MerkleConfig > (
185+ args,
186+ reed_solomon,
187+ basefield_reed_solomon,
188+ leaf_hash_params,
189+ two_to_one_params,
190+ ) ;
211191 }
212192 }
213193}
214194
215195fn run_whir_as_ldt < F , MerkleConfig > (
216196 args : & Args ,
197+ reed_solomon : Arc < dyn ReedSolomon < F > > ,
198+ basefield_reed_solomon : Arc < dyn ReedSolomon < F :: BasePrimeField > > ,
217199 leaf_hash_params : <<MerkleConfig as Config >:: LeafHash as CRHScheme >:: Parameters ,
218200 two_to_one_params : <<MerkleConfig as Config >:: TwoToOneHash as TwoToOneCRHScheme >:: Parameters ,
219201) where
@@ -265,7 +247,12 @@ fn run_whir_as_ldt<F, MerkleConfig>(
265247 merkle_proof_strategy : MerkleProofStrategy :: Compressed ,
266248 } ;
267249
268- let params = WhirConfig :: < F , MerkleConfig , PowStrategy > :: new ( mv_params, whir_params) ;
250+ let params = WhirConfig :: < F , MerkleConfig , PowStrategy > :: new (
251+ reed_solomon,
252+ basefield_reed_solomon,
253+ mv_params,
254+ whir_params,
255+ ) ;
269256
270257 let domainsep = DomainSeparator :: new ( "🌪️" )
271258 . commit_statement ( & params)
@@ -328,6 +315,8 @@ fn run_whir_as_ldt<F, MerkleConfig>(
328315#[ allow( clippy:: too_many_lines) ]
329316fn run_whir_pcs < F , MerkleConfig > (
330317 args : & Args ,
318+ reed_solomon : Arc < dyn ReedSolomon < F > > ,
319+ basefield_reed_solomon : Arc < dyn ReedSolomon < F :: BasePrimeField > > ,
331320 leaf_hash_params : <<MerkleConfig as Config >:: LeafHash as CRHScheme >:: Parameters ,
332321 two_to_one_params : <<MerkleConfig as Config >:: TwoToOneHash as TwoToOneCRHScheme >:: Parameters ,
333322) where
@@ -381,7 +370,12 @@ fn run_whir_pcs<F, MerkleConfig>(
381370 merkle_proof_strategy : MerkleProofStrategy :: Compressed ,
382371 } ;
383372
384- let params = WhirConfig :: < F , MerkleConfig , PowStrategy > :: new ( mv_params, whir_params) ;
373+ let params = WhirConfig :: < F , MerkleConfig , PowStrategy > :: new (
374+ reed_solomon,
375+ basefield_reed_solomon,
376+ mv_params,
377+ whir_params,
378+ ) ;
385379
386380 let domainsep = DomainSeparator :: new ( "🌪️" )
387381 . commit_statement ( & params)
0 commit comments