Module value

Module value 

Source
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 value MAX_NOTE_VALUE), and is serialized in a note plaintext.
  • ValueSum, the sum of note values within a Sapling Bundle. It is represented as an i128 and places an upper bound on the maximum number of notes within a single Bundle.
  • valueBalanceSapling, which is a signed 63-bit integer. This is represented by a user-defined type parameter on Bundle, returned by Bundle::value_balance and Builder::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 valueBalanceSapling type to enforce your valid value range. This can be checked in its TryFrom<i64> implementation.
  • Define your own “amount” type for note values, and convert it to NoteValue prior to calling Builder::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§

testingtest-dependencies
Generators for property testing.

Structs§

CommitmentSum
A sum of Sapling value commitments.
NoteValue
The non-negative value of an individual Sapling note.
TrapdoorSum
A sum of Sapling value commitment blinding factors.
ValueCommitTrapdoor
The blinding factor for a ValueCommitment.
ValueCommitment
A commitment to a ValueSum.
ValueSum
A sum of Sapling note values.

Enums§

BalanceError
A type for balance violations in amount addition and subtraction (overflow and underflow of allowed ranges).

Constants§

MAX_NOTE_VALUE
Maximum note value.