Expand description
Simplicity Program Nodes
The types in this module are used to represent Simplicity expressions as DAGs. The nodes of this DAG are individual combinators along with some cached data about the node, which depends on the specific node type.
All nodes represent the root of an expression. Expressions whose source and target types are both unit are called “programs”. Generally speaking, any nodes that users hold directly will be programs.
There are three main node types:
-
crate::RedeemNode
represents a Simplicity node as it exists on the blockchain. Every witness node is populated with a correctly-typedValue
, every disconnect node has a child, every non-executed branch of acase
combinator is pruned, and there is nothing you can do to modify the expression.RedeemNode
s can be executed on the bit machine and have complete types and resource bounds, and can be serialized in the consensus bit-encoding. -
CommitNode
represents a Simplicity node as it is committed to on the blockchain. This means that witness and (TODO) disconnect nodes are not populated, but type inference is complete and resource bounds are available.case
combinators may have pruned children (in which case they are instead consideredassertl
orassertr
combinators), or not.There is a bit-encoding for
CommitNode
s which is essentially only used by this library. It consists of the bit-encoding.of the combinators, fully shared except that witness and disconnect nodes (and their ancestors) are unshared. No witness data is included.TODO there is also a human-readable encoding.
-
ConstructNode
represents an “under-construction” Simplicity expression. These nodes’ types are not necessarily complete, and are inferred as the program is constructed. This is the only node that you can programmatically construct. It has no encoding, human-readable or bitwise, and is intended to exist only ephemerally.
The following conversions are possible between the node types:
-
ConstructNode::finalize_types
converts aConstructNode
to aCommitNode
by setting any free variables, as well as the source and target of the root node, to unit.This conversion requires no input from the user but may fail with a type error, in case of infinitely-sized types or in the case that the unit bounds cannot be applied.
-
CommitNode::finalize
converts aCommitNode
to aRedeemNode
by attaching witnesses to each witness node, and deciding whether to hide branches for eachcase
node. -
CommitNode::unfinalize_types
converts aCommitNode
to aConstructNode
by throwing away all types and re-inferring them. It cannot fail. -
RedeemNode::unfinalize
converts aRedeemNode
to aCommitNode
by throwing away witness and (TODO) disconnect data. It cannot recover pruned branches so is of limited usefulness, but it is included for completeness.
Structs§
- Commit
- Commit
Data - Construct
- Construct
Data - Display
- Convenience structure for displaying a Simplictiy expression with its witness.
- Display
Expr - Display a Simplicity expression as a linear string.
- Hiding
- Wrapper that allows a node to be “hidden” during program construction.
- NoDisconnect
- Null data type used as dummy for
crate::node::Marker::Disconnect
- NoWitness
- Null data type used as dummy for
Marker::Witness
- Node
- A node in a Simplicity expression.
- Redeem
- Redeem
Data - Simple
Finalizer - Basic finalizer which converts a
super::CommitNode
to asuper::RedeemNode
by attaching witness data from an iterator.
Enums§
- Hide
- A decision about which, if any, child branches of a
case
combinator to hide during aNode::convert
conversion - Inner
- Internal “Simplicity DAG” structure.
Traits§
- Constructible
- Converter
- The primary trait controlling how a node conversion is done.
- Core
Constructible - Disconnect
Constructible - Disconnectable
- Trait representing a “disconnected expression”.
- JetConstructible
- Marker
- Witness
Constructible