Commit graph

512 commits

Author SHA1 Message Date
fb458b1e8e fix warning in first commit 2024-08-22 18:28:08 -06:00
5538585506 feat(smt): implement root-checked insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-22 18:27:48 -06:00
0433e5bb47 feat: export Merkle get_value() in the trait 2024-08-22 18:27:36 -06:00
1c26227fc2 feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 18:27:29 -06:00
1bd60dd376 fix clippy lint 2024-08-22 18:24:34 -06:00
aa4356e1a4 feat: implement root-checked Merkle tree insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-22 18:24:27 -06:00
b55e6b9bf8 delete commented out line 2024-08-22 18:23:43 -06:00
d46e4c7257 feat: implement root-checked Merkle tree insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-22 18:23:17 -06:00
8044e0c49c clarify as initial work 2024-08-22 18:14:44 -06:00
accda40e4b feat: implement root-checked Merkle tree insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-22 18:13:26 -06:00
38b09a57af give root-checked insertion commit a real commit message 2024-08-22 16:19:30 -06:00
b2e8ab66bd feat: implement root-checked Merkle tree insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is a step towards issue 222, and an immediate step towards
0xPolygonMiden/miden-node issue 149.

Future work: as we generalize pre-validation for other mutations we will
likely want a separate type to represent prospective mutations on the
Merkle tree and their validity, (like the `ChangeSet` type suggested in
the issue).
2024-08-22 15:59:02 -06:00
20894b945c replace iter::once hack with an Option 2024-08-22 15:54:35 -06:00
00e2be79a4 feat: export Merkle get_value() in the trait 2024-08-22 15:54:24 -06:00
1795ef4ba3 WIP: smt: implement root-checked insertion 2024-08-22 15:54:24 -06:00
52ab7bca97 feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 15:54:24 -06:00
99bac324a3 put 'prospective' first in tests for prospective commit 2024-08-22 14:50:24 -06:00
4d1f33ab67 WIP: smt: implement root-checked insertion 2024-08-22 14:50:06 -06:00
d7af60d037 feat: export Merkle get_value() in the trait 2024-08-22 14:49:31 -06:00
6178074b9f feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 14:49:29 -06:00
91c4260120 mark get_value commit as non-wip 2024-08-22 14:42:51 -06:00
0c97562ea2 WIP: smt: implement root-checked insertion 2024-08-22 14:32:20 -06:00
70131e892e feat: export Merkle get_value() in the trait 2024-08-22 14:32:20 -06:00
a4677dd99b remove the redundant prospective test in full/mod.rs 2024-08-22 14:17:00 -06:00
0f67239bd3 feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 14:16:17 -06:00
1662a0a8da WIP: smt: implement root-checked insertion 2024-08-22 14:16:17 -06:00
2eb7a84543 WIP: add and implement get_value() to Smt trait 2024-08-22 14:16:17 -06:00
6f1de8c22d give perspective leaf hashing a real commit message 2024-08-22 14:12:18 -06:00
6670b94ba7 WIP: smt: implement root-checked insertion 2024-08-22 13:55:39 -06:00
1307e2c948 WIP: add and implement get_value() to Smt trait 2024-08-22 13:55:39 -06:00
4c19f364ca feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 13:55:39 -06:00
6921ba0442 squash the two hash_prospective_leaf commits 2024-08-22 13:48:10 -06:00
e21b9ab8d3 WIP: smt: implement root-checked insertion 2024-08-22 13:47:06 -06:00
4a9b54f4f7 WIP: add and implement get_value() to Smt trait 2024-08-22 13:47:06 -06:00
e3dae8c8ba WIP: implement hash_prospective_leaf() 2024-08-22 13:46:51 -06:00
ac69789525 rustfmt the things we didn't 2024-08-22 13:45:49 -06:00
78ba0d262c WIP: remove a *bunch* of allocations and clones in hash_prospective_leaf 2024-08-22 13:43:04 -06:00
64d2bd1aaa WIP: smt: implement root-checked insertion 2024-08-22 13:43:04 -06:00
9d0506454a rebase onto next 2024-08-22 13:32:14 -06:00
b974005f91 WIP: add and implement get_value() to Smt trait 2024-08-22 13:31:46 -06:00
124807bf8b WIP: remove a *bunch* of allocations and clones in hash_prospective_leaf 2024-08-22 13:31:46 -06:00
1d29c8971f WIP: implement hash_prospective_leaf() 2024-08-22 13:31:46 -06:00
81da8e9bca WIP: smt: implement root-checked insertion 2024-08-22 13:31:46 -06:00
434ceeb771 fixup tests and cleanup hash_prospective_leaf 2024-08-22 13:31:39 -06:00
7c7a35e887 WIP: remove a *bunch* of allocations and clones in hash_prospective_leaf 2024-08-22 13:31:09 -06:00
fdca917a43 WIP: smt: implement root-checked insertion 2024-08-22 13:31:09 -06:00
Paul-Henry Kajfasz
f4a9d5b027
Merge pull request #323 from 0xPolygonMiden/phklive-consistent-ci
Update `Makefile` and `CI`
2024-08-22 08:22:20 -07:00
Paul-Henry Kajfasz
ee42d87121
Replace i. by 1. 2024-08-22 16:14:19 +01:00
Paul-Henry Kajfasz
b1cb2b6ec3
Fix comments 2024-08-22 15:21:59 +01:00
d575bf1406 drop 'refactor: make Smt's node recomputation pure' 2024-08-21 15:23:45 -06:00