Add verifier-datas tree (set) & in-circuit verification (#274)
* containers: add method to create new {Dict,Set,Array} with custom max_depth
* add vds_tree computation, update tree circuit interface
* add VDTree struct, add DEFAULT_VD_TREE, integrate it with MainPod,EmptyPod,frontend,etc.
* adapt frontend/serialization tests to new containers field (max_depth)
* adapt interfaces to allow using custom vd_tree in frontend & backend constructors
* rename VDTree to VDSet (and derivate namings too)
* containers 'new' always with param 'max_depth', use params.max_depth_mt_containers instead of the global constant MAX_DEPTH
* adapt after rebasing the branch to main latest changes
* apply review suggestions from @ed255
* use emptypod vd_mt_proofs (using vd_set as circuit input), merge the two existing set_targets methods of MainPodVerifyTarget
* document VDSet & vds_root
This commit is contained in:
parent
6258e52e1a
commit
273d803ebd
17 changed files with 486 additions and 259 deletions
|
|
@ -10,8 +10,7 @@ use serialization::{SerializedMainPod, SerializedSignedPod};
|
|||
use crate::middleware::{
|
||||
self, check_st_tmpl, hash_str, hash_values, AnchoredKey, Hash, Key, MainPodInputs,
|
||||
NativeOperation, NativePredicate, OperationAux, OperationType, Params, PodId, PodProver,
|
||||
PodSigner, Predicate, Statement, StatementArg, Value, WildcardValue, EMPTY_HASH, KEY_TYPE,
|
||||
SELF,
|
||||
PodSigner, Predicate, Statement, StatementArg, VDSet, Value, WildcardValue, KEY_TYPE, SELF,
|
||||
};
|
||||
|
||||
mod custom;
|
||||
|
|
@ -117,6 +116,7 @@ impl SignedPod {
|
|||
#[derive(Debug)]
|
||||
pub struct MainPodBuilder {
|
||||
pub params: Params,
|
||||
pub vd_set: VDSet,
|
||||
pub input_signed_pods: Vec<SignedPod>,
|
||||
pub input_main_pods: Vec<MainPod>,
|
||||
pub statements: Vec<Statement>,
|
||||
|
|
@ -151,9 +151,10 @@ impl fmt::Display for MainPodBuilder {
|
|||
}
|
||||
|
||||
impl MainPodBuilder {
|
||||
pub fn new(params: &Params) -> Self {
|
||||
pub fn new(params: &Params, vd_set: &VDSet) -> Self {
|
||||
Self {
|
||||
params: params.clone(),
|
||||
vd_set: vd_set.clone(),
|
||||
input_signed_pods: Vec::new(),
|
||||
input_main_pods: Vec::new(),
|
||||
statements: Vec::new(),
|
||||
|
|
@ -548,6 +549,7 @@ impl MainPodBuilder {
|
|||
};
|
||||
|
||||
let (statements, operations, public_statements) = compiler.compile(inputs, params)?;
|
||||
|
||||
let inputs = MainPodInputs {
|
||||
signed_pods: &self
|
||||
.input_signed_pods
|
||||
|
|
@ -562,9 +564,9 @@ impl MainPodBuilder {
|
|||
statements: &statements,
|
||||
operations: &operations,
|
||||
public_statements: &public_statements,
|
||||
vds_root: EMPTY_HASH, // TODO https://github.com/0xPARC/pod2/issues/249
|
||||
vds_set: self.vd_set.clone(),
|
||||
};
|
||||
let pod = prover.prove(&self.params, inputs)?;
|
||||
let pod = prover.prove(&self.params, &self.vd_set, inputs)?;
|
||||
|
||||
// Gather public statements, making sure to inject the type
|
||||
// information specified by the backend.
|
||||
|
|
@ -838,7 +840,7 @@ pub mod tests {
|
|||
eth_dos_pod_builder, eth_friend_signed_pod_builder, great_boy_pod_full_flow,
|
||||
tickets_pod_full_flow, zu_kyc_pod_builder, zu_kyc_sign_pod_builders,
|
||||
},
|
||||
middleware::{containers::Dictionary, Value},
|
||||
middleware::{containers::Dictionary, Value, DEFAULT_VD_SET},
|
||||
};
|
||||
|
||||
// Check that frontend public statements agree with those
|
||||
|
|
@ -873,6 +875,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_front_zu_kyc() -> Result<()> {
|
||||
let params = Params::default();
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
let (gov_id, pay_stub, sanction_list) = zu_kyc_sign_pod_builders(¶ms);
|
||||
|
||||
println!("{}", gov_id);
|
||||
|
|
@ -899,7 +902,7 @@ pub mod tests {
|
|||
check_kvs(&sanction_list)?;
|
||||
println!("{}", sanction_list);
|
||||
|
||||
let kyc_builder = zu_kyc_pod_builder(¶ms, &gov_id, &pay_stub, &sanction_list)?;
|
||||
let kyc_builder = zu_kyc_pod_builder(¶ms, &vd_set, &gov_id, &pay_stub, &sanction_list)?;
|
||||
println!("{}", kyc_builder);
|
||||
|
||||
// prove kyc with MockProver and print it
|
||||
|
|
@ -926,6 +929,7 @@ pub mod tests {
|
|||
max_custom_predicate_wildcards: 12,
|
||||
..Default::default()
|
||||
};
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
|
||||
let mut alice = MockSigner { pk: "Alice".into() };
|
||||
let bob = MockSigner { pk: "Bob".into() };
|
||||
|
|
@ -945,6 +949,7 @@ pub mod tests {
|
|||
let mut prover = MockProver {};
|
||||
let alice_bob_ethdos = eth_dos_pod_builder(
|
||||
¶ms,
|
||||
&vd_set,
|
||||
true,
|
||||
&alice_attestation,
|
||||
&charlie_attestation,
|
||||
|
|
@ -978,13 +983,15 @@ pub mod tests {
|
|||
#[should_panic]
|
||||
fn test_equal() {
|
||||
let params = Params::default();
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
|
||||
let mut signed_builder = SignedPodBuilder::new(¶ms);
|
||||
signed_builder.insert("a", 1);
|
||||
signed_builder.insert("b", 1);
|
||||
let mut signer = MockSigner { pk: "key".into() };
|
||||
let signed_pod = signed_builder.sign(&mut signer).unwrap();
|
||||
|
||||
let mut builder = MainPodBuilder::new(¶ms);
|
||||
let mut builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
builder.add_signed_pod(&signed_pod);
|
||||
|
||||
//let op_val1 = Operation{
|
||||
|
|
@ -1028,6 +1035,7 @@ pub mod tests {
|
|||
#[should_panic]
|
||||
fn test_false_st() {
|
||||
let params = Params::default();
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
let mut builder = SignedPodBuilder::new(¶ms);
|
||||
|
||||
builder.insert("num", 2);
|
||||
|
|
@ -1039,7 +1047,7 @@ pub mod tests {
|
|||
|
||||
println!("{}", pod);
|
||||
|
||||
let mut builder = MainPodBuilder::new(¶ms);
|
||||
let mut builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
builder.add_signed_pod(&pod);
|
||||
builder.pub_op(op!(gt, (&pod, "num"), 5)).unwrap();
|
||||
|
||||
|
|
@ -1053,6 +1061,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_dictionaries() -> Result<()> {
|
||||
let params = Params::default();
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
let mut builder = SignedPodBuilder::new(¶ms);
|
||||
|
||||
let mut my_dict_kvs: HashMap<Key, Value> = HashMap::new();
|
||||
|
|
@ -1061,7 +1070,7 @@ pub mod tests {
|
|||
my_dict_kvs.insert(Key::from("c"), Value::from(3));
|
||||
// let my_dict_as_mt = MerkleTree::new(5, &my_dict_kvs).unwrap();
|
||||
// let dict = Dictionary { mt: my_dict_as_mt };
|
||||
let dict = Dictionary::new(my_dict_kvs)?;
|
||||
let dict = Dictionary::new(params.max_depth_mt_containers, my_dict_kvs)?;
|
||||
let dict_root = Value::from(dict.clone());
|
||||
builder.insert("dict", dict_root);
|
||||
|
||||
|
|
@ -1070,7 +1079,7 @@ pub mod tests {
|
|||
};
|
||||
let pod = builder.sign(&mut signer).unwrap();
|
||||
|
||||
let mut builder = MainPodBuilder::new(¶ms);
|
||||
let mut builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
builder.add_signed_pod(&pod);
|
||||
let st0 = pod.get_statement("dict").unwrap();
|
||||
let st1 = builder.op(true, op!(new_entry, ("key", "a"))).unwrap();
|
||||
|
|
@ -1106,7 +1115,8 @@ pub mod tests {
|
|||
env_logger::init();
|
||||
|
||||
let params = Params::default();
|
||||
let mut builder = MainPodBuilder::new(¶ms);
|
||||
let vd_set = &*DEFAULT_VD_SET;
|
||||
let mut builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
let st = Statement::ValueOf(AnchoredKey::from((SELF, "a")), Value::from(3));
|
||||
let op_new_entry = Operation(
|
||||
OperationType::Native(NativeOperation::NewEntry),
|
||||
|
|
@ -1124,8 +1134,7 @@ pub mod tests {
|
|||
|
||||
// try to insert a statement that doesn't follow from the operation
|
||||
// right now the mock prover catches this when it calls compile()
|
||||
let params = Params::default();
|
||||
let mut builder = MainPodBuilder::new(¶ms);
|
||||
let mut builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
let self_a = AnchoredKey::from((SELF, "a"));
|
||||
let self_b = AnchoredKey::from((SELF, "b"));
|
||||
let value_of_a = Statement::ValueOf(self_a.clone(), Value::from(3));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue