Add state commitment functions for persistent storage via Taproot - #46
Open
schoen wants to merge 5 commits into
Open
Add state commitment functions for persistent storage via Taproot#46schoen wants to merge 5 commits into
schoen wants to merge 5 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
storage.simfwith state commitment functionsloadandstore.This is based on @apoelstra's stage management MVP functions, originally written around December 2025, with minor name changes and comment edits by me. Versions of these functions have been used in many covenants over the last several months. I'd like them to be in the standard library so that everyone can use them easily without copying and pasting them as "folklore" about how to do basic Simplicity state management.
There are 13 Simplex test cases created by Claude. I asked Claude for each individual test case, and I'm satisfied that they test the most important cases and that they work properly. We test that the storage does work when it should, and that loading or storing the wrong state (or storing to a Taproot or non-Taproot output other than a copy of the current program) fails. The other good thing is that we also test interoperability between state commitments generated by
rust-elementscalls and state commitments generated by thestorefunction's jets calls (which, as Claude pointed out to me, are two different implementations of portions of the relevant logic). This confirms that we can assert commitments from outside of a contract (like withhal-simplicityor LWK or a wallet) and verify them from inside of the contract. We already know this because we already do this in some actual contracts, but it's also directly tested here.As in #45, Claude wrote comments about what the various tests and helper functions do, which could be unnecessarily verbose, and which I'm happy to trim down if that would be preferable.
There may be a further discussion about whether we can usefully extend state commitments to let cooperating covenants load or store one another's state values, but this should wait for the covenant convention stuff (to include documented recommendations for how to accomplish this).