Expand description
Monetary values within the Sapling shielded pool.
Values are represented in three places within the Sapling protocol:
NoteValue, the value of an individual note. It is an unsigned 64-bit integer (with maximum valueMAX_NOTE_VALUE), and is serialized in a note plaintext.ValueSum, the sum of note values within a SaplingBundle. It is represented as ani128and places an upper bound on the maximum number of notes within a singleBundle.valueBalanceSapling, which is a signed 63-bit integer. This is represented by a user-defined type parameter onBundle, returned byBundle::value_balanceandBuilder::value_balance.
If your specific instantiation of the Sapling protocol requires a smaller bound on
valid note values (for example, Zcash’s MAX_MONEY fits into a 51-bit integer), you
should enforce this in two ways:
- Define your
valueBalanceSaplingtype to enforce your valid value range. This can be checked in itsTryFrom<i64>implementation. - Define your own “amount” type for note values, and convert it to
NoteValueprior to callingBuilder::add_output.
Inside the circuit, note values are constrained to be unsigned 64-bit integers.
§Caution!
An i64 is not a signed 64-bit integer! The Rust documentation calls i64 the
64-bit signed integer type, which is true in the sense that its encoding in memory
takes up 64 bits. Numerically, however, i64 is a signed 63-bit integer.
Fortunately, users of this crate should never need to construct ValueSum directly;
you should only need to interact with NoteValue (which can be safely constructed
from a u64) and valueBalanceSapling (which can be represented as an i64).
Modules§
- testing
test-dependencies - Generators for property testing.
Structs§
- Commitment
Sum - A sum of Sapling value commitments.
- Note
Value - The non-negative value of an individual Sapling note.
- Trapdoor
Sum - A sum of Sapling value commitment blinding factors.
- Value
Commit Trapdoor - The blinding factor for a
ValueCommitment. - Value
Commitment - A commitment to a
ValueSum. - Value
Sum - A sum of Sapling note values.
Enums§
- Balance
Error - A type for balance violations in amount addition and subtraction (overflow and underflow of allowed ranges).
Constants§
- MAX_
NOTE_ VALUE - Maximum note value.