|
@@ -202,10 +202,10 @@ 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 `ComposedRelation` 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
|
|
/// bundled into a single `LinearRelation`. The `protocol` code
|
|
|
- /// must evaluate to a `Result<ComposedRelation>` and the `protocol_witness`
|
|
|
|
|
|
|
+ /// must evaluate to a `Result<ComposedInstance>` and the `protocol_witness`
|
|
|
/// code must evaluate to a `Result<ComposedWitness>`.
|
|
/// code must evaluate to a `Result<ComposedWitness>`.
|
|
|
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);
|
|
@@ -260,7 +260,7 @@ impl<'a> CodeGen<'a> {
|
|
|
vec_param_vars.insert(id.clone());
|
|
vec_param_vars.insert(id.clone());
|
|
|
Ok(quote! {#instance_var.#id})
|
|
Ok(quote! {#instance_var.#id})
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }, false)
|
|
|
.unwrap();
|
|
.unwrap();
|
|
|
let AExprType::Point {
|
|
let AExprType::Point {
|
|
|
is_pub: true,
|
|
is_pub: true,
|
|
@@ -356,7 +356,7 @@ impl<'a> CodeGen<'a> {
|
|
|
}
|
|
}
|
|
|
Ok(quote! { #id })
|
|
Ok(quote! { #id })
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }, true)
|
|
|
else {
|
|
else {
|
|
|
let expr_str = quote! { #expr }.to_string();
|
|
let expr_str = quote! { #expr }.to_string();
|
|
|
panic!("Right side of = is not a valid arithmetic expression: {expr_str}");
|
|
panic!("Right side of = is not a valid arithmetic expression: {expr_str}");
|
|
@@ -386,12 +386,11 @@ impl<'a> CodeGen<'a> {
|
|
|
param_vec_code = quote! {
|
|
param_vec_code = quote! {
|
|
|
#param_vec_code
|
|
#param_vec_code
|
|
|
if #vec_len_var != #instance_var.#thisvar.len() {
|
|
if #vec_len_var != #instance_var.#thisvar.len() {
|
|
|
- eprintln!(
|
|
|
|
|
|
|
+ return Err(InvalidInstance::new(format!(
|
|
|
"Instance variables {} and {} must have the same length",
|
|
"Instance variables {} and {} must have the same length",
|
|
|
stringify!(#firstvar),
|
|
stringify!(#firstvar),
|
|
|
stringify!(#thisvar),
|
|
stringify!(#thisvar),
|
|
|
- );
|
|
|
|
|
- return Err(SigmaError::VerificationFailure);
|
|
|
|
|
|
|
+ )));
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -410,7 +409,7 @@ impl<'a> CodeGen<'a> {
|
|
|
stringify!(#firstvar),
|
|
stringify!(#firstvar),
|
|
|
stringify!(#witvar),
|
|
stringify!(#witvar),
|
|
|
);
|
|
);
|
|
|
- return Err(SigmaError::VerificationFailure);
|
|
|
|
|
|
|
+ return Err(InvalidWitness);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -453,7 +452,7 @@ impl<'a> CodeGen<'a> {
|
|
|
#eq_code
|
|
#eq_code
|
|
|
#element_assigns
|
|
#element_assigns
|
|
|
|
|
|
|
|
- SigmaOk(ComposedRelation::try_from(#lr_var).unwrap())
|
|
|
|
|
|
|
+ ComposedInstance::try_from(#lr_var)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
quote! {
|
|
quote! {
|
|
@@ -461,7 +460,7 @@ impl<'a> CodeGen<'a> {
|
|
|
#witness_vec_code
|
|
#witness_vec_code
|
|
|
let mut witnessvec = Vec::new();
|
|
let mut witnessvec = Vec::new();
|
|
|
#witness_code
|
|
#witness_code
|
|
|
- SigmaOk(ComposedWitness::Simple(witnessvec))
|
|
|
|
|
|
|
+ ProverResult::Ok(ComposedWitness::Simple(witnessvec))
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
@@ -481,10 +480,10 @@ impl<'a> CodeGen<'a> {
|
|
|
// leaf "true")
|
|
// leaf "true")
|
|
|
StatementTree::Leaf(_) if statement.is_leaf_true() => (
|
|
StatementTree::Leaf(_) if statement.is_leaf_true() => (
|
|
|
quote! {
|
|
quote! {
|
|
|
- Ok(ComposedRelation::try_from(LinearRelation::<Point>::new()).unwrap())
|
|
|
|
|
|
|
+ InstanceResult::Ok(ComposedInstance::try_from(LinearRelation::<Point>::new()).unwrap())
|
|
|
},
|
|
},
|
|
|
quote! {
|
|
quote! {
|
|
|
- Ok(ComposedWitness::Simple(vec![]))
|
|
|
|
|
|
|
+ ProverResult::Ok(ComposedWitness::Simple(vec![]))
|
|
|
},
|
|
},
|
|
|
),
|
|
),
|
|
|
// The StatementTree is a single statement. Generate a
|
|
// The StatementTree is a single statement. Generate a
|
|
@@ -516,13 +515,13 @@ impl<'a> CodeGen<'a> {
|
|
|
.unzip();
|
|
.unzip();
|
|
|
(
|
|
(
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedRelation::and([
|
|
|
|
|
|
|
+ ComposedInstance::and([
|
|
|
#proto_code?,
|
|
#proto_code?,
|
|
|
#(#others_proto?,)*
|
|
#(#others_proto?,)*
|
|
|
- ]))
|
|
|
|
|
|
|
+ ])
|
|
|
},
|
|
},
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedWitness::and([
|
|
|
|
|
|
|
+ ProverResult::Ok(ComposedWitness::and([
|
|
|
#witness_code?,
|
|
#witness_code?,
|
|
|
#(#others_witness?,)*
|
|
#(#others_witness?,)*
|
|
|
]))
|
|
]))
|
|
@@ -537,12 +536,12 @@ impl<'a> CodeGen<'a> {
|
|
|
.unzip();
|
|
.unzip();
|
|
|
(
|
|
(
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedRelation::or([
|
|
|
|
|
|
|
+ ComposedInstance::or([
|
|
|
#(#proto?,)*
|
|
#(#proto?,)*
|
|
|
- ]))
|
|
|
|
|
|
|
+ ])
|
|
|
},
|
|
},
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedWitness::or([
|
|
|
|
|
|
|
+ ProverResult::Ok(ComposedWitness::or([
|
|
|
#(#witness?,)*
|
|
#(#witness?,)*
|
|
|
]))
|
|
]))
|
|
|
},
|
|
},
|
|
@@ -555,12 +554,12 @@ impl<'a> CodeGen<'a> {
|
|
|
.unzip();
|
|
.unzip();
|
|
|
(
|
|
(
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedRelation::threshold(#thresh, [
|
|
|
|
|
|
|
+ ComposedInstance::threshold(#thresh, [
|
|
|
#(#proto?,)*
|
|
#(#proto?,)*
|
|
|
- ]))
|
|
|
|
|
|
|
+ ])
|
|
|
},
|
|
},
|
|
|
quote! {
|
|
quote! {
|
|
|
- SigmaOk(ComposedWitness::threshold([
|
|
|
|
|
|
|
+ ProverResult::Ok(ComposedWitness::threshold([
|
|
|
#(#witness?,)*
|
|
#(#witness?,)*
|
|
|
]))
|
|
]))
|
|
|
},
|
|
},
|
|
@@ -666,7 +665,7 @@ impl<'a> CodeGen<'a> {
|
|
|
quote! {
|
|
quote! {
|
|
|
fn protocol(
|
|
fn protocol(
|
|
|
#instance_var: &Instance,
|
|
#instance_var: &Instance,
|
|
|
- ) -> SigmaResult<ComposedRelation<Point>> {
|
|
|
|
|
|
|
+ ) -> Result<ComposedInstance<Point>, InvalidInstance> {
|
|
|
#protocol_code
|
|
#protocol_code
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -678,7 +677,7 @@ impl<'a> CodeGen<'a> {
|
|
|
fn protocol_witness(
|
|
fn protocol_witness(
|
|
|
instance: &Instance,
|
|
instance: &Instance,
|
|
|
witness: &Witness,
|
|
witness: &Witness,
|
|
|
- ) -> SigmaResult<ComposedWitness<Point>> {
|
|
|
|
|
|
|
+ ) -> Result<ComposedWitness<Point>, InvalidWitness> {
|
|
|
#witness_code
|
|
#witness_code
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -694,7 +693,6 @@ impl<'a> CodeGen<'a> {
|
|
|
let rng_var = format_ident!("{}rng", self.unique_prefix);
|
|
let rng_var = format_ident!("{}rng", self.unique_prefix);
|
|
|
let proto_var = format_ident!("{}proto", self.unique_prefix);
|
|
let proto_var = format_ident!("{}proto", self.unique_prefix);
|
|
|
let proto_witness_var = format_ident!("{}proto_witness", self.unique_prefix);
|
|
let proto_witness_var = format_ident!("{}proto_witness", self.unique_prefix);
|
|
|
- let nizk_var = format_ident!("{}nizk", self.unique_prefix);
|
|
|
|
|
|
|
|
|
|
quote! {
|
|
quote! {
|
|
|
pub fn prove(
|
|
pub fn prove(
|
|
@@ -702,12 +700,12 @@ impl<'a> CodeGen<'a> {
|
|
|
#witness_var: &Witness,
|
|
#witness_var: &Witness,
|
|
|
#session_id_var: &[u8],
|
|
#session_id_var: &[u8],
|
|
|
#rng_var: &mut (impl CryptoRng + RngCore),
|
|
#rng_var: &mut (impl CryptoRng + RngCore),
|
|
|
- ) -> SigmaResult<Vec<u8>> {
|
|
|
|
|
|
|
+ ) -> Result<Vec<u8>, InvalidWitness> {
|
|
|
|
|
+ // The proof nonces are drawn internally by sigma-proofs
|
|
|
|
|
+ let _ = #rng_var;
|
|
|
let #proto_var = protocol(#instance_var)?;
|
|
let #proto_var = protocol(#instance_var)?;
|
|
|
let #proto_witness_var = protocol_witness(#instance_var, #witness_var)?;
|
|
let #proto_witness_var = protocol_witness(#instance_var, #witness_var)?;
|
|
|
- let #nizk_var = #proto_var.into_nizk(#session_id_var);
|
|
|
|
|
-
|
|
|
|
|
- #nizk_var.prove_compact(&#proto_witness_var, #rng_var)
|
|
|
|
|
|
|
+ prove_compact(#session_id_var, &#proto_var, &#proto_witness_var)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -720,18 +718,15 @@ impl<'a> CodeGen<'a> {
|
|
|
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 proto_var = format_ident!("{}proto", self.unique_prefix);
|
|
|
- let nizk_var = format_ident!("{}nizk", self.unique_prefix);
|
|
|
|
|
|
|
|
|
|
quote! {
|
|
quote! {
|
|
|
pub fn verify(
|
|
pub fn verify(
|
|
|
#instance_var: &Instance,
|
|
#instance_var: &Instance,
|
|
|
#proof_var: &[u8],
|
|
#proof_var: &[u8],
|
|
|
#session_id_var: &[u8],
|
|
#session_id_var: &[u8],
|
|
|
- ) -> SigmaResult<()> {
|
|
|
|
|
|
|
+ ) -> Result<(), VerificationError> {
|
|
|
let #proto_var = protocol(#instance_var)?;
|
|
let #proto_var = protocol(#instance_var)?;
|
|
|
- let #nizk_var = #proto_var.into_nizk(#session_id_var);
|
|
|
|
|
-
|
|
|
|
|
- #nizk_var.verify_compact(#proof_var)
|
|
|
|
|
|
|
+ verify_compact(#session_id_var, &#proto_var, #proof_var)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -756,11 +751,12 @@ impl<'a> CodeGen<'a> {
|
|
|
use sigma_compiler::subtle::CtOption;
|
|
use sigma_compiler::subtle::CtOption;
|
|
|
use sigma_compiler::vecutils::*;
|
|
use sigma_compiler::vecutils::*;
|
|
|
use sigma_proofs::{
|
|
use sigma_proofs::{
|
|
|
- composition::{ComposedRelation, ComposedWitness},
|
|
|
|
|
- errors::Error as SigmaError,
|
|
|
|
|
- errors::Ok as SigmaOk,
|
|
|
|
|
- errors::Result as SigmaResult,
|
|
|
|
|
- LinearRelation, Nizk,
|
|
|
|
|
|
|
+ composition::{ComposedInstance, ComposedWitness},
|
|
|
|
|
+ errors::{
|
|
|
|
|
+ InstanceResult, InvalidInstance, InvalidWitness, ProverResult,
|
|
|
|
|
+ VerificationError,
|
|
|
|
|
+ },
|
|
|
|
|
+ prove_compact, verify_compact, LinearRelation,
|
|
|
};
|
|
};
|
|
|
use std::ops::Neg;
|
|
use std::ops::Neg;
|
|
|
#dump_use
|
|
#dump_use
|