-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inclusion/exclusion proofs - very untested
- Loading branch information
1 parent
3f2ecfb
commit 8138341
Showing
7 changed files
with
81 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Set, Tuple, Optional | ||
|
||
from cbrrr import CID | ||
|
||
from .node import MSTNode | ||
from .node_store import NodeStore | ||
from .node_walker import NodeWalker | ||
|
||
class InvalidProof(Exception): | ||
pass | ||
|
||
# works for both inclusion and exclusion proofs | ||
def find_rpath_and_build_proof(ns: NodeStore, root_cid: CID, rpath: str) -> Tuple[Optional[CID], Set[CID]]: | ||
walker = NodeWalker(ns, root_cid) | ||
value = walker.find_rpath(rpath) # returns None if not found | ||
proof = {frame.node.cid for frame in walker.stack} | ||
return value, proof | ||
|
||
def verify_inclusion(ns: NodeStore, root_cid: CID, rpath: str) -> None: | ||
walker = NodeWalker(ns, root_cid) | ||
try: | ||
if walker.find_rpath(rpath) is None: | ||
raise InvalidProof("rpath not present in MST") | ||
except KeyError: | ||
raise InvalidProof("missing MST blocks") | ||
|
||
def verify_exclusion(ns: NodeStore, root_cid: CID, rpath: str) -> None: | ||
walker = NodeWalker(ns, root_cid) | ||
try: | ||
if walker.find_rpath(rpath) is not None: | ||
raise InvalidProof("rpath *is* present in MST") | ||
except KeyError: | ||
raise InvalidProof("missing MST blocks") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters