zips icon indicating copy to clipboard operation
zips copied to clipboard

[protocol spec] [Orchard book] Clarify that Orchard note values are _defined_ as `u64`, not just used as such

Open str4d opened this issue 3 years ago • 0 comments

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, and valueBalanceSapling enable funds to move into and out of the value pools, and are directly constrained to range 0..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 ValueCommitments.
    • 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.
  • 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 be u64 provides a neutral common value type, and then any asset-specific value-balancing fields can have different value ranges applied to them than valueBalanceOrchard 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).

str4d avatar Jul 06 '21 05:07 str4d