Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZIP-209 RFC: Chain and Transaction Value Pools Design #2152

Closed
mpguerra opened this issue May 13, 2021 · 0 comments · Fixed by #2430
Closed

ZIP-209 RFC: Chain and Transaction Value Pools Design #2152

mpguerra opened this issue May 13, 2021 · 0 comments · Fixed by #2430
Assignees
Labels
C-enhancement Category: This is an improvement

Comments

@mpguerra
Copy link
Contributor

mpguerra commented May 13, 2021

Motivation

In order to apply ZIP-209 (#1895), Zebra needs to calculate the different chain transparent and shielded value pools and store them in the state.

As part of this change, we should verify the sprout, sapling, and orchard value balances against each transaction's transparent value pool.

Scope

Block subsidy, miner fees, and coinbase transaction transparent value pools are out of scope. (#801)

We can validate chain value pools by assuming that coinbase transaction value balances are valid.

Specification

Shielded Chain Value Pools

If any of the "Sprout chain value pool balance", "Sapling chain value pool balance", or "Orchard chain value pool balance" would become negative in the block chain created as a result of accepting a block, then all nodes MUST reject the block as invalid.

Nodes MAY relay transactions even if one or more of them cannot be mined due to the aforementioned restriction.

https://zips.z.cash/zip-0209#specification

Transparent Transaction Value Pool & Remaining Value

Transparent inputs to a transaction insert value into a transparent transaction value pool associated with the transaction, and transparent outputs remove value from this pool. As in Bitcoin, the remaining value in the pool is available to miners as a fee.

Consensus rule: The remaining value in the transparent transaction value pool MUST be nonnegative.

https://zips.z.cash/protocol/protocol.pdf#transactions

Note: there is no explicit rule that the remaining balance in the transparent chain value pool must be non-negative. But it follows from the transparent transaction value pool consensus rule, and the definition of value addition.

Sprout Chain Value Pool

Each JoinSplit transfer can be seen, from the perspective of the transparent transaction value pool , as an input and an output simultaneously.

vold takes value from the transparent transaction value pool and vnew adds value to the transparent transaction
value pool . As a result, vold is treated like an output value, whereas vnew is treated like an input value.

As defined in [ZIP-209], the Sprout chain value pool balance for a given block chain is the sum of all vold field
values for transactions in the block chain, minus the sum of all vnew fields values for transactions in the block chain.

Consensus rule: If the Sprout chain value pool balance would become negative in the block chain created as a result of accepting a block , then all nodes MUST reject the block as invalid.

https://zips.z.cash/protocol/protocol.pdf#joinsplitbalance

Sapling Chain Value Pool

A positive Sapling balancing value takes value from the Sapling transaction value pool and adds it to the transparent transaction value pool . A negative Sapling balancing value does the reverse. As a result, positive vbalanceSapling is treated like an input to the transparent transaction value pool , whereas negative vbalanceSapling is treated like an output from that pool.

As defined in [ZIP-209], the Sapling chain value pool balance for a given block chain is the negation of the sum of all valueBalanceSapling field values for transactions in the block chain.

Consensus rule: If the Sapling chain value pool balance would become negative in the block chain created as a result of accepting a block , then all nodes MUST reject the block as invalid.

https://zips.z.cash/protocol/protocol.pdf#saplingbalance

Orchard Chain Value Pool

Orchard introduces Action transfers, each of which can optionally perform a spend, and optionally perform an output. Similarly to Sapling, the net value of Orchard spends minus outputs in a transaction is called the Orchard balancing value, measured in zatoshi as a signed integer vbalanceOrchard.

vbalanceOrchard is encoded in a transaction as the field valueBalanceOrchard. If a transaction has no Action descriptions, vbalanceOrchard is implicitly zero. Transaction fields are described in § 7.1 ‘Transaction Encoding and Consensus’ on p. 116.

A positive Orchard balancing value takes value from the Orchard transaction value pool and adds it to the transpar- ent transaction value pool . A negative Orchard balancing value does the reverse. As a result, positive vbalanceOrchard is treated like an input to the transparent transaction value pool , whereas negative vbalanceOrchard is treated like an output from that pool.

Similarly to the Sapling chain value pool balance defined in [ZIP-209], the Orchard chain value pool balance for a given block chain is the negation of the sum of all valueBalanceOrchard field values for transactions in the block chain.

Consensus rule: If the Orchard chain value pool balance would become negative in the block chain created as a result of accepting a block , then all nodes MUST reject the block as invalid.

https://zips.z.cash/protocol/protocol.pdf#orchardbalance

Solution

We need to design the value pool implementation in the form of an RFC.

Previous Work

This has already been started in #1928

@mpguerra mpguerra added C-enhancement Category: This is an improvement S-needs-triage Status: A bug report needs triage labels May 13, 2021
@mpguerra mpguerra added this to the 2021 Sprint 12 milestone May 13, 2021
@mpguerra mpguerra linked a pull request May 13, 2021 that will close this issue
4 tasks
@teor2345 teor2345 mentioned this issue May 14, 2021
4 tasks
@mpguerra mpguerra added P-Medium and removed S-needs-triage Status: A bug report needs triage labels May 19, 2021
@teor2345 teor2345 changed the title ZIP-209 RFC: Value Pools Implementation ZIP-209 RFC: Value Pools Design Jun 15, 2021
@teor2345 teor2345 changed the title ZIP-209 RFC: Value Pools Design ZIP-209 RFC: Chain Value Pools Design Jun 21, 2021
@teor2345 teor2345 changed the title ZIP-209 RFC: Chain Value Pools Design ZIP-209 RFC: Chain and Transaction Value Pools Design Jun 24, 2021
@oxarbitrage oxarbitrage mentioned this issue Jul 1, 2021
3 tasks
@mpguerra mpguerra linked a pull request Jul 5, 2021 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: This is an improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants