Skip to content

Commit 918768a

Browse files
authored
Merge pull request #12 from apoelstra/2025-10/gettingstarted
Improvements to "getting started" guide
2 parents bffd85d + daa0eeb commit 918768a

File tree

5 files changed

+76
-51
lines changed

5 files changed

+76
-51
lines changed

docs/documentation/how-simplicity-works.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Simplicity is a typed, combinator-based, functional smart contract language with
55
Frequently used operations are implemented as jets. Jets are predefined, highly efficient building blocks, allowing contracts to execute complex conditional payments, options, and multi-party transactions with predictable resource usage and no reliance on a central authority.
66

77
Let's delve deeper into how Simplicity works within the Bitcoin ecosystem:
8-
8+
99
## SimplicityHL Compilation and Simplicity Bytecode
1010

1111
SimplicityHL is a developer-friendly front-end language, engineered to simplify the process of writing smart contracts by offering a syntax akin to the Rust programming language. It effectively abstracts away the intricate, low-level functional programming details inherent in raw Simplicity. The SimplicityHL Compiler is the dedicated toolchain responsible for translating SimplicityHL code into its foundational Simplicity representation. This approach is crucial because, while Simplicity offers profound mathematical expressiveness, its low-level nature means that practically, developers will write in higher-level languages that then compile down to Simplicity, complete with formal proofs of their correct operation.
@@ -41,21 +41,16 @@ Jets are optimised native code implementations that act as "shortcuts" for large
4141
Examples of jets include:
4242

4343
- **Cryptographic functions**: These are crucial for secure smart contracts. Specific examples include the SHA-256 compression function and Schnorr signature verification (BIP-340). Other elliptic curve functions for `secp256k1` are also included, such as point verification, scalar arithmetic, and field element operations.
44-
4544
- **Arithmetic operations**: Simplicity includes jets for various arithmetic functions, such as 32-bit addition, subtraction, and multiplication. General multi-bit logic operations like `complement`, `and`, `or`, and `xor` are also implemented as jets.
46-
4745
- **Introspection operations**: These allow smart contracts to examine transaction data. Examples include `script-cmr` (script commitment Merkle root), `internal-key`, `version`, `lock-time`, `output-value`, `input-value`, `tapleaf-version`, and `tappath`.
48-
4946
- **Time locks**: Jets exist for various time-based conditions like `check-lock-height`, `check-lock-time`, `tx-height-lock`, `tx-time-lock`, `tx-distance-lock`, and `tx-duration-lock`, which assert conditions based on block height or time.
50-
5147
- **Elements-specific jets**: For the Liquid Network, Simplicity includes additional jets related to Elements features such as issuances, assets, amounts, range proofs, and surjection proofs.
5248

5349
The weight of a Simplicity program, including its jets, is calculated using static analysis before execution from the number of iterations needed to execute the program on the Bit Machine. If this weight is larger than the on-chain footprint of the program, the program must be padded to meet the weight. This means that blockchain validators and transactors continue to have one metric for a transaction's cost: the weight of the transaction, even though the computational cost to validators is not a direct function of this weight. This crucial feature enables users to determine the maximum computational resources (CPU time and memory) a program will require, even for worst-case scenarios. This pre-computation capability is a fundamental defence against denial-of-service attacks, as transactions with excessively costly scripts can be rejected early.
5450

5551
Simplicity employs a fine-grained cost function that allows for precisely calibrated fees based on the actual resources consumed, balancing affordability for legitimate use with disincentives for network abuse. There are two categories of jets:
5652

5753
1. **Ordinary jets**: Handled locally by implementations.
58-
5954
2. **Discounted jets**: These receive special treatment under consensus rules, with explicitly defined cost overrides that are determined through benchmarking, rather than being calculated solely by the Bit Machine's default rules.
6055

6156
This mechanism ensures that highly efficient native code implementations (jets) are correctly accounted for, making complex smart contracts economically viable and predictable for Bitcoin's robust, long-term infrastructure. Simplicity thus empowers builders with unprecedented security and flexibility, solidifying Bitcoin's role as a foundation for a resilient, censorship-resistant financial future.

docs/documentation/jets-explained.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ This process accelerates computation without changing the underlying meaning, wh
77
Think of a Jet as a shortcut:
88

99
- Without Jets: Simplicity executes everything step by step using combinators (correct but slow).
10-
1110
- With Jets: the same logic runs much faster, but the result is **provably identical**.
1211

1312
---
1413

1514
## Why are Jets Important?
1615

1716
- **Performance**: Blockchain validation must be fast. Jets dramatically reduce computation time.
18-
1917
- **Security**: Each Jet is rigorously specified and formally proven to behave exactly like its Simplicity equivalent.
20-
2118
- **Consensus Safety**: Jets have fixed, predictable costs to prevent denial-of-service attacks.
22-
2319
- **Scalability**: More complex smart contracts become feasible without compromising verification speed.
2420

2521
## Jet Creation Process

docs/documentation/jets-overview.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,47 @@ Jets are available for common bit widths: **1, 8, 16, 32, 64, 128, 256**. Operat
66
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
77

88
**`add_N`** - Addition with carry flag
9+
910
- `(uN, uN) → (bool, uN)`
1011
- `let (carry, sum) = jet::add_32(x, y);`
1112

12-
### Subtraction Operations
13+
### Subtraction Operations
1314
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
1415

1516
**`subtract_N`** - Subtraction with borrow flag
17+
1618
- `(uN, uN) → (bool, uN)`
1719

1820
### Multiplication Operations
1921
**Available bit widths:** 8, 16, 32, 64, 128
2022

2123
**`multiply_N`** - Multiplication returning double-width result
24+
2225
- `(uN, uN) → u(2N)`
2326

2427
### Division Operations
2528
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
2629

2730
**`divide_N`** - Division returning quotient and remainder
31+
2832
- `(uN, uN) → (uN, uN)`
2933

3034
### Increment/Decrement Operations
3135
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
3236

3337
**`increment_N`** / **`decrement_N`** - Add/subtract 1 with overflow flag
38+
3439
- `uN → (bool, uN)`
3540

3641
## Comparison Jets
3742
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
3843

3944
**`eq_N`**, **`le_N`**, **`lt_N`** - Equality and comparison operations
45+
4046
- `(uN, uN) → bool`
4147

4248
**`max_N`**, **`min_N`** - Return larger/smaller value
49+
4350
- `(uN, uN) → uN`
4451

4552
## Bitwise Integer Operations
@@ -48,20 +55,24 @@ Jets are available for common bit widths: **1, 8, 16, 32, 64, 128, 256**. Operat
4855
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
4956

5057
**`and_N`**, **`or_N`**, **`xor_N`** - Bitwise logical operations
58+
5159
- `(uN, uN) → uN`
5260

5361
**`complement_N`** - Bitwise NOT
62+
5463
- `uN → uN`
5564

5665
### Bit Shifting Operations
5766
**Available bit widths:** 1, 8, 16, 32, 64, 128, 256
5867

5968
**`shift_left_N`**, **`shift_right_N`** - Bit shifting
69+
6070
- `(uN, u8) → uN`
6171

6272
## Type Conversion Jets
6373

6474
**`left_pad_low_A_B`** - Zero-pad smaller type to larger type
75+
6576
- `uA → uB` (e.g., `u16 → u32`)
6677
- Example: `jet::left_pad_low_16_32(x)`
6778

@@ -74,26 +85,33 @@ Jets are available for common bit widths: **1, 8, 16, 32, 64, 128, 256**. Operat
7485
### Hash Functions
7586

7687
**`sha_256_ctx_8_init`** - Initialize SHA-256 context
88+
7789
- `() → Ctx8`
7890

7991
**`sha_256_ctx_8_add_4`** - Add 4-byte word to SHA-256 context
92+
8093
- `(Ctx8, u32) → Ctx8`
8194

8295
**`sha_256_ctx_8_finalize`** - Finalize SHA-256 hash
96+
8397
- `Ctx8 → u256`
8498

8599
### Digital Signatures
86100

87101
**`bip_0340_check`** - Verify BIP-340 Schnorr signature (returns bool)
102+
88103
- `(Pubkey, u256, Signature) → bool`
89104

90105
**`bip_0340_verify`** - Verify BIP-340 Schnorr signature (panics if invalid)
106+
91107
- `((Pubkey, u256), Signature) → ()`
92108

93109
## Bitcoin-Specific Jets
94110

95111
**`sig_all_hash`** - Compute SIGHASH_ALL signature hash
112+
96113
- `() → u256`
97114

98115
**`check_lock_height`** - Validate height-based timelock
99-
- `u32 → ()`
116+
117+
- `u32 → ()`

docs/getting-started/cli.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This guide shows the complete command-line workflow for developing and deploying Simplicity contracts using `simply` and `elements-cli`.
66

77
**Tools used:**
8+
89
- `simply` - SimplicityHL development toolkit
910
- `elements-cli` - Liquid node client
1011
- `curl` - API requests to Liquid testnet
@@ -115,10 +116,12 @@ simply withdraw --entrypoint always_true.simf --txid c2f44551601034af3cc0d004b5b
115116
```
116117

117118
Replace:
119+
118120
- `<txid>` - From step 4
119121
- `<destination>` - Where to send funds
120122

121123
**What this does:**
124+
122125
- Fetches UTXO from blockchain
123126
- Builds complete transaction
124127
- Encodes Simplicity program and witness
@@ -214,6 +217,7 @@ let sighash = tx_env.c_tx_env().sighash_all();
214217
```
215218

216219
**Sighash includes:**
220+
217221
- All transaction inputs and outputs
218222
- Genesis hash (network identifier)
219223
- Spent UTXO data
@@ -247,8 +251,9 @@ You would need to:
247251
3. Your private key
248252

249253
**Signing options:**
254+
250255
- Liquid wallet with signing capabilities
251-
- Hardware wallet with Schnorr support
256+
- Hardware wallet with Schnorr support
252257
- Software cryptographic libraries
253258
- External signing services
254259

@@ -412,6 +417,7 @@ simply run --entrypoint contract.simf --logging debug
412417
```
413418

414419
**Shows execution trace:**
420+
415421
- Each step
416422
- Jet calls
417423
- Debug output
@@ -431,6 +437,7 @@ simply build --entrypoint contract.simf --stats
431437
```
432438

433439
**Shows:**
440+
434441
- Cost bounds
435442
- Memory usage
436443
- Program size
@@ -457,6 +464,7 @@ https://blockstream.info/liquidtestnet/api
457464
```
458465

459466
**Endpoints:**
467+
460468
- `/address/<address>/utxo` - Get UTXOs
461469
- `/tx/<txid>` - Get transaction
462470
- `/tx/<txid>/status` - Check confirmation

0 commit comments

Comments
 (0)