@@ -262,180 +262,6 @@ impl Operation {
262262 OperationType :: Custom ( cpr) => Self :: Custom ( cpr, args. to_vec ( ) ) ,
263263 } )
264264 }
265- /// Gives the output statement of the given operation, where determined
266- /// A ValueOf statement is not determined by the NewEntry operation, so returns Ok(None)
267- /// The outer Result is error handling
268- pub fn output_statement ( & self ) -> Result < Option < Statement > > {
269- use Statement :: * ;
270- let pred: Option < Predicate > = self . op_type ( ) . output_predicate ( ) ;
271-
272- let st_args: Option < Vec < StatementArg > > = match self {
273- Self :: None => Some ( vec ! [ ] ) ,
274- Self :: NewEntry => Option :: None ,
275- Self :: CopyStatement ( s1) => Some ( s1. args ( ) ) ,
276- Self :: EqualFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) ) => {
277- if v1 == v2 {
278- Some ( vec ! [
279- StatementArg :: Key ( ak1. clone( ) ) ,
280- StatementArg :: Key ( ak2. clone( ) ) ,
281- ] )
282- } else {
283- return Err ( anyhow ! ( "Invalid operation" ) ) ;
284- }
285- }
286- Self :: EqualFromEntries ( _, _) => {
287- return Err ( anyhow ! ( "Invalid operation" ) ) ;
288- }
289- Self :: NotEqualFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) ) => {
290- if v1 != v2 {
291- Some ( vec ! [
292- StatementArg :: Key ( ak1. clone( ) ) ,
293- StatementArg :: Key ( ak2. clone( ) ) ,
294- ] )
295- } else {
296- return Err ( anyhow ! ( "Invalid operation" ) ) ;
297- }
298- }
299- Self :: NotEqualFromEntries ( _, _) => {
300- return Err ( anyhow ! ( "Invalid operation" ) ) ;
301- }
302- Self :: GtFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) ) => {
303- if v1 > v2 {
304- Some ( vec ! [
305- StatementArg :: Key ( ak1. clone( ) ) ,
306- StatementArg :: Key ( ak2. clone( ) ) ,
307- ] )
308- } else {
309- return Err ( anyhow ! ( "Invalid operation" ) ) ;
310- }
311- }
312- Self :: GtFromEntries ( _, _) => {
313- return Err ( anyhow ! ( "Invalid operation" ) ) ;
314- }
315- Self :: LtFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) ) => {
316- if v1 < v2 {
317- Some ( vec ! [
318- StatementArg :: Key ( ak1. clone( ) ) ,
319- StatementArg :: Key ( ak2. clone( ) ) ,
320- ] )
321- } else {
322- return Err ( anyhow ! ( "Invalid operation" ) ) ;
323- }
324- }
325- Self :: LtFromEntries ( _, _) => {
326- return Err ( anyhow ! ( "Invalid operation" ) ) ;
327- }
328- Self :: TransitiveEqualFromStatements ( Equal ( ak1, ak2) , Equal ( ak3, ak4) ) => {
329- if ak2 == ak3 {
330- Some ( vec ! [
331- StatementArg :: Key ( ak1. clone( ) ) ,
332- StatementArg :: Key ( ak4. clone( ) ) ,
333- ] )
334- } else {
335- return Err ( anyhow ! ( "Invalid operation" ) ) ;
336- }
337- }
338- Self :: TransitiveEqualFromStatements ( _, _) => {
339- return Err ( anyhow ! ( "Invalid operation" ) ) ;
340- }
341- Self :: GtToNotEqual ( Gt ( ak1, ak2) ) => Some ( vec ! [
342- StatementArg :: Key ( ak1. clone( ) ) ,
343- StatementArg :: Key ( ak2. clone( ) ) ,
344- ] ) ,
345- Self :: GtToNotEqual ( _) => {
346- return Err ( anyhow ! ( "Invalid operation" ) ) ;
347- }
348- Self :: LtToNotEqual ( Gt ( ak1, ak2) ) => Some ( vec ! [
349- StatementArg :: Key ( ak1. clone( ) ) ,
350- StatementArg :: Key ( ak2. clone( ) ) ,
351- ] ) ,
352- Self :: LtToNotEqual ( _) => {
353- return Err ( anyhow ! ( "Invalid operation" ) ) ;
354- }
355- Self :: ContainsFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) , ValueOf ( ak3, v3) , pf)
356- if MerkleTree :: verify ( pf. siblings . len ( ) , v1. into ( ) , pf, & v2. raw ( ) , & v3. raw ( ) )
357- . is_ok ( ) =>
358- {
359- Some ( vec ! [
360- StatementArg :: Key ( ak1. clone( ) ) ,
361- StatementArg :: Key ( ak2. clone( ) ) ,
362- StatementArg :: Key ( ak3. clone( ) ) ,
363- ] )
364- }
365- Self :: ContainsFromEntries ( _, _, _, _) => {
366- return Err ( anyhow ! ( "Invalid operation" ) ) ;
367- }
368- Self :: NotContainsFromEntries ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) , pf)
369- if MerkleTree :: verify_nonexistence ( pf. siblings . len ( ) , v1. into ( ) , pf, & v2. raw ( ) )
370- . is_ok ( ) =>
371- {
372- Some ( vec ! [
373- StatementArg :: Key ( ak1. clone( ) ) ,
374- StatementArg :: Key ( ak2. clone( ) ) ,
375- ] )
376- }
377- Self :: NotContainsFromEntries ( _, _, _) => {
378- return Err ( anyhow ! ( "Invalid operation" ) ) ;
379- }
380- Self :: SumOf ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) , ValueOf ( ak3, v3) ) => {
381- let v1: i64 = v1. typed ( ) . try_into ( ) ?;
382- let v2: i64 = v2. typed ( ) . try_into ( ) ?;
383- let v3: i64 = v3. typed ( ) . try_into ( ) ?;
384- if v1 == v2 + v3 {
385- Some ( vec ! [
386- StatementArg :: Key ( ak1. clone( ) ) ,
387- StatementArg :: Key ( ak2. clone( ) ) ,
388- StatementArg :: Key ( ak3. clone( ) ) ,
389- ] )
390- } else {
391- return Err ( anyhow ! ( "Invalid operation" ) ) ;
392- }
393- }
394- Self :: SumOf ( _, _, _) => {
395- return Err ( anyhow ! ( "Invalid operation" ) ) ;
396- }
397- Self :: ProductOf ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) , ValueOf ( ak3, v3) ) => {
398- let v1: i64 = v1. typed ( ) . try_into ( ) ?;
399- let v2: i64 = v2. typed ( ) . try_into ( ) ?;
400- let v3: i64 = v3. typed ( ) . try_into ( ) ?;
401- if v1 == v2 * v3 {
402- Some ( vec ! [
403- StatementArg :: Key ( ak1. clone( ) ) ,
404- StatementArg :: Key ( ak2. clone( ) ) ,
405- StatementArg :: Key ( ak3. clone( ) ) ,
406- ] )
407- } else {
408- return Err ( anyhow ! ( "Invalid operation" ) ) ;
409- }
410- }
411- Self :: ProductOf ( _, _, _) => {
412- return Err ( anyhow ! ( "Invalid operation" ) ) ;
413- }
414- Self :: MaxOf ( ValueOf ( ak1, v1) , ValueOf ( ak2, v2) , ValueOf ( ak3, v3) ) => {
415- let v1: i64 = v1. typed ( ) . try_into ( ) ?;
416- let v2: i64 = v2. typed ( ) . try_into ( ) ?;
417- let v3: i64 = v3. typed ( ) . try_into ( ) ?;
418- if v1 == std:: cmp:: max ( v2, v3) {
419- Some ( vec ! [
420- StatementArg :: Key ( ak1. clone( ) ) ,
421- StatementArg :: Key ( ak2. clone( ) ) ,
422- StatementArg :: Key ( ak3. clone( ) ) ,
423- ] )
424- } else {
425- return Err ( anyhow ! ( "Invalid operation" ) ) ;
426- }
427- }
428- Self :: MaxOf ( _, _, _) => {
429- return Err ( anyhow ! ( "Invalid operation" ) ) ;
430- }
431- Self :: Custom ( _, _) => todo ! ( ) ,
432- } ;
433-
434- let x: Option < Result < Statement > > = pred
435- . zip ( st_args)
436- . map ( |( pred, st_args) | Statement :: from_args ( pred, st_args) ) ;
437- x. transpose ( )
438- }
439265 /// Checks the given operation against a statement, and prints information if the check does not pass
440266 pub fn check_and_log ( & self , params : & Params , output_statement : & Statement ) -> Result < bool > {
441267 let valid: bool = self . check ( params, output_statement) ?;
0 commit comments