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: Prohibit Negative Shielded Value Pool #210

Merged
merged 8 commits into from
Mar 26, 2019

Conversation

ebfull
Copy link
Contributor

@ebfull ebfull commented Feb 25, 2019

@mms710 mms710 requested a review from str4d March 4, 2019 21:53
str4d
str4d previously requested changes Mar 6, 2019
zip-???.rst Outdated Show resolved Hide resolved
zip-???.rst Outdated Show resolved Hide resolved
zip-???.rst Outdated Show resolved Hide resolved
zip-???.rst Outdated Show resolved Hide resolved
@daira daira changed the title [ZIP???] Prohibit Negative Shielded Value Pool ZIP 209: Prohibit Negative Shielded Value Pool Mar 14, 2019
Copy link
Collaborator

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes suggested.

zip-0209.rst Outdated Show resolved Hide resolved
zip-0209.rst Outdated Show resolved Hide resolved
zkbot added a commit to zcash/zcash that referenced this pull request Mar 19, 2019
Reject blocks that violate turnstile

This is an implementation of a consensus rule which marks blocks as invalid if they would lead to a turnstile violation in the Sprout or Shielded value pools. The motivations and deployment details can be found in the [accompanying ZIP draft](zcash/zips#210).

**This PR only introduces the rule for testnet at the moment.**

We achieve the institution of this rule in three ways:

1. Nodes prior to #2795 did not record the "delta" in the Sprout value pool balance as part of the on-disk block index. This was a long time ago, though, and all nodes that are consensus-compatible with the network today have been recording this value for newer blocks. However, the value is absent from older block indexes unless the node has reindexed or synchronized from scratch in the time since. We shouldn't need to require nodes to reindex in order to enforce this consensus rule. We avoid this problem by falling back on a hardcoded Sprout shielded value pool balance in a very recent block.
2. If during `ConnectBlock` we observe that the resulting shielded value pool balance of Sprout or Sapling is negative, we reject the block.
3. During the miner's block assembly process the miner will skip over transactions if adding them to the assembled block might violate the turnstile, since the resulting block would be invalid. This means that theoretical transactions violating the turnstile would still be relayed in the network (and made available in users' memory pools) and so a turnstile violation would have some visibility outside of block relay.

## Smoke Testing

It's really tricky to test the behavior that automatically falls back to hardcoded shielded value pool balances in our architecture because it's very testnet-specific and node-version-specific. However, we can do some smoke tests to see that everything is working.

I modified the serialization of `CDiskBlockIndex` to serialize `boost::none` for `nSproutValue`

```
if ((s.GetType() & SER_DISK) && (nVersion >= SPROUT_VALUE_VERSION)) {
    boost::optional<CAmount> nSproutValueFake = boost::none;
    READWRITE(nSproutValueFake);
}
```

and then began a reindex of my node which I interruped around height 130k on testnet. I then restored the original serialization and resumed the reindex; I have thus _roughly_ simulated a older node "upgrading" to a newer node that records the deltas when processing new blocks. My node showed pool monitoring was disabled, as expected, for Sprout. I confirmed that some blocks following the reindex had nonzero Sprout `valueDelta` from `getblock`, as expected. I finished the reindex, restarted the node, and confirmed that the serialization worked for newer blocks but not older blocks by querying `getblock`, simply as a reassurance.

Finally, I introduced the code in this PR and reloaded the node. The desired behavior (that the chain began to be "monitored" again) worked, and the values were consistent with the hardcoded constant. I then made a payment to a Sprout z-addr from the transparent pool and the pool value increased as expected, as reported by `getblockchaininfo`. I reindexed the node again to exercise the remaining logic and check for turnstile violations throughout the history of testnet; there were none.
zip-0209.rst Outdated Show resolved Hide resolved
zip-0209.rst Outdated Show resolved Hide resolved

It is possible for nodes to monitor the total amount of coins that are shielded or unshielded in each of the Sprout or Sapling shielded transaction protocols. If the amount of coins that are unshielded exceed the amount that are shielded, a balance violation has occurred in the corresponding shielded transaction protocol.

It would be preferable for the network to reject blocks that result in the aforementioned balance violation. However, nodes do not currently react to such an event. Remediation may therefore require chain rollbacks and other disruption.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit clunky, here is a suggested rewording:

Rather than allow blocks which result in such a balance violation, it would be preferable for the network to reject them. As nodes do not currently react to this, remediation to such an event may require chain rollbacks and other disruptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️ I am okay with the current wording. This rewording uses "them" and "this" when there are many objects (blocks, balance violations, the network, etc.)

daira and others added 2 commits March 26, 2019 15:55
Co-Authored-By: ebfull <ewillbefull@gmail.com>
Co-Authored-By: ebfull <ewillbefull@gmail.com>
Copy link
Contributor

@defuse defuse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, the comment I left is not a blocker.

zip-0209.rst Outdated Show resolved Hide resolved
Copy link
Collaborator

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK modulo comments.

zip-0209.rst Outdated Show resolved Hide resolved
zip-0209.rst Outdated Show resolved Hide resolved
zip-0209.rst Outdated Show resolved Hide resolved
@daira daira dismissed str4d’s stale review March 26, 2019 23:43

@str4d's comments were addressed.

daira and others added 2 commits March 26, 2019 17:47
Co-Authored-By: ebfull <ewillbefull@gmail.com>
Co-Authored-By: ebfull <ewillbefull@gmail.com>
Copy link
Collaborator

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants