Browse Source

fix: update refactor

Michele Orrù 3 months ago
parent
commit
6d13649911
4 changed files with 28 additions and 26 deletions
  1. 1 1
      Cargo.toml
  2. 23 23
      sigma_compiler_core/src/sigma/codegen.rs
  3. 2 1
      tests/disj.rs
  4. 2 1
      tests/simple_or.rs

+ 1 - 1
Cargo.toml

@@ -7,7 +7,7 @@ edition = "2021"
 sigma_compiler_derive = { path = "sigma_compiler_derive" }
 group = "0.13"
 rand = "0.8.5"
-sigma-rs = { path = "../sigma" }
+sigma-rs = { path = "../sigma-rs" }
 subtle = "2.6"
 
 [dev-dependencies]

+ 23 - 23
sigma_compiler_core/src/sigma/codegen.rs

@@ -183,11 +183,11 @@ impl<'a> CodeGen<'a> {
     }
 
     /// Generate the code for the `protocol` and `protocol_witness`
-    /// functions that create the `Protocol` and `ProtocolWitness`
+    /// functions that create the [`ComposedRelation`] and `ComposedWitness`
     /// structs, respectively, given a slice of [`Expr`]s that will be
     /// bundled into a single `LinearRelation`.  The `protocol` code
-    /// must evaluate to a `Result<Protocol>` and the `protocol_witness`
-    /// code must evaluate to a `Result<ProtocolWitness>`.
+    /// must evaluate to a `Result<ComposedRelation>` and the `protocol_witness`
+    /// code must evaluate to a `Result<ComposedWitness>`.
     fn linear_relation_codegen(&self, exprs: &[&Expr]) -> (TokenStream, TokenStream) {
         let instance_var = format_ident!("{}instance", self.unique_prefix);
         let lr_var = format_ident!("{}lr", self.unique_prefix);
@@ -420,7 +420,7 @@ impl<'a> CodeGen<'a> {
                     #eq_code
                     #element_assigns
 
-                    Ok(Protocol::from(#lr_var))
+                    Ok(ComposedRelation::from(#lr_var))
                 }
             },
             quote! {
@@ -428,30 +428,30 @@ impl<'a> CodeGen<'a> {
                     #witness_vec_code
                     let mut witnessvec = Vec::new();
                     #witness_code
-                    Ok(ProtocolWitness::Simple(witnessvec))
+                    Ok(ComposedWitness::Simple(witnessvec))
                 }
             },
         )
     }
 
     /// Generate the code for the `protocol` and `protocol_witness`
-    /// functions that create the `Protocol` and `ProtocolWitness`
+    /// functions that create the `Protocol` and `ComposedWitness`
     /// structs, respectively, given a [`StatementTree`] describing the
     /// statements to be proven.  The output components are the code for
     /// the `protocol` and `protocol_witness` functions, respectively.
     /// The `protocol` code must evaluate to a `Result<Protocol>` and
     /// the `protocol_witness` code must evaluate to a
-    /// `Result<ProtocolWitness>`.
+    /// `Result<ComposedWitness>`.
     fn proto_witness_codegen(&self, statement: &StatementTree) -> (TokenStream, TokenStream) {
         match statement {
             // The StatementTree has no statements (it's just the single
             // leaf "true")
             StatementTree::Leaf(_) if statement.is_leaf_true() => (
                 quote! {
-                    Ok(Protocol::from(LinearRelation::<Point>::new()))
+                    Ok(ComposedRelation::from(LinearRelation::<Point>::new()))
                 },
                 quote! {
-                    Ok(ProtocolWitness::Simple(vec![]))
+                    Ok(ComposedWitness::Simple(vec![]))
                 },
             ),
             // The StatementTree is a single statement.  Generate a
@@ -483,15 +483,15 @@ impl<'a> CodeGen<'a> {
                             .unzip();
                     (
                         quote! {
-                            Ok(Protocol::And(vec![
-                                #proto_code?,
-                                #(#others_proto?,)*
+                            Ok(ComposedRelation::And(vec![
+                                #proto_code.map_err(|e| -> SigmaError { e })?,
+                                #(#others_proto.map_err(|e| -> SigmaError { e })?,)*
                             ]))
                         },
                         quote! {
-                            Ok(ProtocolWitness::And(vec![
-                                #witness_code?,
-                                #(#others_witness?,)*
+                            Ok(ComposedWitness::And(vec![
+                                #witness_code.map_err(|e| -> SigmaError { e })?,
+                                #(#others_witness.map_err(|e| -> SigmaError { e })?,)*
                             ]))
                         },
                     )
@@ -504,15 +504,15 @@ impl<'a> CodeGen<'a> {
                     .unzip();
                 (
                     quote! {
-                        Ok(Protocol::Or(vec![
-                            #(#proto?,)*
+                        Ok(ComposedRelation::Or(vec![
+                            #(#proto.map_err(|e| -> SigmaError { e })?,)*
                         ]))
                     },
                     // TODO: Choose the correct branch for the witness
                     // (currently hardcoded at 0)
                     quote! {
-                        Ok(ProtocolWitness::Or(0, vec![
-                            #(#witness?,)*
+                        Ok(ComposedWitness::Or(0, vec![
+                            #(#witness.map_err(|e| -> SigmaError { e })?,)*
                         ]))
                     },
                 )
@@ -611,19 +611,19 @@ impl<'a> CodeGen<'a> {
             quote! {
                 fn protocol(
                     #instance_var: &Instance,
-                ) -> Result<Protocol<Point>, SigmaError> {
+                ) -> Result<ComposedRelation<Point>, SigmaError> {
                     #protocol_code
                 }
             }
         };
 
-        // Generate the function that creates the sigma-rs ProtocolWitness
+        // Generate the function that creates the sigma-rs ComposedWitness
         let witness_func = if emit_prover {
             quote! {
                 fn protocol_witness(
                     instance: &Instance,
                     witness: &Witness,
-                ) -> Result<ProtocolWitness<Point>, SigmaError> {
+                ) -> Result<ComposedWitness<Point>, SigmaError> {
                     #witness_code
                 }
             }
@@ -727,7 +727,7 @@ impl<'a> CodeGen<'a> {
                 use sigma_compiler::sigma_rs;
                 use sigma_rs::{
                     codec::Shake128DuplexSponge,
-                    composition::{Protocol, ProtocolWitness},
+                    composition::{ComposedRelation, ComposedWitness},
                     errors::Error as SigmaError,
                     LinearRelation, Nizk,
                 };

+ 2 - 1
tests/disj.rs

@@ -29,5 +29,6 @@ fn disj_test() -> Result<(), sigma_rs::errors::Error> {
     let witness = proof::Witness { x, r };
 
     let proof = proof::prove(&instance, &witness, b"disj_test", &mut rng)?;
-    proof::verify(&instance, &proof, b"disj_test")
+    proof::verify(&instance, &proof, b"disj_test")?;
+    Ok(())
 }

+ 2 - 1
tests/simple_or.rs

@@ -27,5 +27,6 @@ fn simple_or_test() -> Result<(), sigma_rs::errors::Error> {
     let witness = proof::Witness { x, y };
 
     let proof = proof::prove(&instance, &witness, b"simple_or_test", &mut rng)?;
-    proof::verify(&instance, &proof, b"simple_or_test")
+    proof::verify(&instance, &proof, b"simple_or_test")?;
+    Ok(())
 }