Detailed API reference
Structs
Maybe
Encapsulates an optionally present value. If isSome is false, value
should be default<T> by convention.
struct Maybe<T> {
isSome: Boolean;
value: T;
}
Either
Disjoint union of A and B. Iff isLeft if true, left should be
populated, otherwise right. The other should be default< > by convention.
struct Either<A, B> {
isLeft: Boolean;
left: A;
right: B;
}
NativePoint
A point on the proof systems embedded curve, in affine coordinates.
Only outputs of elliptic curve operations are actually guaranteed to lie on the curve.
struct NativePoint {
x: Field;
y: Field;
}
MerkleTreeDigest
The root hash of a Merkle tree, represented by a single Field.
struct MerkleTreeDigest { field: Field; }
MerkleTreePathEntry
An entry in a Merkle tree path, indicating if the path leads left or right, and
the root of the sibling node. Primarily used in MerkleTreePath
struct MerkleTreePathEntry {
sibling: MerkleTreeDigest;
goesLeft: Boolean;
}
MerkleTreePath
A path in a depth n Merkle tree, leading to a leaf of type T.
Primarily used for merkleTreePathRoot.
This can be constructed from witnesses that use the compiler output's
findPathForLeaf and pathForLeaf functions.
struct MerkleTreePath<#n, T> {
leaf: T;
path: Vector<n, MerkleTreePathEntry>;
}
ContractAddress
The address of a contract, used as a recipient in sendShielded,
sendImmediateShielded,
createZswapOutput, and mintShieldedToken.
struct ContractAddress { bytes: Bytes<32>; }
ShieldedCoinInfo
The description of a newly created shielded coin, used in outputting shielded coins, or spending/receiving shielded coins that originate in the current transaction.
nonce can be deterministically derived with evolveNonce.
Used in:
struct ShieldedCoinInfo {
nonce: Bytes<32>;
color: Bytes<32>;
value: Uint<128>;
}
QualifiedShieldedCoinInfo
The description of an existing shielded coin in the ledger, ready to be spent.
Used in:
struct QualifiedShieldedCoinInfo {
nonce: Bytes<32>;
color: Bytes<32>;
value: Uint<128>;
mtIndex: Uint<64>;
}
ZswapCoinPublicKey
The public key used to output a ShieldedCoinInfo to a user, used as a
recipient in sendShielded, sendImmediateShielded, and
createZswapOutput.
struct ZswapCoinPublicKey { bytes: Bytes<32>; }
ShieldedSendResult
The output of sendShielded and sendImmediateShielded,
detailing the created shielded coin, and the change from spending the input, if
applicable.
struct ShieldedSendResult {
change: Maybe<ShieldedCoinInfo>;
sent: ShieldedCoinInfo;
}
UserAddress
The public key of a user, used as a recipient in sendUnshielded
and mintUnshieldedToken.
struct UserAddress { bytes: Bytes<32>; }
Circuits
some
Constructs a Maybe<T> containing an element of type T
circuit some<T>(value: T): Maybe<T>;
none
Constructs a Maybe<T> containing nothing
circuit none<T>(): Maybe<T>;
left
Construct an Either<A, B> containing the A item of the disjoint
union
circuit left<A, B>(value: A): Either<A, B>;
right
Constructs an Either<A, B> containing the B item of the disjoint
union
circuit right<A, B>(value: B): Either<A, B>;
transientHash
Builtin transient hash compression function
This function is a circuit-efficient compression function from arbitrary values to field elements, which is not guaranteed to persist between upgrades. It should not be used to derive state data, but can be used for consistency checks.
Although this function returns a hash of its inputs, it is not considered sufficient
to protect its input from disclosure.
If its input contains any value returned from a witness, the program must acknowledge
disclosure (via a disclose wrapper) if the result can be stored in the public ledger,
returned from an exported circuit, or passed to another contract via a cross-contract call.
circuit transientHash<T>(value: T): Field;
transientCommit
Builtin transient commitment function
This function is a circuit-efficient commitment function over arbitrary types, and a field element commitment opening, to field elements, which is not guaranteed to persist between upgrades. It should not be used to derive state data, but can be used for consistency checks.
Unlike transientHash, this function is considered sufficient to protect
its input from disclosure, under the assumption that the rand argument is
sufficiently random.
Thus, even if its input contains a value or values returned from one or more
witnesses, the program need not acknowledge disclosure (via a disclose wrapper) if
the result can be stored in the public ledger, returned from an exported circuit, or
passed to another contract via a cross-contract call.
circuit transientCommit<T>(value: T, rand: Field): Field;
persistentHash
Builtin persistent hash compression function
This function is a non-circuit-optimised compression function from arbitrary values to a 256-bit bytestring. It is guaranteed to persist between upgrades, and to consistently use the SHA-256 compression algorithm. It should be used to derive state data, and not for consistency checks where avoidable.
The note about disclosing under transientHash also applies to this function.
circuit persistentHash<T>(value: T): Bytes<32>;
persistentCommit
Builtin persistent commitment function
This function is a non-circuit-optimised commitment function from arbitrary values representable in Compact, and a 256-bit bytestring opening, to a 256-bit bytestring. It is guaranteed to persist between upgrades, and use the SHA-256 compression algorithm. It should be used to derive state data, and not for consistency checks where avoidable.
The note about disclosing under transientCommit also applies to this function.
circuit persistentCommit<T>(value: T, rand: Bytes<32>): Bytes<32>;