@@ -7,7 +7,6 @@ use core::fmt::Debug;
77use derive_more:: From ;
88use derive_more:: TryInto ;
99use ergotree_ir:: sigma_protocol:: sigma_boolean:: SigmaBoolean ;
10- use ergotree_ir:: sigma_protocol:: sigma_boolean:: SigmaConjectureItems ;
1110
1211use crate :: sigma_protocol:: unproven_tree:: CandUnproven ;
1312use crate :: sigma_protocol:: unproven_tree:: UnprovenConjecture ;
@@ -136,7 +135,7 @@ pub(crate) enum ConjectureType {
136135
137136pub ( crate ) trait ProofTreeConjecture {
138137 fn conjecture_type ( & self ) -> ConjectureType ;
139- fn children ( & self ) -> SigmaConjectureItems < ProofTree > ;
138+ fn children ( & self ) -> Vec < ProofTree > ;
140139}
141140
142141pub ( crate ) enum ProofTreeKind < ' a > {
@@ -150,16 +149,20 @@ pub(crate) fn rewrite_bu<F>(tree: ProofTree, f: &F) -> Result<ProofTree, ProverE
150149where
151150 F : Fn ( & ProofTree ) -> Result < Option < ProofTree > , ProverError > ,
152151{
153- let cast_to_ust = |children : SigmaConjectureItems < ProofTree > | {
154- children. try_mapped ( |c| {
155- if let ProofTree :: UncheckedTree ( ust) = c {
156- Ok ( ust)
157- } else {
158- Err ( ProverError :: Unexpected (
159- "rewrite: expected UncheckedSigmaTree got UnprovenTree" ,
160- ) )
161- }
162- } )
152+ let cast_to_ust = |children : & [ ProofTree ] | {
153+ children
154+ . iter ( )
155+ . cloned ( )
156+ . map ( |c| {
157+ if let ProofTree :: UncheckedTree ( ust) = c {
158+ Ok ( ust)
159+ } else {
160+ Err ( ProverError :: Unexpected (
161+ "rewrite: expected UncheckedSigmaTree got UnprovenTree" ,
162+ ) )
163+ }
164+ } )
165+ . collect :: < Result < Vec < _ > , _ > > ( )
163166 } ;
164167
165168 let tree_with_updated_children = match & tree {
@@ -206,9 +209,12 @@ where
206209 challenge,
207210 children,
208211 } => {
209- let rewritten_children =
210- children. clone ( ) . try_mapped ( |c| rewrite_bu ( c. into ( ) , f) ) ?;
211- let casted_children = cast_to_ust ( rewritten_children) ?;
212+ let rewritten_children = children
213+ . iter ( )
214+ . cloned ( )
215+ . map ( |c| rewrite_bu ( c. into ( ) , f) )
216+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
217+ let casted_children = cast_to_ust ( & rewritten_children) ?;
212218 UncheckedConjecture :: CandUnchecked {
213219 children : casted_children,
214220 challenge : challenge. clone ( ) ,
@@ -219,9 +225,12 @@ where
219225 challenge,
220226 children,
221227 } => {
222- let rewritten_children =
223- children. clone ( ) . try_mapped ( |c| rewrite_bu ( c. into ( ) , f) ) ?;
224- let casted_children = cast_to_ust ( rewritten_children) ?;
228+ let rewritten_children = children
229+ . iter ( )
230+ . cloned ( )
231+ . map ( |c| rewrite_bu ( c. into ( ) , f) )
232+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
233+ let casted_children = cast_to_ust ( & rewritten_children) ?;
225234 UncheckedConjecture :: CorUnchecked {
226235 children : casted_children,
227236 challenge : challenge. clone ( ) ,
@@ -234,11 +243,14 @@ where
234243 k,
235244 polynomial : polynomial_opt,
236245 } => {
237- let rewritten_children =
238- children. clone ( ) . try_mapped ( |c| rewrite_bu ( c. into ( ) , f) ) ?;
239- let casted_children = cast_to_ust ( rewritten_children) ?;
246+ let rewritten_children = children
247+ . iter ( )
248+ . cloned ( )
249+ . map ( |c| rewrite_bu ( c. into ( ) , f) )
250+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
251+ let casted_children = cast_to_ust ( & rewritten_children) ?;
240252 UncheckedConjecture :: CthresholdUnchecked {
241- children : casted_children,
253+ children : casted_children. try_into ( ) ? ,
242254 challenge : challenge. clone ( ) ,
243255 k : * k,
244256 polynomial : polynomial_opt. clone ( ) ,
@@ -257,16 +269,20 @@ pub(crate) fn rewrite_td<F>(tree: ProofTree, f: &F) -> Result<ProofTree, ProverE
257269where
258270 F : Fn ( & ProofTree ) -> Result < Option < ProofTree > , ProverError > ,
259271{
260- let cast_to_ust = |children : SigmaConjectureItems < ProofTree > | {
261- children. try_mapped ( |c| {
262- if let ProofTree :: UncheckedTree ( ust) = c {
263- Ok ( ust)
264- } else {
265- Err ( ProverError :: Unexpected (
266- "rewrite: expected UncheckedSigmaTree got UnprovenTree" ,
267- ) )
268- }
269- } )
272+ let cast_to_ust = |children : & [ ProofTree ] | {
273+ children
274+ . iter ( )
275+ . cloned ( )
276+ . map ( |c| {
277+ if let ProofTree :: UncheckedTree ( ust) = c {
278+ Ok ( ust)
279+ } else {
280+ Err ( ProverError :: Unexpected (
281+ "rewrite: expected UncheckedSigmaTree got UnprovenTree" ,
282+ ) )
283+ }
284+ } )
285+ . collect :: < Result < Vec < _ > , _ > > ( )
270286 } ;
271287
272288 let rewritten_tree = f ( & tree) ?. unwrap_or ( tree) ;
@@ -314,9 +330,12 @@ where
314330 challenge,
315331 children,
316332 } => {
317- let rewritten_children =
318- children. clone ( ) . try_mapped ( |c| rewrite_td ( c. into ( ) , f) ) ?;
319- let casted_children = cast_to_ust ( rewritten_children) ?;
333+ let rewritten_children = children
334+ . iter ( )
335+ . cloned ( )
336+ . map ( |c| rewrite_td ( c. into ( ) , f) )
337+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
338+ let casted_children = cast_to_ust ( & rewritten_children) ?;
320339 UncheckedConjecture :: CandUnchecked {
321340 children : casted_children,
322341 challenge : challenge. clone ( ) ,
@@ -327,9 +346,12 @@ where
327346 challenge,
328347 children,
329348 } => {
330- let rewritten_children =
331- children. clone ( ) . try_mapped ( |c| rewrite_td ( c. into ( ) , f) ) ?;
332- let casted_children = cast_to_ust ( rewritten_children) ?;
349+ let rewritten_children = children
350+ . iter ( )
351+ . cloned ( )
352+ . map ( |c| rewrite_td ( c. into ( ) , f) )
353+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
354+ let casted_children = cast_to_ust ( & rewritten_children) ?;
333355 UncheckedConjecture :: CorUnchecked {
334356 children : casted_children,
335357 challenge : challenge. clone ( ) ,
@@ -343,10 +365,11 @@ where
343365 polynomial : polynomial_opt,
344366 } => {
345367 let rewritten_children =
346- children. clone ( ) . try_mapped ( |c| rewrite_td ( c. into ( ) , f) ) ?;
347- let casted_children = cast_to_ust ( rewritten_children) ?;
368+ children. try_mapped_ref ( |c| rewrite_td ( c. clone ( ) . into ( ) , f) ) ?;
369+ let casted_children = cast_to_ust ( rewritten_children. as_slice ( ) ) ?;
348370 UncheckedConjecture :: CthresholdUnchecked {
349- children : casted_children,
371+ #[ allow( clippy:: unwrap_used) ] // casted_children.len() == children.len(), so conversion can't to BoundedVec can't fail
372+ children : casted_children. try_into ( ) . unwrap ( ) ,
350373 challenge : challenge. clone ( ) ,
351374 k : * k,
352375 polynomial : polynomial_opt. clone ( ) ,
0 commit comments