Add relative timelock enforcement functions - #45
Open
schoen wants to merge 5 commits into
Open
Conversation
This was referenced Aug 15, 2026
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
timelocks.simfwith relative timelock enforcement functionsenforce_relative_distanceandenforce_relative_duration. These are direct replacements for the deprecated jetsjet::check_lock_distanceandjet::check_lock_duration. You can learn more about how to use these at https://docs.simplicity-lang.org/documentation/timelocks (which currently includes a more verbose version of these same functions, which I plan to trim from there once they're part of the standard library!).I wrote these functions based on conversations with @apoelstra and @roconnor-blockstream about how these jets were supposed to work, and I've also tested
enforce_relative_durationa bit in contracts.There are 11 Simplex test cases created by Claude. I asked Claude for each individual test case, and I'm satisfied that they test most of the most important cases and that they work properly. The remaining gap is that Simplex currently can't simulate the passage of realtime effectively (see BlockstreamResearch/smplx#126), so we lack tests for the happy path of
enforce_relative_duration, and for its failure cases where sufficient realtime has actually passed but is not correctly asserted in the transaction.Since Simplex can ask
elementsdto simulate mining blocks, we have valid tests forDistancecases (enforcing that a certain number of blocks have been mined on top of the original transaction containing the input UTXO). This is handled viablocks_to_minein therun_with_sequencefunction added totests/common/core.rs.Claude also wrote comments about what the various tests and helper functions do. These comments certainly do read like they were written by an AI and may be unnecessarily verbose about Claude's reasoning about the internals. I'm happy to trim these comments or rewrite them if they seem too verbose to anyone.
It's possible that
tx_version_below_2_failsisn't a very good test because it may just be shoehorning a version1into a transaction that is not otherwise valid as a version 1 transaction, and then confirming that it gets rejected (so it could be more realistic to try to construct a valid version 1 transaction here, in order to ensure that the transaction isn't rejected for the wrong reason).