|
@@ -34,15 +34,15 @@ pub struct CodeGen {
|
|
|
/// be generated by the sigma_compiler itself) that the prover needs
|
|
|
/// to send to the verifier along with the proof. These could
|
|
|
/// include commitments to bits in range proofs, for example.
|
|
|
- sent_params: StructFieldList,
|
|
|
+ sent_instance: StructFieldList,
|
|
|
/// Extra code that will be emitted in the `prove` function
|
|
|
prove_code: TokenStream,
|
|
|
/// Extra code that will be emitted in the `verify` function
|
|
|
verify_code: TokenStream,
|
|
|
/// Extra code that will be emitted in the `verify` function before
|
|
|
- /// the `sent_params` are deserialized. This is where the verifier
|
|
|
- /// sets the lengths of vector variables in the `sent_params`.
|
|
|
- verify_pre_params_code: TokenStream,
|
|
|
+ /// the `sent_instance` are deserialized. This is where the verifier
|
|
|
+ /// sets the lengths of vector variables in the `sent_instance`.
|
|
|
+ verify_pre_instance_code: TokenStream,
|
|
|
}
|
|
|
|
|
|
impl CodeGen {
|
|
@@ -76,10 +76,10 @@ impl CodeGen {
|
|
|
group_name: spec.group_name.clone(),
|
|
|
vars: spec.vars.clone(),
|
|
|
unique_prefix: Self::unique_prefix(&spec.vars),
|
|
|
- sent_params: StructFieldList::default(),
|
|
|
+ sent_instance: StructFieldList::default(),
|
|
|
prove_code: quote! {},
|
|
|
verify_code: quote! {},
|
|
|
- verify_pre_params_code: quote! {},
|
|
|
+ verify_pre_instance_code: quote! {},
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -91,10 +91,10 @@ impl CodeGen {
|
|
|
group_name: parse_quote! { G },
|
|
|
vars: TaggedVarDict::default(),
|
|
|
unique_prefix: "gen__".into(),
|
|
|
- sent_params: StructFieldList::default(),
|
|
|
+ sent_instance: StructFieldList::default(),
|
|
|
prove_code: quote! {},
|
|
|
verify_code: quote! {},
|
|
|
- verify_pre_params_code: quote! {},
|
|
|
+ verify_pre_instance_code: quote! {},
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -125,7 +125,7 @@ impl CodeGen {
|
|
|
id
|
|
|
}
|
|
|
|
|
|
- /// Create a new public Point variable to put in the Params,
|
|
|
+ /// Create a new public Point variable to put in the Instance,
|
|
|
/// optionally marking it as needing to be sent from the prover to
|
|
|
/// the verifier along with the proof.
|
|
|
///
|
|
@@ -133,7 +133,7 @@ impl CodeGen {
|
|
|
/// [`prove_append`](Self::prove_append) with code like `quote!{ let
|
|
|
/// #id = ... }` where `id` is the [`struct@Ident`] returned from
|
|
|
/// this function. If `is_vec` is `true`, then you should also call
|
|
|
- /// [`verify_pre_params_append`](Self::verify_pre_params_append)
|
|
|
+ /// [`verify_pre_instance_append`](Self::verify_pre_instance_append)
|
|
|
/// with code like `quote!{ let mut #id = Vec::<Point>::new();
|
|
|
/// #id.resize(#len, Point::default()); }` where `len` is the number
|
|
|
/// of elements you expect to have in the vector (computed at
|
|
@@ -157,9 +157,9 @@ impl CodeGen {
|
|
|
);
|
|
|
if send_to_verifier {
|
|
|
if is_vec {
|
|
|
- self.sent_params.push_vecpoint(&id);
|
|
|
+ self.sent_instance.push_vecpoint(&id);
|
|
|
} else {
|
|
|
- self.sent_params.push_point(&id);
|
|
|
+ self.sent_instance.push_point(&id);
|
|
|
}
|
|
|
}
|
|
|
id
|
|
@@ -189,27 +189,27 @@ impl CodeGen {
|
|
|
}
|
|
|
|
|
|
/// Append some code to the generated `verify` function to be run
|
|
|
- /// before the `sent_params` are deserialized
|
|
|
- pub fn verify_pre_params_append(&mut self, code: TokenStream) {
|
|
|
- let verify_pre_params_code = &self.verify_pre_params_code;
|
|
|
- self.verify_pre_params_code = quote! {
|
|
|
- #verify_pre_params_code
|
|
|
+ /// before the `sent_instance` are deserialized
|
|
|
+ pub fn verify_pre_instance_append(&mut self, code: TokenStream) {
|
|
|
+ let verify_pre_instance_code = &self.verify_pre_instance_code;
|
|
|
+ self.verify_pre_instance_code = quote! {
|
|
|
+ #verify_pre_instance_code
|
|
|
#code
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/// Append some code to both the generated `prove` and `verify`
|
|
|
- /// functions, the latter to be run before the `sent_params` are
|
|
|
+ /// functions, the latter to be run before the `sent_instance` are
|
|
|
/// deserialized
|
|
|
- pub fn prove_verify_pre_params_append(&mut self, code: TokenStream) {
|
|
|
+ pub fn prove_verify_pre_instance_append(&mut self, code: TokenStream) {
|
|
|
let prove_code = &self.prove_code;
|
|
|
self.prove_code = quote! {
|
|
|
#prove_code
|
|
|
#code
|
|
|
};
|
|
|
- let verify_pre_params_code = &self.verify_pre_params_code;
|
|
|
- self.verify_pre_params_code = quote! {
|
|
|
- #verify_pre_params_code
|
|
|
+ let verify_pre_instance_code = &self.verify_pre_instance_code;
|
|
|
+ self.verify_pre_instance_code = quote! {
|
|
|
+ #verify_pre_instance_code
|
|
|
#code
|
|
|
};
|
|
|
}
|
|
@@ -251,24 +251,24 @@ impl CodeGen {
|
|
|
);
|
|
|
let sigma_rs_code = sigma_rs_codegen.generate(emit_prover, emit_verifier);
|
|
|
|
|
|
- let mut pub_params_fields = StructFieldList::default();
|
|
|
- pub_params_fields.push_vars(&vardict, true);
|
|
|
+ let mut pub_instance_fields = StructFieldList::default();
|
|
|
+ pub_instance_fields.push_vars(&vardict, true);
|
|
|
let mut witness_fields = StructFieldList::default();
|
|
|
witness_fields.push_vars(&vardict, false);
|
|
|
|
|
|
- let mut sigma_rs_params_fields = StructFieldList::default();
|
|
|
- sigma_rs_params_fields.push_vars(&sigma_rs_vardict, true);
|
|
|
+ let mut sigma_rs_instance_fields = StructFieldList::default();
|
|
|
+ sigma_rs_instance_fields.push_vars(&sigma_rs_vardict, true);
|
|
|
let mut sigma_rs_witness_fields = StructFieldList::default();
|
|
|
sigma_rs_witness_fields.push_vars(&sigma_rs_vardict, false);
|
|
|
|
|
|
- // Generate the public params struct definition
|
|
|
- let params_def = {
|
|
|
- let decls = pub_params_fields.field_decls();
|
|
|
+ // Generate the public instance struct definition
|
|
|
+ let instance_def = {
|
|
|
+ let decls = pub_instance_fields.field_decls();
|
|
|
#[cfg(feature = "dump")]
|
|
|
let dump_impl = {
|
|
|
- let dump_chunks = pub_params_fields.dump();
|
|
|
+ let dump_chunks = pub_instance_fields.dump();
|
|
|
quote! {
|
|
|
- impl Params {
|
|
|
+ impl Instance {
|
|
|
fn dump_scalar(s: &Scalar) {
|
|
|
let bytes: &[u8] = &s.to_repr();
|
|
|
print!("{:02x?}", bytes);
|
|
@@ -291,7 +291,7 @@ impl CodeGen {
|
|
|
};
|
|
|
quote! {
|
|
|
#[derive(Clone)]
|
|
|
- pub struct Params {
|
|
|
+ pub struct Instance {
|
|
|
#decls
|
|
|
}
|
|
|
|
|
@@ -314,28 +314,28 @@ impl CodeGen {
|
|
|
|
|
|
// Generate the prove function
|
|
|
let prove_func = if emit_prover {
|
|
|
- let params_ids = pub_params_fields.field_list();
|
|
|
+ let instance_ids = pub_instance_fields.field_list();
|
|
|
let witness_ids = witness_fields.field_list();
|
|
|
- let sigma_rs_params_ids = sigma_rs_params_fields.field_list();
|
|
|
+ let sigma_rs_instance_ids = sigma_rs_instance_fields.field_list();
|
|
|
let sigma_rs_witness_ids = sigma_rs_witness_fields.field_list();
|
|
|
let prove_code = &self.prove_code;
|
|
|
- let codegen_params_var = format_ident!("{}sigma_params", self.unique_prefix);
|
|
|
+ let codegen_instance_var = format_ident!("{}sigma_instance", self.unique_prefix);
|
|
|
let codegen_witness_var = format_ident!("{}sigma_witness", self.unique_prefix);
|
|
|
- let params_var = format_ident!("{}params", self.unique_prefix);
|
|
|
+ let instance_var = format_ident!("{}instance", self.unique_prefix);
|
|
|
let witness_var = format_ident!("{}witness", self.unique_prefix);
|
|
|
let rng_var = format_ident!("{}rng", self.unique_prefix);
|
|
|
let proof_var = format_ident!("{}proof", self.unique_prefix);
|
|
|
let sid_var = format_ident!("{}session_id", self.unique_prefix);
|
|
|
- let sent_params_code = {
|
|
|
- let chunks = self.sent_params.fields.iter().map(|sf| match sf {
|
|
|
+ let sent_instance_code = {
|
|
|
+ let chunks = self.sent_instance.fields.iter().map(|sf| match sf {
|
|
|
StructField::Point(id) => quote! {
|
|
|
#proof_var.extend(sigma_rs::serialization::serialize_elements(
|
|
|
- std::slice::from_ref(&#codegen_params_var.#id)
|
|
|
+ std::slice::from_ref(&#codegen_instance_var.#id)
|
|
|
));
|
|
|
},
|
|
|
StructField::VecPoint(id) => quote! {
|
|
|
#proof_var.extend(sigma_rs::serialization::serialize_elements(
|
|
|
- &#codegen_params_var.#id
|
|
|
+ &#codegen_instance_var.#id
|
|
|
));
|
|
|
},
|
|
|
_ => quote! {},
|
|
@@ -345,8 +345,8 @@ impl CodeGen {
|
|
|
|
|
|
let dumper = if cfg!(feature = "dump") {
|
|
|
quote! {
|
|
|
- println!("prover params = {{");
|
|
|
- #params_var.dump();
|
|
|
+ println!("prover instance = {{");
|
|
|
+ #instance_var.dump();
|
|
|
println!("}}");
|
|
|
}
|
|
|
} else {
|
|
@@ -355,26 +355,26 @@ impl CodeGen {
|
|
|
|
|
|
quote! {
|
|
|
pub fn prove(
|
|
|
- #params_var: &Params,
|
|
|
+ #instance_var: &Instance,
|
|
|
#witness_var: &Witness,
|
|
|
#sid_var: &[u8],
|
|
|
#rng_var: &mut (impl CryptoRng + RngCore),
|
|
|
) -> Result<Vec<u8>, SigmaError> {
|
|
|
#dumper
|
|
|
- let Params { #params_ids } = #params_var.clone();
|
|
|
+ let Instance { #instance_ids } = #instance_var.clone();
|
|
|
let Witness { #witness_ids } = #witness_var.clone();
|
|
|
#prove_code
|
|
|
let mut #proof_var = Vec::<u8>::new();
|
|
|
- let #codegen_params_var = sigma::Params {
|
|
|
- #sigma_rs_params_ids
|
|
|
+ let #codegen_instance_var = sigma::Instance {
|
|
|
+ #sigma_rs_instance_ids
|
|
|
};
|
|
|
let #codegen_witness_var = sigma::Witness {
|
|
|
#sigma_rs_witness_ids
|
|
|
};
|
|
|
- #sent_params_code
|
|
|
+ #sent_instance_code
|
|
|
#proof_var.extend(
|
|
|
sigma::prove(
|
|
|
- &#codegen_params_var,
|
|
|
+ &#codegen_instance_var,
|
|
|
&#codegen_witness_var,
|
|
|
#sid_var,
|
|
|
#rng_var,
|
|
@@ -389,18 +389,18 @@ impl CodeGen {
|
|
|
|
|
|
// Generate the verify function
|
|
|
let verify_func = if emit_verifier {
|
|
|
- let params_ids = pub_params_fields.field_list();
|
|
|
- let sigma_rs_params_ids = sigma_rs_params_fields.field_list();
|
|
|
- let verify_pre_params_code = &self.verify_pre_params_code;
|
|
|
+ let instance_ids = pub_instance_fields.field_list();
|
|
|
+ let sigma_rs_instance_ids = sigma_rs_instance_fields.field_list();
|
|
|
+ let verify_pre_instance_code = &self.verify_pre_instance_code;
|
|
|
let verify_code = &self.verify_code;
|
|
|
- let codegen_params_var = format_ident!("{}sigma_params", self.unique_prefix);
|
|
|
+ let codegen_instance_var = format_ident!("{}sigma_instance", self.unique_prefix);
|
|
|
let element_len_var = format_ident!("{}element_len", self.unique_prefix);
|
|
|
let offset_var = format_ident!("{}proof_offset", self.unique_prefix);
|
|
|
- let params_var = format_ident!("{}params", self.unique_prefix);
|
|
|
+ let instance_var = format_ident!("{}instance", self.unique_prefix);
|
|
|
let proof_var = format_ident!("{}proof", self.unique_prefix);
|
|
|
let sid_var = format_ident!("{}session_id", self.unique_prefix);
|
|
|
- let sent_params_code = {
|
|
|
- let element_len_code = if self.sent_params.fields.is_empty() {
|
|
|
+ let sent_instance_code = {
|
|
|
+ let element_len_code = if self.sent_instance.fields.is_empty() {
|
|
|
quote! {}
|
|
|
} else {
|
|
|
quote! {
|
|
@@ -409,7 +409,7 @@ impl CodeGen {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- let chunks = self.sent_params.fields.iter().map(|sf| match sf {
|
|
|
+ let chunks = self.sent_instance.fields.iter().map(|sf| match sf {
|
|
|
StructField::Point(id) => quote! {
|
|
|
let #id: Point = sigma_rs::serialization::deserialize_elements(
|
|
|
&#proof_var[#offset_var..],
|
|
@@ -436,8 +436,8 @@ impl CodeGen {
|
|
|
|
|
|
let dumper = if cfg!(feature = "dump") {
|
|
|
quote! {
|
|
|
- println!("verifier params = {{");
|
|
|
- #params_var.dump();
|
|
|
+ println!("verifier instance = {{");
|
|
|
+ #instance_var.dump();
|
|
|
println!("}}");
|
|
|
}
|
|
|
} else {
|
|
@@ -446,20 +446,20 @@ impl CodeGen {
|
|
|
|
|
|
quote! {
|
|
|
pub fn verify(
|
|
|
- #params_var: &Params,
|
|
|
+ #instance_var: &Instance,
|
|
|
#proof_var: &[u8],
|
|
|
#sid_var: &[u8],
|
|
|
) -> Result<(), SigmaError> {
|
|
|
#dumper
|
|
|
- let Params { #params_ids } = #params_var.clone();
|
|
|
- #verify_pre_params_code
|
|
|
- #sent_params_code
|
|
|
+ let Instance { #instance_ids } = #instance_var.clone();
|
|
|
+ #verify_pre_instance_code
|
|
|
+ #sent_instance_code
|
|
|
#verify_code
|
|
|
- let #codegen_params_var = sigma::Params {
|
|
|
- #sigma_rs_params_ids
|
|
|
+ let #codegen_instance_var = sigma::Instance {
|
|
|
+ #sigma_rs_instance_ids
|
|
|
};
|
|
|
sigma::verify(
|
|
|
- &#codegen_params_var,
|
|
|
+ &#codegen_instance_var,
|
|
|
&#proof_var[#offset_var..],
|
|
|
#sid_var,
|
|
|
)
|
|
@@ -493,7 +493,7 @@ impl CodeGen {
|
|
|
|
|
|
#sigma_rs_code
|
|
|
|
|
|
- #params_def
|
|
|
+ #instance_def
|
|
|
#witness_def
|
|
|
#prove_func
|
|
|
#verify_func
|