No Pod IDs (#394)
- middleware:
- Add `Statement::Intro`
- Add `SignedBy` native predicate and operation. The signature is auxiliary data to the operation
- Rename `PodSigner` to `Signer` with a new API (just for signing `RawValue`)
- Removed `NewEntry` operation. Use `ContainsFromEntries` instead
- Remove `KEY_SIGNER` and `KEY_TYPE` which are no longer used
- Merge `RecursivePod` and `Pod` traits
- Change the `Pod::deserialize_data` method to use `Self` instead of `Box<dyn Pod>`
- Extend `Pod` trait with these methods:
- `is_main`: when the pod is Main, in a (recursive) verification its vk will be checked to exist in the vd_set but not if it's intro pod
- `is_mock`: skip some verifications in the recursive mock MainPod verification
- `verifier_data_hash`
- `pod_id` renamed to `statements_hash`
- AnchoredKeys are now a pair of dictionary root and key
- Entry statements are now defined as Contains with literal arguments
- Operations that take Entries now use Contains statements with literal arguments
- frontend:
- Rename `SignedPod` to `SignedDict` (which now contains the dict, public key and signature, and can still `verify(self)`ed)
- The `SignedDict` keeps the method `get_statement` for convenience but now it returns a `Contains` statement that proves the existence of the key in the dict
- The `MainPodBuilder` automatically inserts a `Contains` statement when an operation is added that uses an entry as argument that was not yet "opened".
- Removed the `literal` methods from the `MainPodBuilder` that were loading literals to anchored keys: that was no longer needed after we introduced literal arguments
- backend
- Only verify inclusion of the verifying key into the vd_set if the pod is MainPod. A pod is not MainPod if the first statement is Intro.
- Reject intro pods that have non-intro statements
- Empty pod now returns an intro statement
- Don't insert a type statement automatically in MainPod and MockMainPod. We get rid of the type entry.
- Implement `SignedBy` operation, which uses the muxed table to store signature verifications
- Rename `PodId` to `statements_hash` or `sts_hash` for short. Now this is only used as a hash of the statements for the circuits public inputs.
- Refactor normalization of `self` statements:
- Before: replace values that contain `SELF` by the given pod_id
- After: place the verifying key hash into the Intro predicates
This commit is contained in:
parent
122f9c3cac
commit
0e2f7b756e
39 changed files with 2127 additions and 3064 deletions
|
|
@ -6,7 +6,7 @@ use schemars::JsonSchema;
|
|||
use crate::{
|
||||
frontend::{AnchoredKey, Error, Result, Statement, StatementArg},
|
||||
middleware::{
|
||||
self, hash_str, CustomPredicate, CustomPredicateBatch, Key, NativePredicate, Params, PodId,
|
||||
self, hash_str, CustomPredicate, CustomPredicateBatch, Hash, Key, NativePredicate, Params,
|
||||
Predicate, StatementTmpl, StatementTmplArg, ToFields, Value, Wildcard,
|
||||
},
|
||||
};
|
||||
|
|
@ -181,8 +181,8 @@ impl CustomPredicateBatchBuilder {
|
|||
.map(|a| {
|
||||
Ok::<_, Error>(match a {
|
||||
BuilderArg::Literal(v) => StatementTmplArg::Literal(v.clone()),
|
||||
BuilderArg::Key(pod_id_wc, key_str) => StatementTmplArg::AnchoredKey(
|
||||
resolve_wildcard(args, priv_args, pod_id_wc)?,
|
||||
BuilderArg::Key(root_wc, key_str) => StatementTmplArg::AnchoredKey(
|
||||
resolve_wildcard(args, priv_args, root_wc)?,
|
||||
Key::from(key_str),
|
||||
),
|
||||
BuilderArg::WildcardLiteral(v) => {
|
||||
|
|
@ -223,7 +223,7 @@ fn resolve_wildcard(args: &[&str], priv_args: &[&str], s: &str) -> Result<Wildca
|
|||
.enumerate()
|
||||
.find_map(|(i, name)| (s == *name).then_some(Wildcard::new(s.to_string(), i)))
|
||||
.ok_or(Error::custom(format!(
|
||||
"Wildcard {} not amongst args {:?}",
|
||||
"Wildcard \"{}\" not amongst args {:?}",
|
||||
s,
|
||||
[args.to_vec(), priv_args.to_vec()].concat()
|
||||
)))
|
||||
|
|
@ -274,15 +274,10 @@ mod tests {
|
|||
let mut builder = CustomPredicateBatchBuilder::new(params.clone(), "gt_custom_pred".into());
|
||||
|
||||
let gt_stb = StatementTmplBuilder::new(NativePredicate::Gt)
|
||||
.arg(("s1_origin", "s1_key"))
|
||||
.arg(("s2_origin", "s2_key"));
|
||||
.arg("s1")
|
||||
.arg("s2");
|
||||
|
||||
builder.predicate_and(
|
||||
"gt_custom_pred",
|
||||
&["s1_origin", "s2_origin"],
|
||||
&[],
|
||||
&[gt_stb],
|
||||
)?;
|
||||
builder.predicate_and("gt_custom_pred", &["s1", "s2"], &[], &[gt_stb])?;
|
||||
let batch = builder.finish();
|
||||
let batch_clone = batch.clone();
|
||||
let gt_custom_pred = CustomPredicateRef::new(batch, 0);
|
||||
|
|
@ -290,11 +285,8 @@ mod tests {
|
|||
let mut mp_builder = MainPodBuilder::new(¶ms, vd_set);
|
||||
|
||||
// 2 > 1
|
||||
let s1 = mp_builder.priv_op(Operation::new_entry("s1_key", Value::from(2)))?;
|
||||
let s2 = mp_builder.priv_op(Operation::new_entry("s2_key", Value::from(1)))?;
|
||||
|
||||
// Adding a gt operation will produce a desugared lt operation
|
||||
let desugared_gt = mp_builder.pub_op(Operation::gt(s1, s2))?;
|
||||
let desugared_gt = mp_builder.pub_op(Operation::gt(2, 1))?;
|
||||
assert_eq!(
|
||||
desugared_gt.predicate(),
|
||||
Predicate::Native(NativePredicate::Lt)
|
||||
|
|
@ -324,12 +316,12 @@ mod tests {
|
|||
CustomPredicateBatchBuilder::new(params.clone(), "set_contains_custom_pred".into());
|
||||
|
||||
let set_contains_stb = StatementTmplBuilder::new(NativePredicate::SetContains)
|
||||
.arg(("s1_origin", "s1_key"))
|
||||
.arg(("s2_origin", "s2_key"));
|
||||
.arg("s1")
|
||||
.arg("s2");
|
||||
|
||||
builder.predicate_and(
|
||||
"set_contains_custom_pred",
|
||||
&["s1_origin", "s2_origin"],
|
||||
&["s1", "s2"],
|
||||
&[],
|
||||
&[set_contains_stb],
|
||||
)?;
|
||||
|
|
@ -339,11 +331,8 @@ mod tests {
|
|||
let mut mp_builder = MainPodBuilder::new(¶ms, vd_set);
|
||||
|
||||
let set_values: HashSet<Value> = [1, 2, 3].iter().map(|i| Value::from(*i)).collect();
|
||||
let s1 = mp_builder.priv_op(Operation::new_entry(
|
||||
"s1_key",
|
||||
Value::from(Set::new(params.max_depth_mt_containers, set_values)?),
|
||||
))?;
|
||||
let s2 = mp_builder.priv_op(Operation::new_entry("s2_key", Value::from(1)))?;
|
||||
let s1 = Set::new(params.max_depth_mt_containers, set_values)?;
|
||||
let s2 = 1;
|
||||
|
||||
let set_contains = mp_builder.pub_op(Operation::set_contains(s1, s2))?;
|
||||
assert_eq!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue