Expand description
§rust-simplicity
This is the official Rust library of the Simplicity Language.
Simplicity is a low-level, typed functional language designed to be a drop-in alternative for Bitcoin’s Tapscript. It offers static resource bounds and has a formal specification (in Rocq) which allows the creation of machine-checkable proofs of program behavior.
It is currently deployed on Blockstream’s Liquid, which is a sidechain resembling Bitcoin in many ways; but which differs in many Script-relevant ways (e.g. supporting multiple assets and using Confidential Transactions). We expect by the end of 2025 to directly support Bitcoin, so that Simplicity can be used on a custom regtest chain.
Simplicity is a very low-level language. If you are simply looking to develop with the language, you may wish to use SimplicityHL instead.
§Nodes
When creating and manipulating Simplicity programs, there are three node types that you may use when creating programs.
ConstructNode
represents a program under construction. Type inference is done on the program as it is being built, which must be done within a scope containing atypes::Context
.CommitNode
represents a complete program for which witness and disconnect nodes are unpopulated. This can be used to produce a CMR, which in turn is used to generate an address for use on-chain.RedeemNode
represents a program as it is embedded on-chain. Unused nodes must be pruned, and any disconnect or witness nodes which remain must appear on-chain. This is the only node type which has a canonical encoding.
§Quick Start
use simplicity::node::CoreConstructible;
use simplicity::types::Context;
use simplicity::{ConstructNode, jet::Core};
use std::sync::Arc;
// Create a trivial Simplicity program
let program = Context::with_context(|ctx| {
let construct = Arc::<ConstructNode<Core>>::unit(&ctx);
construct.finalize_types().unwrap()
});
// Encode the program to bytes
let encoded: Vec<u8> = simplicity::write_to_vec(|w| {
program.encode_without_witness(w)
});
Re-exports§
pub extern crate bitcoin;
pub extern crate byteorder;
pub extern crate elements;
pub extern crate ghost_cell;
pub extern crate hashes;
pub extern crate hex;
pub use crate::policy::sighash;
pub use crate::policy::Policy;
pub use crate::policy::Preimage32;
pub use crate::policy::Satisfier;
pub use crate::policy::SimplicityKey;
pub use crate::policy::ToXOnlyPubkey;
pub use crate::policy::Translator;
pub use crate::bit_machine::BitMachine;
pub use crate::node::CommitNode;
pub use crate::node::ConstructNode;
pub use crate::node::Hiding;
pub use crate::node::RedeemNode;
pub use simplicity_sys as ffi;
Modules§
- bit_
machine - Simplicity Execution
- dag
- General DAG iteration utilities
- decode
- Decoding
- encode
- Encoding
- human_
encoding - The Simplicity Human-Readable Encoding
- jet
- Simplicity jets
- node
- Simplicity Program Nodes
- policy
- Function-like Expression Language
- types
- Types and Type Inference
Macros§
- decode_
bits - impl_
midstate_ wrapper - Convenience macro for wrappers of
Midstate
. - impl_
serde_ string
Structs§
- Amr
- Annotated Merkle root
- BitIter
- Bitwise iterator formed from a wrapped bytewise iterator. Bytes are interpreted big-endian, i.e. MSB is returned first
- BitWriter
- Bitwise writer formed by wrapping a bytewise
io::Write
. Bits are written in big-endian order. Bytes are filled with zeroes for padding. - Cmr
- Commitment Merkle root
- Cost
- CPU cost of a Simplicity expression.
- Early
EndOf Stream Error - Attempted to read from a bit iterator, but there was no more data
- Fail
Entropy - 512-bit opaque blob of data used to seed
Fail
nodes - Ihr
- Identity Hash Root
- Imr
- Identity Merkle Root
- Node
Bounds - Bounds on the resources required by a node during execution on the Bit Machine
- Tmr
- Type Merkle root
- Value
- A Simplicity value.
- Value
Ref - Reference to a value, or to a sub-value of a value.
- Word
- A Simplicity word. A value of type
TWO^(2^n)
for some0 ≤ n < 32
.
Enums§
- BitIter
Close Error - Closed out a bit iterator and there was remaining data.
- Decode
Error - Error decoding a program from the bit encoding.
- Error
- Error type for simplicity
- Finalize
Error - Error finalizing a program (i.e. typechecking and pruning).
- Parse
Error - Error parsing a program or witness (decoding it from a string encoding).
- u2
- Two-bit type used during decoding
Traits§
- BitCollector
- Functionality for Boolean iterators to collect their bits or bytes.
- HasCmr
- Trait for types that have a Commitment Merkle Root.
Functions§
- encode_
natural - Encode a positive integer to bits.
- encode_
value - Encode a value to bits.
- encode_
witness - Encode witness data to bits.
- leaf_
version - Return the version of Simplicity leaves inside a tap tree.
- write_
to_ vec - Write the result of a bit operation into a byte vector and return the vector.