Compare commits

...

23 commits

Author SHA1 Message Date
1402b8dcf7 leaf cloning is acceptable! 2024-08-27 14:32:43 -06:00
113832d6a4 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-27 14:27:39 -06:00
2696e4884c feat(smt): export get_value() in the trait 2024-08-27 14:27:39 -06:00
a00a3c3974 feat(smt): impl hashing 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. Since almost all leaves are very
small, we can just clone the leaf and modify a copy.

Future work could optimize the uncommon SmtLeaf::Multiple case and
avoid a heap clone by combining the normal insertion logic and the
normal hash logic without an intermediate leaf value.
2024-08-27 14:27:39 -06:00
78e08626fb fixup SimpleSmt get_value per review 2024-08-27 14:10:43 -06:00
52c35b12c3 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-27 14:10:27 -06:00
448e59884f feat(smt): export get_value() in the trait 2024-08-27 14:10:27 -06:00
7abce338bf wrap hash_prospective_leaf's comments at 100 2024-08-27 14:02:22 -06:00
b08196ec9b 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-27 14:02:03 -06:00
d5e5778ad3 feat(smt): export get_value() in the trait 2024-08-27 14:01:29 -06:00
5b7d759f89 feat(smt): impl hashing 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-27 14:01:16 -06:00
c9fc6325db fix ci 2024-08-22 18:57:24 -06:00
5a0a9b1b8f 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:56:59 -06:00
2822b597c3 feat(smt): export get_value() in the trait 2024-08-22 18:29:31 -06:00
abe0cfaa1f feat(smt): impl hashing 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:29:19 -06:00
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

2
series

@ -1 +1 @@
Subproject commit accda40e4bd3a4bc6305eb9d7880e5ee5138f6d4
Subproject commit 113832d6a4b1d5375ff2f5f5348ca63aacbdd059