Skip to content

Commit

Permalink
Made tweaks from PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rozbb committed Jul 12, 2022
1 parent f7a4a39 commit 4556b1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
29 changes: 10 additions & 19 deletions guiding_docs/api_usage_example/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {
// Start the issuer
let mut issuer_state = load_issuer_state("issuer_state.json");
// Check the issuance request
match issuer_state.issue(&crs_table, &isu_req) {
match issuer_state.issue(&isu_req, &crs_table) {
Some(auth_path) => {
// Issuance check succeeded. Return the auth path
send_to_user(auth_path);
Expand All @@ -73,8 +73,7 @@ fn main() {
// The user computes their membership proofs and saves them for later
user.set_auth_path(auth_path);
user.set_roots(forest_roots);
let tree_proof = user_state.prove_tree_memb(&mut rng, &crs_table);
let forest_proof = user_state.prove_forest_memb(&mut rng, &crs_table);
let memb_proof = user_state.prove_memb(&mut rng, &crs_table);

//
// A user walks into a bar
Expand Down Expand Up @@ -103,8 +102,7 @@ fn main() {
let link_prover = LinkProver::new()
.with_crs(&crs_table)
.with_cred(cred)
.in_forest(forest_proof, &forest_roots)
.in_tree(tree_proof, &my_root)
.in_forest(memb_proof, (&forest_roots, &my_root))
.add_pred("age", age_proof, age_pub_inputs)
.add_pred("expiry", expiry_proof, expiry_pub_inputs)
.add_pred("face", face_proof, face_pub_inputs);
Expand Down Expand Up @@ -182,18 +180,19 @@ impl UserState {
}

// Returns this user's credential
fn cred() -> Com {
fn cred(&self) -> Com {
self.attrs.com()
}

// Returns the root of the tree that our cred resides in
fn tree_root() -> ComTreeRoot {
fn tree_root(&self) -> ComTreeRoot {
self.auth_path.root()
}

/// Proves anything at all about this user. Returns the proof and any public inputs that the
/// verifier will need
fn prove_pred<R, P>(
&self,
rng: &mut R,
pred: &P,
pred_name: &str,
Expand All @@ -213,24 +212,16 @@ impl UserState {
(proof, pub_input)
}

// Proves membership in the tree whose root is in self.auth_path
fn prove_tree_memb<R: Rng>(rng: &mut R, crs_table: &CrsTable) -> TreeProof {
// Proves membership of this cred in the Merkle forest
fn prove_memb<R: Rng>(&self, rng: &mut R, crs_table: &CrsTable) -> MembershipProof {
let cred = self.attrs.com();
self.auth_path
.unwrap()
.prove_membership(rng, &crs_table, cred)
}

// Proves that self.auth_path's tree is in the forest described by `self.roots`
fn prove_forest_memb<R: Rng>(rng: &mut R, crs_table: &CrsTable) -> ForestProof {
let my_root = self.auth_path.root();
self.roots.prove_membership(rng, &my_root, &crs_table)
prove_merkle_membership(rng, crs_table, cred, &self.auth_path, self.roots)
}
}

impl IssuerState {
/// Checks an issuance request and, on success adds it to the tree
fn issue(&mut self, crs_table: &CrsTable, req: &IssuanceReq) -> Option<ComTreePath> {
fn issue(&mut self, req: &IssuanceReq, crs_table: &CrsTable) -> Option<ComTreePath> {
// Get the verifying key for issuance
let issuance_vk = crs_table.get("issuance", CrsType::VerifyingKey).unwrap();

Expand Down
2 changes: 2 additions & 0 deletions guiding_docs/framework_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ link -> precompute and then Show?
make a CrsTable struct??
make AttrsVar, AccountableAttrsVar, not parameterized by the underlying Attr
Make PredicateChecker parameterized over A, and give it an associated type AttrsVar: AllocVar<A>.
Make MembershipProof = (TreeProof, ForestProof);
Make a prove_merkle_membership function

define link prover and verifier like this. Also make a set_pred function to override previous pred values. Order should be defined by the given string, not by order of add_pred

Expand Down

0 comments on commit 4556b1b

Please sign in to comment.