zips
zips copied to clipboard
[protocol spec] [Orchard book] Clarify that Orchard note values are _defined_ as `u64`, not just used as such
In Sapling (and Sprout before it), note values were defined as having range 0..MAX_MONEY
. However, note values themselves never directly interact with the consensus rules; instead we have:
- Note values are used inside their respective circuits, where they are only constrained to have range
u64
. -
vpub_old
,vpub_new
, andvalueBalanceSapling
enable funds to move into and out of the value pools, and are directly constrained to range0..MAX_MONEY
or-MAX_MONEY..MAX_MONEY
as relevant.
Thus note values are really separate types from value-balancing fields, but this is tricky to represent in the spec when they have identical ranges (and in the C++ codebase everything is just typedef int64_t CAmount
).
For Orchard, we make this type separation explicit by defining Orchard note values as having range u64
, while valueBalanceOrchard
has range -MAX_MONEY..MAX_MONEY
. This is useful for several reasons:
- Separation of concerns: value-balancing fields are directly checked by consensus rules. By contrast, a
NoteValue
is never directly checked by consensus rules:- Inside bundles, note values are handled as
ValueCommitment
s. - For shielded coinbase rules, the only consensus requirement is that the notes can be correctly decrypted, and note plaintexts have always defined the values they contain as
u64
.
- Inside bundles, note values are handled as
- ZSAs: If we ever want to have alternative asset types inside the Orchard pool, we cannot enforce the Zcash- and Bitcoin-specific
MAX_MONEY
on their values (which may be nonsensical for e.g. an ERC20 token). Having note values beu64
provides a neutral common value type, and then any asset-specific value-balancing fields can have different value ranges applied to them thanvalueBalanceOrchard
does.
While this is not a consensus-relevant type distinction, it would be helpful to point out this reasoning somewhere (either in "S3.2 Notes" where "Orchard note value" is defined, or somewhere else more appropriate for design notes, like the Orchard book).