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>
This commit is contained in:
Rob Knight 2025-04-07 14:27:20 -07:00 committed by GitHub
parent 6528914366
commit a6cd02ec2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 538 additions and 113 deletions

View file

@ -3,11 +3,11 @@ use std::sync::Arc;
use anyhow::Result;
use crate::{
frontend::{literal, CustomPredicateBatchBuilder, StatementTmplBuilder},
middleware::{
CustomPredicateBatch, CustomPredicateRef, NativePredicate, Params, PodType, Predicate,
KEY_SIGNER, KEY_TYPE,
frontend::{
literal, CustomPredicateBatch, CustomPredicateBatchBuilder, CustomPredicateRef,
NativePredicate, Predicate, StatementTmplBuilder, Value,
},
middleware::{self, Params, PodType, KEY_SIGNER, KEY_TYPE},
};
use NativePredicate as NP;
@ -27,7 +27,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
// there is an attestation pod that's a SignedPod
STB::new(NP::ValueOf)
.arg(("attestation_pod", literal(KEY_TYPE)))
.arg(PodType::MockSigned), // TODO
.arg(middleware::Value::from(PodType::MockSigned)), // TODO
// the attestation pod is signed by (src_or, src_key)
STB::new(NP::Equal)
.arg(("attestation_pod", literal(KEY_SIGNER)))
@ -37,6 +37,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
.arg(("attestation_pod", literal("attestation")))
.arg(("dst_ori", "dst_key")),
],
"eth_friend",
)?;
println!("a.0. eth_friend = {}", builder.predicates.last().unwrap());
@ -45,7 +46,7 @@ pub fn eth_friend_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
/// Instantiates an ETHDoS batch
pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
let eth_friend = Predicate::Custom(CustomPredicateRef(eth_friend_batch(params)?, 0));
let eth_friend = Predicate::Custom(CustomPredicateRef::new(eth_friend_batch(params)?, 0));
let mut builder = CustomPredicateBatchBuilder::new("eth_dos_distance_base".into());
// 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>> {
.arg(("distance_ori", "distance_key"))
.arg(0),
],
"eth_dos_distance_base",
)?;
println!(
"b.0. eth_dos_distance_base = {}",
@ -119,6 +121,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
.arg(("intermed_ori", "intermed_key"))
.arg(("dst_ori", "dst_key")),
],
"eth_dos_distance_ind",
)?;
println!(
@ -147,6 +150,7 @@ pub fn eth_dos_batch(params: &Params) -> Result<Arc<CustomPredicateBatch>> {
.arg(("dst_ori", "dst_key"))
.arg(("distance_ori", "distance_key")),
],
"eth_dos_distance",
)?;
println!(

View file

@ -5,11 +5,11 @@ use custom::{eth_dos_batch, eth_friend_batch};
use std::collections::HashMap;
use crate::backends::plonky2::mock::signedpod::MockSigner;
use crate::frontend::CustomPredicateRef;
use crate::frontend::{
containers::{Dictionary, Set},
MainPodBuilder, SignedPod, SignedPodBuilder, Statement, Value,
};
use crate::middleware::CustomPredicateRef;
use crate::middleware::{Params, PodType, KEY_SIGNER, KEY_TYPE};
use crate::op;
@ -94,11 +94,11 @@ pub fn eth_dos_pod_builder(
bob_pubkey: &Value,
) -> Result<MainPodBuilder> {
// Will need ETH friend and ETH DoS custom predicate batches.
let eth_friend = CustomPredicateRef(eth_friend_batch(params)?, 0);
let eth_friend = CustomPredicateRef::new(eth_friend_batch(params)?, 0);
let eth_dos_batch = eth_dos_batch(params)?;
let eth_dos_base = CustomPredicateRef(eth_dos_batch.clone(), 0);
let eth_dos_ind = CustomPredicateRef(eth_dos_batch.clone(), 1);
let eth_dos = CustomPredicateRef(eth_dos_batch.clone(), 2);
let eth_dos_base = CustomPredicateRef::new(eth_dos_batch.clone(), 0);
let eth_dos_ind = CustomPredicateRef::new(eth_dos_batch.clone(), 1);
let eth_dos = CustomPredicateRef::new(eth_dos_batch.clone(), 2);
// ETHDoS POD builder
let mut alice_bob_ethdos = MainPodBuilder::new(params);