Skip to content

feat(Smt): Reject duplicate keys in inputs#899

Open
iamrecursion wants to merge 1 commit intonextfrom
nondeterministic-tree-updates
Open

feat(Smt): Reject duplicate keys in inputs#899
iamrecursion wants to merge 1 commit intonextfrom
nondeterministic-tree-updates

Conversation

@iamrecursion
Copy link
Collaborator

Describe your changes

This change makes it so all SMT operations that operate on batches of key-value pairs will reject any input where the same key occurs more than once. This ensures that all of the various SMT implementations are coherent on the results they provide as there are no longer order-dependent computations.

This commit introduces no measurable performance change when it comes to the concurrent and sequential compute_mutations versions, and LargeSmt does not suffer any performance regressions either.

I've left LargeSmtForest out of this PR for the simple reason that it already has its own way of handling this. Its input batches SmtUpdateBatch and ForestUpdateBatch always deduplicate and retain the last operation for any key. Please let me know if you'd like to see the forest return an error instead. It's a fairly trivial change.

Performance-wise, best I can tell this causes no regressions. I am having some strange issue with the benchmarks today where some operations will regress and others will stay the same, and then when I re-run others will regress and the prior regressions will go back to normal. If somebody reviewing this could run the following benchmarks before and after this commit to confirm my findings here I would be most appreciative.

  • smt.rs: smt_compute_mutations smt_apply_mutations smt_batch_updates smt_insert
  • large_smt.rs: large_smt_compute_mutations large_smt_apply_mutations large_smt_insert_batch large_smt_insert_batch_to_empty_tree large_smt_insert_batch_to_populated_tree memory_smt_compute_mutations memory_smt_apply_mutations memory_smt_insert_batch

Closes #867.

Checklist before requesting a review

  • Repo forked and branch created from next according to naming convention.
  • Commit messages and codestyle follow conventions.
  • Relevant issues are linked in the PR description.
  • Tests added for new functionality.
  • Documentation/comments updated according to changes.

@iamrecursion iamrecursion self-assigned this Mar 13, 2026
@iamrecursion iamrecursion added the merkle Related to Merkle trees or MMRs label Mar 13, 2026
@iamrecursion iamrecursion force-pushed the nondeterministic-tree-updates branch from 4311770 to b0fc03c Compare March 13, 2026 14:09
@iamrecursion iamrecursion marked this pull request as ready for review March 13, 2026 14:28
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the duplicate-key rejection can be bypassed in batch paths, see inline.

@iamrecursion iamrecursion force-pushed the nondeterministic-tree-updates branch 5 times, most recently from da9c7d5 to 477f1ae Compare March 16, 2026 15:43
@iamrecursion iamrecursion requested a review from huitseeker March 16, 2026 15:46
@iamrecursion
Copy link
Collaborator Author

Good catch on that. I had it in my head that I was sorting directly by key (which implents the behaviour that I want), rather than leaf index. That is now what I am doing.

This change makes it so all SMT operations that operate on batches of
key-value pairs will reject any input where the same key occurs more
than once. This ensures that all of the various SMT implementations are
coherent on the results they provide as there are no longer
order-dependent computations.

This commit introduces no measurable performance change for any impacted
code path. No performance regressions are included.
@iamrecursion iamrecursion force-pushed the nondeterministic-tree-updates branch from 477f1ae to f07e43a Compare March 16, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merkle Related to Merkle trees or MMRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compute_mutations_concurrent uses unstable sort, giving non-deterministic results for duplicate keys

2 participants