Commit graph

257 commits

Author SHA1 Message Date
Augusto F. Hack
429d3bab6f
feat: add support for MMR to the MerkleStore 2023-04-04 22:33:01 +02:00
Augusto F. Hack
1df4318399
feat: add node iterator to MerkleTree 2023-04-04 22:11:21 +02:00
Bobbin Threadbare
433b467953 feat: optimized hash_elements for blake3 hasher 2023-04-04 01:06:51 -07:00
Augusto F. Hack
f8a62dae76
chore: remove simple_smt::Store 2023-03-31 03:10:01 +02:00
Victor Lopez
d37f3f5e84
feat: Add depth as store SMT argument
Prior to this commit, MerkleStore allowed the creation of Sparse Merkle
tree only with the maximum depth of 63. However, this doesn't fit the
Tiered Sparse Merkle tree requirements, as it will contain trees of
depth 16.

This commit adds the `depth` argument to the MerkleStore methods that
will create Sparse Merkle trees.
2023-03-30 01:13:05 +02:00
Bobbin Threadbare
80171af872
Merge pull request #114 from 0xPolygonMiden/v0.2.0-release-prep
Prepare v0.2 release
2023-03-24 23:50:41 -07:00
Augusto Hack
75af3d474b
Merge pull request #113 from 0xPolygonMiden/hacka-merkle-store-fix-empty-roots
bugfix: fix internal nodes of for empty leafs of a SMT
2023-03-24 23:26:48 +01:00
Augusto F. Hack
9e6c8ff700
bugfix: fix internal nodes of for empty leafs of a SMT
The path returned by `EmptySubtreeRoots` starts at the root, and goes to
the leaf. The MerkleStore constructor assumed the other direction, so
the parent/child hashes were reversed.

This fixes the bug and adds a test.
2023-03-24 23:22:31 +01:00
Bobbin Threadbare
a58922756a chore: update crate versions, dependencies, and CHANGELOG 2023-03-24 14:58:19 -07:00
Augusto F. Hack
7957cc929a
feat: added MerkleStore serde 2023-03-24 21:44:36 +01:00
Victor Lopes
854892ba9d
Merge pull request #111 from 0xPolygonMiden/vlopes11-increase-empty-subtrees
feat: add empty subtree constants to cover u8::MAX depth
2023-03-23 22:50:37 +01:00
Bobbin Threadbare
ce38ee388d
Merge pull request #104 from 0xPolygonMiden/hacka-store-docs
Store docs
2023-03-23 13:11:04 -07:00
Augusto F. Hack
2d1bc3ba34
store: added user documentation on usage and purpose 2023-03-23 14:19:37 +01:00
Victor Lopez
2ff96f40cb
feat: add empty subtree constants to cover u8::MAX depth
Prior to this commit, we limited the constants count to 64 for the empty
subtrees depth computation. This is a hard-assumption that every tree of
Miden will have a depth up to 64 - and will cause undefined behavior if
it doesn't.

With the introduction of `MerkleStore::merge_roots` and the deprecation
of `mtree_cwm` instruction from the VM, this assumption is broken and
the user might end with trees with depth greater than 64. This broken
assumption could lead to attack vectors.

We can easily fix that by extending the pre-computed hashes list to the
maximum of `u8` (i.e. 255). This will have zero impact on functionality,
and will be completely safe to use without hard assumptions.
2023-03-23 12:59:47 +01:00
Bobbin Threadbare
9531d2bd34 fix: to paths reduction of MerklePathSet 2023-03-23 01:12:02 -07:00
Bobbin Threadbare
c79351be99
Merge pull request #107 from 0xPolygonMiden/hacka-store-add-merkle-paths
store: added with_merkle_paths constructor
2023-03-22 16:14:45 -07:00
Augusto F. Hack
0375f31035
feat: added utility to format MerkleTree and MerklePath to hex
Example formatted MerkleTree:

```
880abe452320966617646e7740b014954300f19a28780a0889d62ff33f4b0534
  1ade1369091efa31201e9b60c9c28874d0ddce5362b335135a6bb4c917285983
  3e60a9c843b4bb19f7a0572102e6507195f5240767a396335fd21981b048b807
    0100000000000000000000000000000000000000000000000000000000000000
    0200000000000000000000000000000000000000000000000000000000000000
    0300000000000000000000000000000000000000000000000000000000000000
    0400000000000000000000000000000000000000000000000000000000000000
```

Example formatted MerklePath:

```
[0400000000000000000000000000000000000000000000000000000000000000, 1ade1369091efa31201e9b60c9c28874d0ddce5362b335135a6bb4c917285983]
```
2023-03-22 21:53:05 +01:00
Augusto F. Hack
b250752883
store: added with_merkle_paths constructor
And unit tests for each constructor type.
2023-03-22 14:17:12 +01:00
Augusto F. Hack
d6cbd178e1
chore: clarified assert message 2023-03-22 11:30:19 +01:00
Victor Lopez
84086bdb95
feat: add merkle path containers and return them on tree update
Returning tuples is often confusing as they don't convey meaning and it
should be used only when there is no possible ambiguity.

For `MerkleStore`, we had a couple of tuples being returned, and reading
the implementation was required in order to distinguish if they were
leaf values or computed roots.

This commit introduces two containers that will self-document these
returns: `RootPath` and `ValuePath`. It will also update `set_node` to
return both the new root & the new path, so we can prevent duplicated
traversals downstream when updating a node (one to update, the second to
fetch the new path/root).
2023-03-21 20:45:01 +01:00
Augusto F. Hack
17eb8d78d3 chore: storage -> store 2023-03-21 09:45:36 +01:00
Victor Lopez
8cb245dc1f
bugfix: reverse merkle path to match other structures
The store builds the path from root to leaf, this updates the code to
return a path from leaf to root, as it is done by the other structures.

