# Selecting the chain (Elements or Bitcoin) in SimplicityHL source

**URL:** <https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88>\
**Category:** SimplicityHL development\
**Created:** [October 9, 2026, 2:52pm UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88 "2026-10-09T14:52:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LesterEvSe](https://yyz1.discourse-cdn.com/flex007/user_avatar/community.simplicity-lang.org/lesterevse/32/67_2.png) [@LesterEvSe](https://community.simplicity-lang.org/u/LesterEvSe)\
**Post date:** [October 9, 2026, 2:52pm UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/1 "2026-10-09T14:52:49Z")

</div>

I’m working on Bitcoin support in SimplicityHL. [#437](https://github.com/BlockstreamResearch/SimplicityHL/pull/437) adds the Bitcoin jets. it’s independent and ready for review. [#436](https://github.com/BlockstreamResearch/SimplicityHL/pull/436) (draft) lets programs be compiled for Bitcoin. It depends on rust-simplicity [#385](https://github.com/BlockstreamResearch/rust-simplicity/pull/385)–#388, which add Bitcoin jet CMRs, costs and execution.

The open question is how a program says which chain it is for. The problem is that the same code is often valid on both chains, but it compiles to a different program. If the chain is chosen outside the source, compiling for the wrong one gives no error, just a program for the wrong chain.

There are two ways to solve this:

1. **A compiler option.** Ivan’s [#364](https://github.com/BlockstreamResearch/SimplicityHL/pull/364) adds `simc --target elements|core`, and Bitcoin could be one more value. It needs no language change, but the source doesn’t say which chain it’s for, so the CMR depends on how the compiler was invoked. Tools that use the library directly, like Simplex, would also have to carry this setting for every contract.
2. **A header in the source** (what #436 does now):  
`target bitcoin;`  
No header means Elements, so existing code doesn’t change. The compiler checks that the jet set matches the header, and Simplex can compile Bitcoin contracts without any changes.

I prefer the header, and the two can work together, because `--target` still makes sense for Core and custom jet sets, which aren’t chains.

### Library files

In #436, only the entry file (with `main` function) has a header, and imported files are checked against whatever it says. That makes libraries implicitly chain-agnostic: a library can rely on Elements transaction rules and still be used in a Bitcoin program without any error.

So I’d like every file to declare which chains it supports, for example `target bitcoin;` for Bitcoin only, or `target elements, bitcoin;` for both. No header means `elements`, and every imported file must support the chain of the entry file, but we also can make it explicit with `target elements;`.

I’d be glad to hear your thoughts on these questions:

- Which approach is better: a source header (#436), a compiler option (#364), or both?
- Is `target` a good name? `chain` might be clearer, but [#425](https://github.com/BlockstreamResearch/SimplicityHL/pull/425) adds a `chain!` built-in.
- Should the header only name chains (`elements`, `bitcoin`), or also `core`?

---

<div class="post-metadata">

**Author:** ![ivanlele](https://avatars.discourse-cdn.com/v4/letter/i/4da419/32.png) [@ivanlele](https://community.simplicity-lang.org/u/ivanlele)\
**Post date:** [October 9, 2026, 3:31pm UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/2 "2026-10-09T15:31:29Z")

</div>

It would be cool to delegate the decision which target to use to the framework, so we wouldn’t have to deal with adding boilerplate.

We could just have this target specified in `Simplex.toml`.

It would look similar to how Rust ecosystem works: Cargo decides which target to use for the platform, If not specified otherwise, and it just passes it automaticly to `rustc`via the `--target` CLI parameter.

---

<div class="post-metadata">

**Author:** ![LesterEvSe](https://yyz1.discourse-cdn.com/flex007/user_avatar/community.simplicity-lang.org/lesterevse/32/67_2.png) [@LesterEvSe](https://community.simplicity-lang.org/u/LesterEvSe)\
**Post date:** [October 9, 2026, 3:48pm UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/3 "2026-10-09T15:48:43Z")

</div>

Agreed that `Simplex.toml` should choose the chain, like Cargo chooses the target. But in Rust the source can still restrict it (for example with `#[cfg(target_os = ...)]`). I’d like the same in SimplicityHL: Simplex picks the chain, and a `target` header in the source restricts which chains the code supports, so the compiler can check that everything we build for Bitcoin actually supports Bitcoin.

---

<div class="post-metadata">

**Author:** ![schoen](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@schoen](https://community.simplicity-lang.org/u/schoen)\
**Post date:** [October 10, 2026, 1:19am UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/4 "2026-10-10T01:19:39Z")

</div>

Still another possibility is something that generates a nonfatal warning if the target is not the intended one (only relevant to code that compiles for multiple targets). “Warning: input file `some.simf` expects deployment on target `bitcoin`, but was compiled for target `elements`.”

Possibly related: @apoelstra and @stringhandler have been working on a “binary format” for representing compiled SimplicityHL programs together with additional data; that format can indicate which chain is targeted by a compiled program, so it can carry along this information into later deployment steps. That might be somewhat relevant and useful for this discussion.

---

<div class="post-metadata">

**Author:** ![LesterEvSe](https://yyz1.discourse-cdn.com/flex007/user_avatar/community.simplicity-lang.org/lesterevse/32/67_2.png) [@LesterEvSe](https://community.simplicity-lang.org/u/LesterEvSe)\
**Post date:** [October 12, 2026, 8:50am UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/5 "2026-10-12T08:50:35Z")

</div>

Hm, good idea, I think we can do it, since we already have `Severity` in `errors.rs`

---

<div class="post-metadata">

**Author:** ![stringhandler](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@stringhandler](https://community.simplicity-lang.org/u/stringhandler)\
**Post date:** [October 12, 2026, 8:59am UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/6 "2026-10-12T08:59:57Z")

</div>

I have been using the same .simf files for bitcoin and elements. I don’t think there is a general need for specifying the chain, however there are some scenarios where you would want to restrict it.

In most cases, this is not the concern of the `.simf` source. The jets used alone determine which targets it can be compiled for. For example, the post quantum Shrincs jets can run on any target that has the core jets, but the `.simf` files used by simplicity\_unchained cannot be compiled for any other target.

The one place I would say it’s necessary to restrict a `.simf` file, is when using a constant for validating timelocks. Because the block times are different, the `.simf` file changes meanings between compilations.

```auto
fn cancel_spend(sender_sig: Signature) {
    let timeout: Height = 1000;
    jet::check_lock_height(timeout);
    let sender_pk: Pubkey = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5; // 2 * G
    checksig(sender_pk, sender_sig)
}

```

This example above has different meanings on bitcoin and elements, and having a compiler hint or restriction in the `.simf` file makes sense.

One statement I don’t agree with here:

> The problem is that the same code is often valid on both chains, but it compiles to a different program.

This statement alone is not enough to justify adding statements to `.simf` syntax. We already have a case where compiling with debug symbols generates a different program, and in future, compilation of `.simf` to `simplicity` might change.

I would suggest this:

1. if there is no compiler hint (e.g. `target = bitcoin`), then the compiler can attempt any target. Compilation fails for jets that are not known. NOTE: this is different from your suggestion that absence means “target=elements”
2. If there is a compiler hint (e.g. `target = bitcoin`), the compiler SHOULD fail for attempts to compile to a different target. My suggestion is a compilation failure with the option to override.

---

<div class="post-metadata">

**Author:** ![schoen](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@schoen](https://community.simplicity-lang.org/u/schoen)\
**Post date:** [October 20, 2026, 3:38am UTC](https://community.simplicity-lang.org/t/selecting-the-chain-elements-or-bitcoin-in-simplicityhl-source/88/7 "2026-10-20T03:38:14Z")

</div>

> [@stringhandler](#):
>
> The one place I would say it’s necessary to restrict a `.simf` file, is when using a constant for validating timelocks. Because the block times are different, the `.simf` file changes meanings between compilations.
> 
> ```css
> fn cancel_spend(sender_sig: Signature) {
> let timeout: Height = 1000;
> jet::check_lock_height(timeout);
> let sender_pk: Pubkey = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5; // 2 * G
> checksig(sender_pk, sender_sig)
> }
> 
> ```
> 
> This example above has different meanings on bitcoin and elements, and having a compiler hint or restriction in the `.simf` file makes sense.

This gives me a thought, although I think it’s a questionable thought because of its effect on backwards compatibility. My thought is that these could be distinguished with more specific types. If we had chain-specific types for `Height` then calling a jet on one chain with a value meant for the other chain would be a type error. For example, we could have `let timeout: ElementsHeight = 1000;` and then calling `jet::check_lock_height(timeout);` would be valid on Elements but not on Bitcoin, due to different type signatures.

(I think this is not true today as casting may be implicit, but I think it’s meant to be true with some version of the future type system.)

Are there any possible cases other than timelocks where there are identically-named jets with different semantics?
