Просмотр исходного кода

docs: update instance codegen terminology

Michele Orrù 5 дней назад
Родитель
Сommit
4457e39c76
2 измененных файлов с 39 добавлено и 39 удалено
  1. 3 3
      README.md
  2. 36 36
      sigma-compiler-core/src/sigma/codegen.rs

+ 3 - 3
README.md

@@ -188,9 +188,9 @@ The macro creates a submodule with the name specified by
     byte slice, and the verifier must use the same byte slice in
     byte slice, and the verifier must use the same byte slice in
     order to verify the proof.  The parameter `rng` is a random
     order to verify the proof.  The parameter `rng` is a random
     number generator that implements the [`CryptoRng`] and
     number generator that implements the [`CryptoRng`] and
-    [`Rng`] traits and supplies compiler-generated random scalars.
-    The underlying sigma proof obtains its randomness from the OS through
-    `sigma_proofs::prove_compact`.  The output, if successful, is the proof
+    [`Rng`] traits. It will be used to sample additional commitment blindings
+    when needed. The underlying Sigma proof will rely on its own private CSRNG
+    via `sigma_proofs::prove_compact`.  The output, if successful, is the proof
     as a byte vector.
     as a byte vector.
   - A function `verify` with the signature
   - A function `verify` with the signature
     ```
     ```

+ 36 - 36
sigma-compiler-core/src/sigma/codegen.rs

@@ -204,9 +204,9 @@ impl<'a> CodeGen<'a> {
     /// Generate the code for the `protocol` and `protocol_witness`
     /// Generate the code for the `protocol` and `protocol_witness`
     /// functions that create the `ComposedInstance` and `ComposedWitness`
     /// functions that create the `ComposedInstance` and `ComposedWitness`
     /// structs, respectively, given a slice of [`Expr`]s that will be
     /// structs, respectively, given a slice of [`Expr`]s that will be
-    /// bundled into a single `LinearRelation`.  The `protocol` code
-    /// must evaluate to a `Result<ComposedInstance>` and the `protocol_witness`
-    /// code must evaluate to a `Result<ComposedWitness>`.
+    /// bundled into a single `LinearRelation`. The instance code evaluates
+    /// to `Result<ComposedInstance<Point>, InvalidInstance>`; the witness
+    /// code evaluates to `Result<ComposedWitness<Point>, InvalidWitness>`.
     fn linear_relation_codegen(&self, exprs: &[&Expr]) -> (TokenStream, TokenStream) {
     fn linear_relation_codegen(&self, exprs: &[&Expr]) -> (TokenStream, TokenStream) {
         let instance_var = format_ident!("{}instance", self.unique_prefix);
         let instance_var = format_ident!("{}instance", self.unique_prefix);
         let lr_var = format_ident!("{}lr", self.unique_prefix);
         let lr_var = format_ident!("{}lr", self.unique_prefix);
@@ -478,14 +478,14 @@ impl<'a> CodeGen<'a> {
     }
     }
 
 
     /// Generate the code for the `protocol` and `protocol_witness`
     /// Generate the code for the `protocol` and `protocol_witness`
-    /// functions that create the `Protocol` and `ComposedWitness`
+    /// functions that create the `ComposedInstance` and `ComposedWitness`
     /// structs, respectively, given a [`StatementTree`] describing the
     /// structs, respectively, given a [`StatementTree`] describing the
     /// statements to be proven.  The output components are the code for
     /// statements to be proven.  The output components are the code for
     /// the `protocol` and `protocol_witness` functions, respectively.
     /// 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<ComposedWitness>`.
-    fn proto_witness_codegen(&self, statement: &StatementTree) -> (TokenStream, TokenStream) {
+    /// The instance code evaluates to
+    /// `Result<ComposedInstance<Point>, InvalidInstance>`; the witness code
+    /// evaluates to `Result<ComposedWitness<Point>, InvalidWitness>`.
+    fn instance_witness_codegen(&self, statement: &StatementTree) -> (TokenStream, TokenStream) {
         match statement {
         match statement {
             // The StatementTree has no statements (it's just the single
             // The StatementTree has no statements (it's just the single
             // leaf "true")
             // leaf "true")
@@ -515,63 +515,63 @@ impl<'a> CodeGen<'a> {
                         _ => others.push(st),
                         _ => others.push(st),
                     }
                     }
                 }
                 }
-                let (proto_code, witness_code) = self.linear_relation_codegen(&leaves);
+                let (instance_code, witness_code) = self.linear_relation_codegen(&leaves);
                 if others.is_empty() {
                 if others.is_empty() {
-                    (proto_code, witness_code)
+                    (instance_code, witness_code)
                 } else {
                 } else {
-                    let (others_proto, others_witness): (Vec<TokenStream>, Vec<TokenStream>) =
+                    let (other_instances, other_witnesses): (Vec<TokenStream>, Vec<TokenStream>) =
                         others
                         others
                             .iter()
                             .iter()
-                            .map(|st| self.proto_witness_codegen(st))
+                            .map(|st| self.instance_witness_codegen(st))
                             .unzip();
                             .unzip();
                     (
                     (
                         quote! {
                         quote! {
                             ComposedInstance::and([
                             ComposedInstance::and([
-                                #proto_code?,
-                                #(#others_proto?,)*
+                                #instance_code?,
+                                #(#other_instances?,)*
                             ])
                             ])
                         },
                         },
                         quote! {
                         quote! {
                             Result::<_, InvalidWitness>::Ok(ComposedWitness::and([
                             Result::<_, InvalidWitness>::Ok(ComposedWitness::and([
                                 #witness_code?,
                                 #witness_code?,
-                                #(#others_witness?,)*
+                                #(#other_witnesses?,)*
                             ]))
                             ]))
                         },
                         },
                     )
                     )
                 }
                 }
             }
             }
             StatementTree::Or(stvec) => {
             StatementTree::Or(stvec) => {
-                let (proto, witness): (Vec<TokenStream>, Vec<TokenStream>) = stvec
+                let (instances, witnesses): (Vec<TokenStream>, Vec<TokenStream>) = stvec
                     .iter()
                     .iter()
-                    .map(|st| self.proto_witness_codegen(st))
+                    .map(|st| self.instance_witness_codegen(st))
                     .unzip();
                     .unzip();
                 (
                 (
                     quote! {
                     quote! {
                         ComposedInstance::or([
                         ComposedInstance::or([
-                            #(#proto?,)*
+                            #(#instances?,)*
                         ])
                         ])
                     },
                     },
                     quote! {
                     quote! {
                         Result::<_, InvalidWitness>::Ok(ComposedWitness::or([
                         Result::<_, InvalidWitness>::Ok(ComposedWitness::or([
-                            #(#witness?,)*
+                            #(#witnesses?,)*
                         ]))
                         ]))
                     },
                     },
                 )
                 )
             }
             }
             StatementTree::Thresh(thresh, stvec) => {
             StatementTree::Thresh(thresh, stvec) => {
-                let (proto, witness): (Vec<TokenStream>, Vec<TokenStream>) = stvec
+                let (instances, witnesses): (Vec<TokenStream>, Vec<TokenStream>) = stvec
                     .iter()
                     .iter()
-                    .map(|st| self.proto_witness_codegen(st))
+                    .map(|st| self.instance_witness_codegen(st))
                     .unzip();
                     .unzip();
                 (
                 (
                     quote! {
                     quote! {
                         ComposedInstance::threshold(#thresh, [
                         ComposedInstance::threshold(#thresh, [
-                            #(#proto?,)*
+                            #(#instances?,)*
                         ])
                         ])
                     },
                     },
                     quote! {
                     quote! {
                         Result::<_, InvalidWitness>::Ok(ComposedWitness::threshold([
                         Result::<_, InvalidWitness>::Ok(ComposedWitness::threshold([
-                            #(#witness?,)*
+                            #(#witnesses?,)*
                         ]))
                         ]))
                     },
                     },
                 )
                 )
@@ -667,17 +667,17 @@ impl<'a> CodeGen<'a> {
             quote! {}
             quote! {}
         };
         };
 
 
-        let (protocol_code, witness_code) = self.proto_witness_codegen(self.statements);
+        let (instance_code, witness_code) = self.instance_witness_codegen(self.statements);
 
 
-        // Generate the function that creates the sigma-proofs Protocol
-        let protocol_func = {
+        // Generate the function that creates the sigma-proofs ComposedInstance
+        let instance_func = {
             let instance_var = format_ident!("{}instance", self.unique_prefix);
             let instance_var = format_ident!("{}instance", self.unique_prefix);
 
 
             quote! {
             quote! {
                 fn protocol(
                 fn protocol(
                     #instance_var: &Instance,
                     #instance_var: &Instance,
                 ) -> Result<ComposedInstance<Point>, InvalidInstance> {
                 ) -> Result<ComposedInstance<Point>, InvalidInstance> {
-                    #protocol_code
+                    #instance_code
                 }
                 }
             }
             }
         };
         };
@@ -701,8 +701,8 @@ impl<'a> CodeGen<'a> {
             let instance_var = format_ident!("{}instance", self.unique_prefix);
             let instance_var = format_ident!("{}instance", self.unique_prefix);
             let witness_var = format_ident!("{}witness", self.unique_prefix);
             let witness_var = format_ident!("{}witness", self.unique_prefix);
             let session_id_var = format_ident!("{}session_id", self.unique_prefix);
             let session_id_var = format_ident!("{}session_id", self.unique_prefix);
-            let proto_var = format_ident!("{}proto", self.unique_prefix);
-            let proto_witness_var = format_ident!("{}proto_witness", self.unique_prefix);
+            let composed_instance_var = format_ident!("{}composed_instance", self.unique_prefix);
+            let composed_witness_var = format_ident!("{}composed_witness", self.unique_prefix);
 
 
             quote! {
             quote! {
                 pub fn prove(
                 pub fn prove(
@@ -710,10 +710,10 @@ impl<'a> CodeGen<'a> {
                     #witness_var: &Witness,
                     #witness_var: &Witness,
                     #session_id_var: &[u8],
                     #session_id_var: &[u8],
                 ) -> Result<Vec<u8>, InvalidWitness> {
                 ) -> Result<Vec<u8>, InvalidWitness> {
-                    let #proto_var = protocol(#instance_var)?;
-                    let #proto_witness_var = protocol_witness(#instance_var, #witness_var)?;
+                    let #composed_instance_var = protocol(#instance_var)?;
+                    let #composed_witness_var = protocol_witness(#instance_var, #witness_var)?;
                     sigma_proofs::prove_compact(
                     sigma_proofs::prove_compact(
-                        #session_id_var, &#proto_var, &#proto_witness_var,
+                        #session_id_var, &#composed_instance_var, &#composed_witness_var,
                     )
                     )
                 }
                 }
             }
             }
@@ -726,7 +726,7 @@ impl<'a> CodeGen<'a> {
             let instance_var = format_ident!("{}instance", self.unique_prefix);
             let instance_var = format_ident!("{}instance", self.unique_prefix);
             let proof_var = format_ident!("{}proof", self.unique_prefix);
             let proof_var = format_ident!("{}proof", self.unique_prefix);
             let session_id_var = format_ident!("{}session_id", self.unique_prefix);
             let session_id_var = format_ident!("{}session_id", self.unique_prefix);
-            let proto_var = format_ident!("{}proto", self.unique_prefix);
+            let composed_instance_var = format_ident!("{}composed_instance", self.unique_prefix);
 
 
             quote! {
             quote! {
                 pub fn verify(
                 pub fn verify(
@@ -734,8 +734,8 @@ impl<'a> CodeGen<'a> {
                     #proof_var: &[u8],
                     #proof_var: &[u8],
                     #session_id_var: &[u8],
                     #session_id_var: &[u8],
                 ) -> Result<(), VerificationError> {
                 ) -> Result<(), VerificationError> {
-                    let #proto_var = protocol(#instance_var)?;
-                    sigma_proofs::verify_compact(#session_id_var, &#proto_var, #proof_var)
+                    let #composed_instance_var = protocol(#instance_var)?;
+                    sigma_proofs::verify_compact(#session_id_var, &#composed_instance_var, #proof_var)
                 }
                 }
             }
             }
         } else {
         } else {
@@ -770,7 +770,7 @@ impl<'a> CodeGen<'a> {
                 #instance_def
                 #instance_def
                 #witness_def
                 #witness_def
 
 
-                #protocol_func
+                #instance_func
                 #witness_func
                 #witness_func
                 #prove_func
                 #prove_func
                 #verify_func
                 #verify_func