Skip to content

Commit

Permalink
inclusion/exclusion proof builder helper
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Dec 21, 2024
1 parent 651eba7 commit fdd56e9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/atmst/mst/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from .node_store import NodeStore
from .node_walker import NodeWalker

class InvalidProof(Exception):
# validating a proof failed
class InvalidProof(ValueError):
pass

# constructing a proof failed
class ProofError(ValueError):
pass

# works for both inclusion and exclusion proofs
Expand All @@ -16,6 +21,18 @@ def find_rpath_and_build_proof(ns: NodeStore, root_cid: CID, rpath: str) -> Tupl
proof = {frame.node.cid for frame in walker.stack}
return value, proof

def build_exclusion_proof(ns: NodeStore, root_cid: CID, rpath: str) -> Set[CID]:
value, proof = find_rpath_and_build_proof(ns, root_cid, rpath)
if value is not None:
raise ProofError("can't build exclusion proof for a record that exists!")
return proof

def build_inclusion_proof(ns: NodeStore, root_cid: CID, rpath: str) -> Set[CID]:
value, proof = find_rpath_and_build_proof(ns, root_cid, rpath)
if value is None:
raise ProofError("can't build inclusion proof for a record that doesn't exist!")
return proof

def verify_inclusion(ns: NodeStore, root_cid: CID, rpath: str) -> None:
walker = NodeWalker(ns, root_cid)
try:
Expand Down

0 comments on commit fdd56e9

Please sign in to comment.