Implement Containers (Dictionary,Set,Array) on top of MerkleTree. And restructure the code. (#55)
* Implement Containers (Dictionary,Set,Array) on top of MerkleTree. And restructure the code.
- Reorganize the code grouping backends, middleware, frontend, (crypto) primitives.
- Add types Dictionary,Set,Array at the middleware layer, so that
it can be used both by the backend and frontend. The Dictionary, Set,
Array use the merkletree differently as specified at
f2575d1524/book/src/values.md (dictionary-array-set)
- The containers introduce the trait Container, which has the
method 'cm()'. At the current version this uses a merkletree
under the hood, and the method 'cm' returns the merkle root.
- Ideally neither frontend nor backend use the MerkleTree type, and they
use the wrappers {Dictionary,Set,Array}. Note that the current commit
the MerkleTree is used at the mock-backend to check internal values, but
not at the struct types.
- updated the spec's merkletree section updating the defined interface
- add github ci to run the tests
---------
Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
This commit is contained in:
parent
f2575d1524
commit
bb865a4fea
14 changed files with 330 additions and 94 deletions
|
|
@ -145,28 +145,30 @@ For the current use cases, we don't need to prove that the key exists but the va
|
|||
|
||||
```rust
|
||||
impl MerkleTree {
|
||||
/// builds a new `MerkleTree` where the leaves contain the given key-values
|
||||
fn new(kvs: HashMap<Value, Value>) -> Self;
|
||||
|
||||
/// returns the root of the tree
|
||||
fn root(&self) -> Result<Hash>;
|
||||
fn root(&self) -> Hash;
|
||||
|
||||
/// returns the value at the given key
|
||||
fn get(&self, key: &Value) -> Result<Value>;
|
||||
|
||||
/// returns a boolean indicating whether the key exists in the tree
|
||||
fn contains(&self, key: &Value) -> bool;
|
||||
|
||||
/// returns a proof of existence, which proves that the given key exists in
|
||||
/// the tree. It returns the `value` of the leaf at the given `key`, and
|
||||
/// the `MerkleProof`.
|
||||
fn prove(&self, key: &Value) -> Result<(Value, MerkleProof)>;
|
||||
|
||||
/// the tree. It returns the `MerkleProof`.
|
||||
fn prove(&self, key: &Value) -> Result<MerkleProof>;
|
||||
|
||||
/// returns a proof of non-existence, which proves that the given `key`
|
||||
/// does not exist in the tree
|
||||
fn prove_nonexistence(&self, key: &Value) -> Result<MerkleProof>;
|
||||
|
||||
|
||||
/// verifies an inclusion proof for the given `key` and `value`
|
||||
fn verify(root: Hash, proof: &MerkleProof, key: &Value, value: &Value) -> Result<()>;
|
||||
|
||||
|
||||
/// verifies a non-inclusion proof for the given `key`, that is, the given
|
||||
/// `key` does not exist in the tree
|
||||
fn verify_nonexistence(root: Hash, proof: &MerkleProof, key: &Value) -> Result<()>;
|
||||
|
||||
|
||||
/// returns an iterator over the leaves of the tree
|
||||
fn iter(&self) -> std::collections::hash_map::Iter<Value, Value>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,14 +51,15 @@ The array, set and dictionary types are similar types. While all of them use [a
|
|||
- `leaf.key=hash(original_key)`
|
||||
- `leaf.value=hash(original_value)`
|
||||
- **array**: the elements are placed at the value field of each leaf, and the key field is just the array index (integer)
|
||||
- `leaf.value=original_value`
|
||||
- `leaf.key=i`
|
||||
- `leaf.value=original_value`
|
||||
- **set**: the value field of the leaf is unused, and the key contains the hash of the element
|
||||
- `leaf.key=hash(original_value)`
|
||||
- `leaf.value=0`
|
||||
|
||||
In the three types, the merkletree under the hood allows to prove inclusion & non-inclusion of the particular entry of the {dictionary/array/set} element.
|
||||
|
||||
A concrete implementation of dictionary, array, set can be found at [pod2/src/middleware/containers.rs](https://github.com/0xPARC/pod2/blob/main/src/middleware/containers.rs).
|
||||
|
||||
<br><br>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue