|
|
@@ -44,69 +44,69 @@ pub fn transform(
|
|
|
// Are we in the root disjunction branch? (path is empty)
|
|
|
let in_root_disjunction_branch = path.is_empty();
|
|
|
|
|
|
- // For each leaf expression, see if it looks like a public Scalar
|
|
|
- // equality statement
|
|
|
+ // For each leaf expression, see if it looks like a public Scalar
|
|
|
+ // equality statement
|
|
|
branch.for_each_disjunction_branch_leaf(&mut |leaf| {
|
|
|
- if let StatementTree::Leaf(Expr::Assign(syn::ExprAssign { left, right, .. })) = leaf {
|
|
|
- if let Expr::Path(syn::ExprPath { path, .. }) = left.as_ref() {
|
|
|
- if let Some(id) = path.get_ident() {
|
|
|
- let idstr = id.to_string();
|
|
|
- if let Some(TaggedIdent::Scalar(TaggedScalar {
|
|
|
- is_pub: true,
|
|
|
- is_vec: false,
|
|
|
- ..
|
|
|
- })) = vars.get(&idstr)
|
|
|
- {
|
|
|
- if let (
|
|
|
- AExprType::Scalar {
|
|
|
- is_pub: true,
|
|
|
- is_vec: false,
|
|
|
- ..
|
|
|
- },
|
|
|
- right_tokens,
|
|
|
- ) = expr_type_tokens(&vardict, right)?
|
|
|
+ if let StatementTree::Leaf(Expr::Assign(syn::ExprAssign { left, right, .. })) = leaf {
|
|
|
+ if let Expr::Path(syn::ExprPath { path, .. }) = left.as_ref() {
|
|
|
+ if let Some(id) = path.get_ident() {
|
|
|
+ let idstr = id.to_string();
|
|
|
+ if let Some(TaggedIdent::Scalar(TaggedScalar {
|
|
|
+ is_pub: true,
|
|
|
+ is_vec: false,
|
|
|
+ ..
|
|
|
+ })) = vars.get(&idstr)
|
|
|
{
|
|
|
- // We found a public Scalar equality
|
|
|
- // statement.
|
|
|
- if in_root_disjunction_branch {
|
|
|
- // If we're in the root disjunction branch,
|
|
|
- // add code to both the prover and the
|
|
|
- // verifier to directly check the statement.
|
|
|
- codegen.prove_verify_append(quote! {
|
|
|
- if #id != #right_tokens {
|
|
|
- return Err(SigmaError::VerificationFailure);
|
|
|
- }
|
|
|
- });
|
|
|
+ if let (
|
|
|
+ AExprType::Scalar {
|
|
|
+ is_pub: true,
|
|
|
+ is_vec: false,
|
|
|
+ ..
|
|
|
+ },
|
|
|
+ right_tokens,
|
|
|
+ ) = expr_type_tokens(&vardict, right)?
|
|
|
+ {
|
|
|
+ // We found a public Scalar equality
|
|
|
+ // statement.
|
|
|
+ if in_root_disjunction_branch {
|
|
|
+ // If we're in the root disjunction branch,
|
|
|
+ // add code to both the prover and the
|
|
|
+ // verifier to directly check the statement.
|
|
|
+ codegen.prove_verify_append(quote! {
|
|
|
+ if #id != #right_tokens {
|
|
|
+ return Err(SigmaError::VerificationFailure);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // Remove the statement from the
|
|
|
- // [`StatementTree`] by replacing it with
|
|
|
- // leaf_true (which will be pruned below).
|
|
|
- *leaf = StatementTree::leaf_true();
|
|
|
- } else {
|
|
|
- // If we're not in the root disjunction
|
|
|
- // branch, replace the statement
|
|
|
- // `left_id = right_side` with the
|
|
|
- // statement `left_id*A =
|
|
|
- // (right_side)*A` for a cind Point A.
|
|
|
- if cind_points.is_empty() {
|
|
|
- return Err(Error::new(
|
|
|
- proc_macro2::Span::call_site(),
|
|
|
- "At least one cind Point must be declared to support public Scalar equality statements inside disjunctions",
|
|
|
- ));
|
|
|
- }
|
|
|
- let cind_A = &cind_points[0];
|
|
|
+ // Remove the statement from the
|
|
|
+ // [`StatementTree`] by replacing it with
|
|
|
+ // leaf_true (which will be pruned below).
|
|
|
+ *leaf = StatementTree::leaf_true();
|
|
|
+ } else {
|
|
|
+ // If we're not in the root disjunction
|
|
|
+ // branch, replace the statement
|
|
|
+ // `left_id = right_side` with the
|
|
|
+ // statement `left_id*A =
|
|
|
+ // (right_side)*A` for a cind Point A.
|
|
|
+ if cind_points.is_empty() {
|
|
|
+ return Err(Error::new(
|
|
|
+ proc_macro2::Span::call_site(),
|
|
|
+ "At least one cind Point must be declared to support public Scalar equality statements inside disjunctions",
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ let cind_A = &cind_points[0];
|
|
|
|
|
|
- *leaf = StatementTree::Leaf(parse_quote! {
|
|
|
- #id * #cind_A = (#right) * #cind_A
|
|
|
- });
|
|
|
+ *leaf = StatementTree::Leaf(parse_quote! {
|
|
|
+ #id * #cind_A = (#right) * #cind_A
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- Ok(())
|
|
|
- })
|
|
|
+ Ok(())
|
|
|
+ })
|
|
|
})?;
|
|
|
|
|
|
// Now prune the StatementTree
|