This also added custom error for missing root.
2023-03-21 09:45:29 +01:00
Victor Lopez
867b772d9a
fix: merkle store panics on bounds
Prior to this commit, the MerkleStore panicked under certain bounds. It
will prevent such panics by using checked operations.

ilog2, for instance, will panic when the operand is zero. However, there
is a documentation rule enforcing the merkle tree to be size at least 2.
If this rule is checked, then the panic is impossible.
2023-03-18 02:20:11 +01:00
Augusto F. Hack
669ebb49fb
bugfix: check if the requested root is in the storage 2023-03-16 23:26:02 +01:00
Victor Lopez
91667fd7de
refactor: add derive proc macros to merkle store
This commit introduce common derive proc macros to MerkleStore. These
are required downstream as the in-memory storage can be cloned.

It also introduces constructors common to the other types of the crate
that will help to build a merkle store, using a build pattern.
2023-03-16 10:28:45 +01:00
Augusto F. Hack
88a646031f
feat: add merkle store 2023-03-15 17:34:42 +01:00
Victor Lopez
3a6a4fcce6
feat: refactor simple smt to use empty subtree constants
Prior to this commit, there was an internal procedure with the merkle
trees to compute empty sub-tree for arbitrary depths.

However, this isn't ideal as this code can be reused in any merkle
implementation that uses RPO as backend.

This commit introduces a structure that will generate these empty
subtrees values.
2023-03-07 20:44:42 +01:00
Augusto F. Hack
32d37f1591
feat: merkle mountain range 2023-03-02 13:07:55 +01:00
Bobbin Threadbare
ae3f14e0ff
Merge pull request #74 from 0xPolygonMiden/hacka-node-index-docs
docs: mention tree form order of NodeIndex docs
2023-02-22 12:19:45 -08:00
Augusto F. Hack
dfb073f784
docs: mention tree form order of NodeIndex docs 2023-02-22 17:23:03 +01:00
Victor Lopez
35b255b5eb
feat: re-export winter-crypto Hasher, Digest & ElementHasher
This commit introduces the re-export of the listed primitives.

They will be used inside Miden to report the security level of the
picked primitive, as well as other functionality.

closes #72
2023-02-22 16:56:14 +01:00
Victor Lopez
0af45b75f4
feat: upgrade to winterfell 0.5 2023-02-20 23:57:41 +01:00
Bobbin Threadbare
3c9a5235a0 docs: fix typos in doc comments 2023-02-17 11:58:23 -08:00
Victor Lopez
9307178873
feat: add from_elements to NodeIndex 2023-02-16 21:14:07 +01:00
Victor Lopez
0799b1bb9d
feat: add merkle node index
This commit introduces a wrapper structure to encapsulate the merkle
tree traversal.

related issue: #36
2023-02-15 23:53:01 +01:00
Victor Lopez
21a8cbcb45
feat: add merkle path wrapper
A Merkle path is a vector of nodes, regardless of the Merkle tree
implementation.

This commit introduces an encapsulation for such vector, also to provide
functionality that is common between different algorithms such as
opening verification.

related issue: #36
2023-02-13 22:43:13 +01:00
Victor Lopez
ed36ebc542
fix: sponge pad panics on input
closes #44
2023-02-09 13:06:06 +01:00
Kaneki (カネキ ケン)
f399df5def
Merge pull request #47 from 0xPolygonMiden/kaneki-domain-separator
refactor merge in domain tests
2023-02-01 13:21:24 +00:00
0xKanekiKen
37c6f003c4
tests: refactor merge_in_domain tests
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
2023-02-01 13:14:03 +00:00
Kaneki (カネキ ケン)
6de7730e30
Merge pull request #40 from 0xPolygonMiden/kaneki-domain-separator
Domain separator during merge
2023-01-23 20:20:38 +00:00
0xKanekiKen
5757b896fe
test: unit tests for merge in domain method
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
2023-01-23 20:17:34 +00:00
0xKanekiKen
ce2cbe704b
refactor: reexport publiccoin & publiccoinerror from winterfell
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
2023-01-23 16:50:30 +00:00
0xKanekiKen
bc6191b3fa
feat: new merge method for 2 digest with a domain separator
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
2023-01-23 16:26:53 +00:00
Bobbin Threadbare
4f65d01df4 feat: add PartialEq and Eq traits to Merkle structs 2022-12-27 19:40:58 -08:00
Victor Lopes
aa12215d30
Merge pull request #27 from 0xPolygonMiden/add-simple-smt
feat: add simple sparse merkle tree
2022-12-14 14:32:40 +01:00
Victor Lopez
5fd0d692e8
feat: add simple sparse merkle tree
This commit moves the previous implementation of `SparseMerkleTree` from
miden-core to this crate.

It also include a couple of new tests, a bench suite, and a couple of
minor fixes. The original API was preserved to maintain compatibility
with `AdviceTape`.

closes #21
2022-12-14 14:26:01 +01:00
Anjan Roy
b4f9d60981
chg: don't assume we're only working with base field elements, consider extension field elements too
See https://github.com/0xPolygonMiden/crypto/pull/29#discussion_r1045108928 where it was suggested.

Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
2022-12-12 09:49:33 +04:00
Anjan Roy
0d713af4ac
chg: don't assume that default features are available on all targets
Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
2022-12-10 12:49:38 +04:00
Anjan Roy
aa4e313690
chg: first convert all elements to little endian bytes and then consume them in a single call to blake3 hasher
Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
2022-12-10 11:48:19 +04:00
Bobbin Threadbare
9782992662 feat: improve blake3 sequential hashing performance 2022-12-09 13:51:16 -08:00