You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/documentation/witness.md
+16-42Lines changed: 16 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
# Witnesses in SimplicityHL development
2
2
3
-
The [execution model](../execution-model) for Simplicity [contract](../glossary.md#contract)s allows the user who is proposing a [transaction](../glossary.md#transaction) to provide input values to the contract. The meaning of these inputs is specific to an individual contract, but in general they help the contract to confirm that the proposed transaction is authorized according to the contract's rules. This is necessary because anyone can propose transactions to spend assets at any time, so a contract needs a clear way to distinguish which transactions are appropriate and which aren't.
3
+
This document describes *witnesses*, which are transaction-time input data for a Simplicity contract provided by the user proposing the transaction. A witness explains what the user wants the contract to do, and convinces the contract that this action is authorized.
4
+
5
+
When you interact with a Simplicity [contract](../glossary.md#contract) on the blockchain, you'll need to build and attach witness data for each [transaction](../glossary.md#transaction).
6
+
7
+
## Witness overview
8
+
9
+
The [execution model](../execution-model) for Simplicity [contract](../glossary.md#contract)s allows the user who is proposing a [transaction](../glossary.md#transaction) to provide input values to the contract. Each contract expects different inputs, but in general they help confirm that the proposed transaction is authorized according to the contract's rules. This is necessary because anyone can propose transactions to spend assets at any time, so a contract needs a clear way to distinguish which transactions are appropriate and which aren't.
4
10
5
11
One can think of a Simplicity program as a function that deterministically answers "yes" or "no" to each proposed transaction. The input data for this function will be the specific transaction details, together with some user-supplied inputs which are collectively known as a *witness*. The form of the expected witness is determined in advance by the Simplicity program, just as any function definition determines what kind of input that function expects.
6
12
@@ -22,7 +28,7 @@ The rest of this document provides details about the means of creating witnesses
22
28
23
29
The [simc](../glossary.md#simc) compiler is able to compile (in this context, "serialize") a witness using a contract-specific text file called a `.wit` file. The output is a base64 string which can then be provided to other tools like `hal-simplicity pset finalize` to be incorporated into a complete transaction.
24
30
25
-
The `.wit` file is formatted as a JSON file. Each top-level entry in the file has a *name* which has two elements: `value` and `type`. The entry name is used in the SimplicityHL program as a variable name to refer to this specific entry. The `value` and `type` are both strings containing Rust-like code for the data value and data type annotation for the entry. For example,
31
+
The `.wit` file is a JSON file. Each top-level entry in the file has a *name* which has two elements: `value` and `type`. The entry name is used in the SimplicityHL program as a variable name to refer to this specific entry. The `value` and `type` are both strings containing Rust-like code for the data value and data type annotation for the entry. For example,
26
32
27
33
```json
28
34
{
@@ -34,14 +40,14 @@ The `.wit` file is formatted as a JSON file. Each top-level entry in the file ha
34
40
"value": "3",
35
41
"type": "u8"
36
42
},
37
-
"yep_or_nope": {
43
+
"yes_or_no": {
38
44
"value": "false",
39
45
"type": "bool"
40
46
}
41
47
}
42
48
```
43
49
44
-
This witness provides two separate integer values, available to a SimplicityHL program as `witness::amount` and `witness::x`, and a boolean value available as `witness::yep_or_nope`. The witness file indicates that `witness::amount` is a 32-bit integer (`u32`) equal to `100`, while `witness::x` is an 8-bit integer (`u8`) equal to `3`, and `witness:yep_or_nope` is a boolean (`bool`) equal to `false`.
50
+
This witness provides two separate integer values, available to a SimplicityHL program as `witness::amount` and `witness::x`, and a boolean value available as `witness::yes_or_no`. The witness file indicates that `witness::amount` is a 32-bit integer (`u32`) equal to `100`, while `witness::x` is an 8-bit integer (`u8`) equal to `3`, and `witness:yes_or_no` is a boolean (`bool`) equal to `false`.
45
51
46
52
Note that even numeric values are represented as JSON strings within the `.wit` file (`"value": "100"`, not `"value": 100`).
47
53
@@ -83,15 +89,13 @@ The base64 value beginning `+6WeUroy...` is the complete serialized witness, inc
83
89
84
90
## Other tools for building witness data
85
91
86
-
In other development contexts, witness data doesn't necessarily need to be written to disk as part of a `.wit` file. The `rust-simplicity` library can be used to build a witness based on a Rust data structure containing the relevant values. If you're developing your Simplicity contract inside a Rust project and interacting with the contract (by creating transactions) from Rust code, you can easily write Rust functions to generate an appropriate witness and bypass the `.wit` file process entirely.
92
+
Witness data doesn't necessarily need to be written to disk in a `.wit` file. It may be assembled in memory by a client application that's interacting with an on-chain contract. (The syntax and data types described in the current document may be relevant even if you are building a witness in a different environment or with different tools.)
87
93
88
-
The syntax and data types described in the current document may be relevant even if you are building a witness in a different environment or with different tools.
94
+
For example, if you're developing in Rust, you can build a witness based on a Rust data structure containing the relevant values. You can write Rust functions to generate an appropriate witness and bypass the `.wit` file process entirely. <ahref="https://github.com/BlockstreamResearch/smplx">Simplex</a> now includes basic Rust artifact generation, automatically creating Rust witness generation code on the basis of an input `.simf` file.
89
95
90
96
Several instances of this pattern can be found in <ahref="https://github.com/BlockstreamResearch/simplicity-contracts/tree/main/crates/contracts/src">the examples in the `simplicity-contracts` repository</a>. Each contract there is accompanied by a `build_witness.rs` file defining what the witness consumed by that contract should look like. The details of each are different according to the structure of the required witness, but each ends with a definition like `pub fn build_x_witness()` to complete the witness-building process.
91
97
92
-
<ahref="https://github.com/BlockstreamResearch/smplx">Simplex</a> now includes basic Rust artifact generation. This includes automatically creating Rust witness generation code on the basis of an input `.simf` file.
93
-
94
-
The <ahref="https://github.com/Blockstream/lwk">Liquid Wallet Kit</a> SDK library ("`lwk`") is currently (January 2026) adding Simplicity support. This will also provide equivalent functionality for building Simplicity witnesses in various supported programming languages, again without explicitly creating a `.wit` file. For example, it will be possible to use `lwk` to create a witness from Rust, Python, or JavaScript. This document will be updated with more information once this integration is complete.
98
+
The <ahref="https://github.com/Blockstream/lwk">Liquid Wallet Kit</a> SDK library ("`lwk`") is currently (April 2026) adding Simplicity support. This will also provide equivalent functionality for building Simplicity witnesses in various supported programming languages, again without explicitly creating a `.wit` file. For example, it will be possible to use `lwk` to create a witness from Rust, Python, or JavaScript. This document will be updated with more information once this integration is complete.
95
99
96
100
## Types
97
101
@@ -225,36 +229,6 @@ Some more complex type system features that can be used in creating witnesses in
225
229
226
230
### More built-in types
227
231
228
-
Other built-in SimplicityHL types and alias types may also be used in witnesses, including `Pubkey` for [public key](../glossary.md#public-key)s, `Distance` for timelock distances, and various others, but there's usually less frequent reason to use these compared to integers and signatures. The complete list of available built-in type aliases and their type definitions is <ahref="https://github.com/BlockstreamResearch/SimplicityHL/blob/master/src/types.rs#L815">available in the SimplicityHL source code</a>, but you should generally only use these when passing them as parameters to a specific jet that expects them. These types' names are always capitalized in SimplicityHL code, like `Signature`, `Pubkey`, `Distance`, `Duration`.
229
-
230
-
The type signatures of the <ahref="https://github.com/BlockstreamResearch/SimplicityHL/blob/c412dfc684a47c9f430195c20d5a906294b27575/src/jet.rs#L32">inputs</a> and <ahref="https://github.com/BlockstreamResearch/SimplicityHL/blob/c412dfc684a47c9f430195c20d5a906294b27575/src/jet.rs#L533">outputs</a> to each jet are specified in the jet implementation and will be provided as an integral part of the jet documentation.
231
-
232
-
<!-- The complete list of builtin type aliases as of 2026-01-28 is
233
-
234
-
* Ctx8
235
-
* Pubkey
236
-
* Message
237
-
* Message64
238
-
* Signature
239
-
* Scalar
240
-
* Fe
241
-
* Ge
242
-
* Gej
243
-
* Point
244
-
* Height
245
-
* Time
246
-
* Distance
247
-
* Duration
248
-
* Lock
249
-
* Outpoint
250
-
* Confidential1
251
-
* ExplicitAsset
252
-
* Asset1
253
-
* ExplicitAmount
254
-
* Amount1
255
-
* ExplicitNonce
256
-
* Nonce
257
-
* TokenAmount1
258
-
259
-
but some of these are impossible to explain without the context of the individual jet that consumes them, which is often very technical and not relevant to most contract development.
260
-
-->
232
+
Although integers and signatures are most commonly used, other [built-in SimplicityHL types](../../simplicityhl-reference/type) and [alias types](../../simplicityhl-reference/type_alias) may also be used in witnesses, including `Pubkey` for [public key](../glossary.md#public-key)s, `Distance` for [timelock](../glossary.md#timelock) distances, and various others. You can use these for clarity when passing them as parameters to a specific jet that expects them. These types' names are always capitalized in SimplicityHL code, like `Signature`, `Pubkey`, `Distance`, `Duration`.
233
+
234
+
The type signatures of the inputs and outputs to each jet are included in [the jet documentation](../jets).
0 commit comments