Skip to content

Commit a6cd02e

Browse files
robknightax0
andauthored
Add extra front-end types and make MainPodBuilder emit these (#166)
* All test pass on middleware->frontend type refactor * Convert frontend CustomPredicateRef to a named field struct * Minor serialization improvements * Set appropriate titles in JSON schemas * Add names for custom predicates * Remove PodClass from front-end Origin type * Simplify value conversion --------- Co-authored-by: Ahmad <root@ahmadafuni.com>
1 parent 6528914 commit a6cd02e

File tree

9 files changed

+538
-113
lines changed

9 files changed

+538
-113
lines changed

src/examples/custom.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::sync::Arc;
33
use anyhow::Result;
44

55
use crate::{
6-
frontend::{literal, CustomPredicateBatchBuilder, StatementTmplBuilder},
7-
middleware::{
8-
CustomPredicateBatch, CustomPredicateRef, NativePredicate, Params, PodType, Predicate,
9-
KEY_SIGNER, KEY_TYPE,
6+
frontend::{
7+
literal, CustomPredicateBatch, CustomPredicateBatchBuilder, CustomPredicateRef,
8+
NativePredicate, Predicate, StatementTmplBuilder, Value,
109
},
10+
middleware::{self, Params, PodType, KEY_SIGNER, KEY_TYPE},
1111
};
1212

1313
use NativePredicate as NP;
@@ -27,7 +27,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
2727
// there is an attestation pod that's a SignedPod
2828
STB::new(NP::ValueOf)
2929
.arg(("attestation_pod", literal(KEY_TYPE)))
30-
.arg(PodType::MockSigned), // TODO
30+
.arg(middleware::Value::from(PodType::MockSigned)), // TODO
3131
// the attestation pod is signed by (src_or, src_key)
3232
STB::new(NP::Equal)
3333
.arg(("attestation_pod", literal(KEY_SIGNER)))
@@ -37,6 +37,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
3737
.arg(("attestation_pod", literal("attestation")))
3838
.arg(("dst_ori", "dst_key")),
3939
],
40+
"eth_friend",
4041
)?;
4142

4243
println!("a.0. eth_friend = {}", builder.predicates.last().unwrap());
@@ -45,7 +46,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
4546

4647
/// Instantiates an ETHDoS batch
4748
pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
48-
let eth_friend = Predicate::Custom(CustomPredicateRef(eth_friend_batch(params)?, 0));
49+
let eth_friend = Predicate::Custom(CustomPredicateRef::new(eth_friend_batch(params)?, 0));
4950
let mut builder = CustomPredicateBatchBuilder::new("eth_dos_distance_base".into());
5051

5152
// eth_dos_distance_base(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = and<
@@ -74,6 +75,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
7475
.arg(("distance_ori", "distance_key"))
7576
.arg(0),
7677
],
78+
"eth_dos_distance_base",
7779
)?;
7880
println!(
7981
"b.0. eth_dos_distance_base = {}",
@@ -119,6 +121,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
119121
.arg(("intermed_ori", "intermed_key"))
120122
.arg(("dst_ori", "dst_key")),
121123
],
124+
"eth_dos_distance_ind",
122125
)?;
123126

124127
println!(
@@ -147,6 +150,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
147150
.arg(("dst_ori", "dst_key"))
148151
.arg(("distance_ori", "distance_key")),
149152
],
153+
"eth_dos_distance",
150154
)?;
151155

152156
println!(

src/examples/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use custom::{eth_dos_batch, eth_friend_batch};
55
use std::collections::HashMap;
66

77
use crate::backends::plonky2::mock::signedpod::MockSigner;
8+
use crate::frontend::CustomPredicateRef;
89
use crate::frontend::{
910
containers::{Dictionary, Set},
1011
MainPodBuilder, SignedPod, SignedPodBuilder, Statement, Value,
1112
};
12-
use crate::middleware::CustomPredicateRef;
1313
use crate::middleware::{Params, PodType, KEY_SIGNER, KEY_TYPE};
1414
use crate::op;
1515

@@ -94,11 +94,11 @@ pub fn eth_dos_pod_builder(
9494
bob_pubkey: &Value,
9595
) -> Result<MainPodBuilder> {
9696
// Will need ETH friend and ETH DoS custom predicate batches.
97-
let eth_friend = CustomPredicateRef(eth_friend_batch(params)?, 0);
97+
let eth_friend = CustomPredicateRef::new(eth_friend_batch(params)?, 0);
9898
let eth_dos_batch = eth_dos_batch(params)?;
99-
let eth_dos_base = CustomPredicateRef(eth_dos_batch.clone(), 0);
100-
let eth_dos_ind = CustomPredicateRef(eth_dos_batch.clone(), 1);
101-
let eth_dos = CustomPredicateRef(eth_dos_batch.clone(), 2);
99+
let eth_dos_base = CustomPredicateRef::new(eth_dos_batch.clone(), 0);
100+
let eth_dos_ind = CustomPredicateRef::new(eth_dos_batch.clone(), 1);
101+
let eth_dos = CustomPredicateRef::new(eth_dos_batch.clone(), 2);
102102

103103
// ETHDoS POD builder
104104
let mut alice_bob_ethdos = MainPodBuilder::new(params);

0 commit comments

Comments
 (0)