Progress on the MainPod circuit (#159)
* feat: add SignedPodVerify test * unify circuits style * more clear sizes * get operation_verify test working * be consistent with names
This commit is contained in:
parent
9afc43675d
commit
b93187c9bb
11 changed files with 411 additions and 175 deletions
|
|
@ -5,6 +5,7 @@ use std::{fmt, hash as h, iter, iter::zip};
|
|||
use anyhow::{anyhow, Result};
|
||||
use plonky2::field::types::Field;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
hash_fields, AnchoredKey, Hash, NativePredicate, Params, PodId, Statement, StatementArg,
|
||||
|
|
@ -12,7 +13,6 @@ use super::{
|
|||
};
|
||||
use crate::backends::plonky2::basetypes::HASH_SIZE;
|
||||
use crate::util::hashmap_insert_no_dupe;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// BEGIN Custom 1b
|
||||
|
||||
|
|
@ -49,9 +49,9 @@ impl fmt::Display for HashOrWildcard {
|
|||
}
|
||||
|
||||
impl ToFields for HashOrWildcard {
|
||||
fn to_fields(&self, _params: &Params) -> Vec<F> {
|
||||
fn to_fields(&self, params: &Params) -> Vec<F> {
|
||||
match self {
|
||||
HashOrWildcard::Hash(h) => h.to_fields(_params),
|
||||
HashOrWildcard::Hash(h) => h.to_fields(params),
|
||||
HashOrWildcard::Wildcard(w) => (0..HASH_SIZE - 1)
|
||||
.chain(iter::once(*w))
|
||||
.map(|x| F::from_canonical_u64(x as u64))
|
||||
|
|
@ -91,7 +91,7 @@ impl StatementTmplArg {
|
|||
}
|
||||
|
||||
impl ToFields for StatementTmplArg {
|
||||
fn to_fields(&self, _params: &Params) -> Vec<F> {
|
||||
fn to_fields(&self, params: &Params) -> Vec<F> {
|
||||
// None => (0, ...)
|
||||
// Literal(value) => (1, [value], 0, 0, 0, 0)
|
||||
// Key(hash_or_wildcard1, hash_or_wildcard2)
|
||||
|
|
@ -107,15 +107,15 @@ impl ToFields for StatementTmplArg {
|
|||
}
|
||||
StatementTmplArg::Literal(v) => {
|
||||
let fields: Vec<F> = iter::once(F::from_canonical_u64(1))
|
||||
.chain(v.to_fields(_params))
|
||||
.chain(v.to_fields(params))
|
||||
.chain(iter::repeat_with(|| F::from_canonical_u64(0)).take(HASH_SIZE))
|
||||
.collect();
|
||||
fields
|
||||
}
|
||||
StatementTmplArg::Key(hw1, hw2) => {
|
||||
let fields: Vec<F> = iter::once(F::from_canonical_u64(2))
|
||||
.chain(hw1.to_fields(_params))
|
||||
.chain(hw2.to_fields(_params))
|
||||
.chain(hw1.to_fields(params))
|
||||
.chain(hw2.to_fields(params))
|
||||
.collect();
|
||||
fields
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ impl StatementTmpl {
|
|||
Err(anyhow!(
|
||||
"Cannot check self-referencing statement templates."
|
||||
))
|
||||
} else if self.pred() != &s.code() {
|
||||
} else if self.pred() != &s.predicate() {
|
||||
Err(anyhow!("Type mismatch between {:?} and {}.", self, s))
|
||||
} else {
|
||||
zip(self.args(), s.args())
|
||||
|
|
@ -318,8 +318,8 @@ impl ToFields for CustomPredicateBatch {
|
|||
}
|
||||
|
||||
impl CustomPredicateBatch {
|
||||
pub fn hash(&self, _params: &Params) -> Hash {
|
||||
let input = self.to_fields(_params);
|
||||
pub fn hash(&self, params: &Params) -> Hash {
|
||||
let input = self.to_fields(params);
|
||||
|
||||
hash_fields(&input)
|
||||
}
|
||||
|
|
@ -399,7 +399,7 @@ impl From<NativePredicate> for Predicate {
|
|||
}
|
||||
|
||||
impl ToFields for Predicate {
|
||||
fn to_fields(&self, _params: &Params) -> Vec<F> {
|
||||
fn to_fields(&self, params: &Params) -> Vec<F> {
|
||||
// serialize:
|
||||
// NativePredicate(id) as (0, id, 0, 0, 0, 0) -- id: usize
|
||||
// BatchSelf(i) as (1, i, 0, 0, 0, 0) -- i: usize
|
||||
|
|
@ -410,13 +410,13 @@ impl ToFields for Predicate {
|
|||
// in every case: pad to (hash_size + 2) field elements
|
||||
let mut fields: Vec<F> = match self {
|
||||
Self::Native(p) => iter::once(F::from_canonical_u64(1))
|
||||
.chain(p.to_fields(_params))
|
||||
.chain(p.to_fields(params))
|
||||
.collect(),
|
||||
Self::BatchSelf(i) => iter::once(F::from_canonical_u64(2))
|
||||
.chain(iter::once(F::from_canonical_usize(*i)))
|
||||
.collect(),
|
||||
Self::Custom(CustomPredicateRef(pb, i)) => iter::once(F::from_canonical_u64(3))
|
||||
.chain(pb.hash(_params).0)
|
||||
.chain(pb.hash(params).0)
|
||||
.chain(iter::once(F::from_canonical_usize(*i)))
|
||||
.collect(),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue