Skip to content

Add relative timelock enforcement functions - #45

Merged
Hrom131 merged 9 commits into
BlockstreamResearch:devfrom
schoen:feat/timelocks
Nov 23, 2026
Merged

Hrom131 merged 9 commits into
BlockstreamResearch:devfrom
schoen:feat/timelocks

Conversation

@schoen

@schoen schoen commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Add timelocks.simf with relative timelock enforcement functions enforce_relative_distance and enforce_relative_duration. These are replacements for the deprecated jets jet::check_lock_distance and jet::check_lock_duration, whose version of this functionality is significantly incorrect (see BlockstreamResearch/simplicity@fc466a8). 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 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_duration a 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 elementsd to simulate mining blocks, we have valid tests for Distance cases (enforcing that a certain number of blocks have been mined on top of the original transaction containing the input UTXO). This is handled via blocks_to_mine in the run_with_sequence function added to tests/stdlib/common/core.rs.

(tx_version_below_2_fails now uses a version 1 transaction whose input declares a sufficient timelock.)

[PR description updated on 2026-11-20 based on feedback from @Hrom131.]

Comment thread simf/lib/timelocks.simf Resolved
Comment thread simf/lib/timelocks.simf Resolved
Comment thread tests/stdlib/timelocks.rs Resolved
Comment thread tests/stdlib/timelocks.rs Resolved
Comment thread docs/stdlib.json Resolved
schoen and others added 9 commits November 20, 2026 14:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move function comments into `///` doc comments matching the library style.
- Factor the shared version check and sequence parsing into a private helper.
- Trim test comments that restated the code.
- Make tx_version_below_2_fails declare a sufficient timelock, so the
  version check is the only thing that can reject it.
- Explain what's wrong with the deprecated jets in stdlib.json.
- Fix the timelocks.md link in WISHLIST.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schoen

schoen commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

I think this CI failure is still spurious. It failed at the Simplex startup stage, with no actual tests failed. I'll rerun the CI.

@schoen schoen closed this Nov 20, 2026
@schoen schoen reopened this Nov 20, 2026
@schoen schoen closed this Nov 20, 2026
@schoen schoen reopened this Nov 20, 2026
@schoen schoen closed this Nov 21, 2026
@schoen schoen reopened this Nov 21, 2026

@Hrom131 Hrom131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@Hrom131
Hrom131 merged commit 0a35639 into BlockstreamResearch:dev Nov 23, 2026
11 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants