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 221] FlyClient - Consensus-Layer Changes #220

Merged
merged 38 commits into from
Mar 10, 2020

Conversation

therealyingtong
Copy link

A proposed implementation of the probabilistic verification FlyClient protocol on top of the existing ZCash reference light client protocol. This can be implemented with a hard fork to include a Merkle Mountain Range proof in each block header.

@daira daira changed the title [WIP] [ZIP 311] FlyClient SPV for ZCash [WIP] [ZIP 221] FlyClient SPV for Zcash Mar 31, 2019
@daira daira changed the title [WIP] [ZIP 221] FlyClient SPV for Zcash [WIP] [ZIP 221] Adding MMR Proofs to Block Headers, and their use in FlyClient Mar 31, 2019
@daira daira changed the title [WIP] [ZIP 221] Adding MMR Proofs to Block Headers, and their use in FlyClient [WIP] [ZIP 221] Adding MMR Proofs to Block Headers, and their use in the FlyClient Protocol Mar 31, 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.

ACK modulo comments.

zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated
An event occurs with high probability if it occurs with probability 1-O(1/2^λ), where λ is the security parameter.

Negligible probability
An event occurs with negligible probability if it occurs with probability O(1/2^λ), where λ is the security parameter.
Copy link
Collaborator

@daira daira Mar 31, 2019

Choose a reason for hiding this comment

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

It isn't clear what the security parameter actually is in the instantiation. I suggest doing a concrete security analysis in the Rationale section. In any case this is enough for a draft.

zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated

Verifier
`````````
**Verifying a valid chain**: the hash of the block B_n at the head of the chain specifies a random subset of blocks to sample. If the PoW solution or the MMR proofs of any of the sampled blocks is invalid, then the verifier rejects the proof. Otherwise, it accepts B_n as the last block of the honest chain.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would need to specify the sampled subset. Again, it's enough for a draft.

Copy link

Choose a reason for hiding this comment

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

Specifying the consensus rule changes is IMO more important than specifying the concrete light client strategy. You certainly need to convince readers that a good light client strategy that is enabled by the consensus rule changes exists, but it's not as important that an exact specific one is fully nailed down, that's a discussion that can easily be done even after the network upgrade.

Copy link
Contributor

Choose a reason for hiding this comment

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

@daira and I agree with you, but would like to have more of a discussion about the possible strategies prior to the network upgrade. Not all of those details need to be in the ZIP, but they serve as a valuable sanity check.

zip-0311.rst Outdated Show resolved Hide resolved
@autotunafish
Copy link

What are the advantages of this compared to another compression tool such as Coda?

@daira
Copy link
Collaborator

daira commented Apr 29, 2019

Roughly: It's simpler, but it only provides "SPV" security for the light clients. Coda provides full security for light clients (but needs significant adaptation to be applicable to Zcash; Coda itself depends on account states being public).

str4d
str4d previously requested changes May 17, 2019
Copy link
Collaborator

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Please rename the ZIP to zip-0221.rst and move all its files into a zip-0221 subdirectory.

The ZIP should also specify the consensus rules that Zcash nodes must enforce on the new block header field (ensuring that each block contains a valid root).

zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated

Abstract
========
A proposed implementation of the probabilistic verification FlyClient protocol [#FlyClient]_ on top of the existing ZCash reference light client protocol [#ZIPXXX]_. This can be implemented with a hard fork to include a MMR proof in each block header.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
A proposed implementation of the probabilistic verification FlyClient protocol [#FlyClient]_ on top of the existing ZCash reference light client protocol [#ZIPXXX]_. This can be implemented with a hard fork to include a MMR proof in each block header.
This proposal defines modifications to the Zcash block header format and consensus rules
in order to support the probabilistic verification FlyClient protocol [#FlyClient]_ on top
of the existing Zcash reference light client protocol [#zip-0307]_.

zip-0311.rst Outdated Show resolved Hide resolved
zip-0311.rst Outdated

.. [#ZIPXXX] `ZCash reference light client protocol <https://github.com/gtank/zips/blob/light_payment_detection/zip-XXX-light-payment-detection.rst>`

.. [#PeterTodd] _`Merkle Mountain Range <https://github.com/proofchains/python-proofmarshal/blob/master/proofmarshal/mmr.py>`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.. [#PeterTodd] _`Merkle Mountain Range <https://github.com/proofchains/python-proofmarshal/blob/master/proofmarshal/mmr.py>`
.. [#MerkleMR] _`Merkle Mountain Ranges <https://github.com/opentimestamps/opentimestamps-server/blob/master/doc/merkle-mountain-range.md>`_

zip-0311.rst Outdated
An event occurs with negligible probability if it occurs with probability O(1/2^λ), where λ is the security parameter.

Merkle mountain range (MMR)
A Merkle mountain range (MMR) is binary hash tree that allows for efficient appends of new leaves without changing the value of existing nodes [#PeterTodd]_.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
A Merkle mountain range (MMR) is binary hash tree that allows for efficient appends of new leaves without changing the value of existing nodes [#PeterTodd]_.
A Merkle mountain range (MMR) is binary hash tree that allows for efficient appends of new leaves without changing the value of existing nodes [#MerkleMR]_.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having looked at the Merkle mountain range specification, it is very similar to the incremental Merkle tree that we use for Sprout and Sapling. The primary difference appears to be that the root of our incremental Merkle tree is computed by explicitly filling empty nodes with an unusable value (because we can't have the shape of the tree changing inside the circuit), while the MMR root is constructed almost directly from the roots of its subtrees (which is slightly more efficient, but can't be easily represented within a circuit).

We should think about whether we might want to leverage this new tree of block headers in some future circuit. Would there be a benefit in being able to prove in zero knowledge that some past block contained a particular public value, without revealing which block it was? I'm not sure it's useful without having a circuit-friendly block header construction, and we could probably switch from MMR to a circuit-friendly tree in the future if necessary, but if there's a concrete use case that this could service, we might want to consider replacing the MMR with a circuit-friendly tree from the start.

I haven't confirmed yet whether the FlyClient protocol would still work with an incremental Merkle tree instead of MMR, but it looks like the only change would be an efficiency loss due to the number of empty nodes, which are bounded on log (n) (because like MMR, an incremental Merkle tree is filled densely from the left-hand side).

zip-0311.rst Outdated Show resolved Hide resolved
@mms710
Copy link

mms710 commented May 17, 2019

@zmanian Would you be willing to review and provide comments on this ZIP next week?

@mms710
Copy link

mms710 commented May 20, 2019

@vbuterin Would you be willing to review and provide comments on this ZIP sometime this week?

@mms710
Copy link

mms710 commented May 22, 2019

Hi @zmanian and @vbuterin, just checking back in. Would you be willing to review and provide comments on this ZIP by the end of this week?

@gmaxwell

This comment has been minimized.

@daira
Copy link
Collaborator

daira commented May 23, 2019

@gmaxwell wrote:

str4d's suggested changes appear to be systematically removing the correct citation to Peter Todd for the MMR.

The structure now called Merkle Mountain Ranges was not first invented by Peter Todd. It was originally invented in the context of the Certificate Transparency protocol, as Todd's writings correctly acknowledge: https://tools.ietf.org/html/rfc6962 (that RFC in turn references a 2009 paper on "history trees" by Crosby and Wallach describing essentially the same structure, with some minor differences). I agree there should be an acknowledgement to Peter Todd for his subsequent work in implementing and popularising them. The replacement reference that @str4d suggests is still written by Todd; in any case, accurate specification of the precise variant used is what is important here. Note that references in ZIPs are typically named by content and not author(s).

In general, the Zcash project has a strong culture of properly acknowledging sources. Any omission in that regard is an oversight that we will correct.

@str4d

This comment has been minimized.

@gmaxwell

This comment has been minimized.

@str4d

This comment has been minimized.

zip-0311.rst Outdated Show resolved Hide resolved
@mms710
Copy link

mms710 commented May 24, 2019

Hi @vbuterin and @zmanian! Just a reminder we'd love your reviews of this ZIP by end of day today if possible. Thanks!

@zmanian
Copy link

zmanian commented May 26, 2019

I'd advocate against prioritizing FlyClient compatibility in the immediate future.

Here are my reasons:

  1. The story for key management and proving for Sapling transactions on light devices(phones) is very immature.

  2. This work would be rendered more or less irrelevant by any change to adopt a finality gadget.

  3. There is a clear alternative to stateful proof of work based sidechains which is oracle based side chains. Verifying the other chain's proof of work is only potentially relevant as a slashing mechanism to the oracles.

@prestwich
Copy link
Contributor

  1. The story for key management and proving for Sapling transactions on light devices(phones) is very immature.

On the other hand, immaturity means the field is wide open. Zcash has avoided getting locked into Electrum/Stratum like most other chains. FlyClient proofs have the added zcash-specific advantage of giving each validator a sampling of historical headers (and therefore commitment tree anchors) from the chain history.

  1. This work would be rendered more or less irrelevant by any change to adopt a finality gadget.

Has any significant PoW chain adopted a finality gadget? Is there a compelling reason for Zcash to be among the first? Zcash arguably has stronger social finality guarantees than other PoW chains, due to its strong developer influence and the danger of long reorgs to the shielded commitment trees and expiring transactions.

  1. There is a clear alternative to stateful proof of work based sidechains which is oracle based side chains. Verifying the other chain's proof of work is only potentially relevant as a slashing mechanism to the oracles.

Is there a slashable oracle model for chains that don't support fraud proofs?

@zookozcash
Copy link

For the record, I've read this ZIP and all of the comments up to here.

zip-0311.rst Outdated

Schematic of Merkle mountain range (from [#FlyClient]_).

The MMR structure allows for subchain proofs. Consider a client who has already received a verified a proof for a chain of n blocks. When it later receives k new blocks, it need only verify that the new section of length k is honest, as well as that the old chain is a prefix of the new chain.
Copy link

Choose a reason for hiding this comment

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

Maybe this is an aesthetic difference between the zcash and ethereum communities but it would be nice to see a formal description of exactly what this entails. I don't necessarily mean Latex or Coq, just a python function def get_mmr_values(prev_mmr_values: List[Bytes32], block_hash: Bytes32) -> Bytes32 with the code. Maybe this code that I wrote a few months ago does the same thing? https://github.com/ethereum/research/blob/master/beacon_chain_impl/progressive_merkle_tree.py#L12

Copy link
Collaborator

@daira daira Jun 27, 2019

Choose a reason for hiding this comment

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

In general: it's only strictly necessary to specify the rules needed for consensus conformance. (Another example of this is that the protocol spec specifies Equihash validation, but not how to construct Equihash proofs.) There's no objection to discussing anything else that is useful, though. Thanks for the code reference.

@prestwich
Copy link
Contributor

This ZIP has undergone major changes. It now specifies consensus rule changes for the MMR commitment

zip-0211.rst Outdated Show resolved Hide resolved
@daira daira force-pushed the master branch 4 times, most recently from e5c7413 to 5711fc1 Compare August 6, 2019 00:38
str4d and others added 26 commits March 10, 2020 13:14
The pseudocode is Python-esque, so snake_case makes sense for other
variables, but as the pseudocode is intended for specification clarity
it should defer to the specification's naming scheme.
This addresses finding NCC-1908_Zcash-001.
This addresses finding NCC-1908_Zcash-002.
Figures should be stored in a subdirectory, but the source files for the
figures have not been provided, and one of the figures contains an error.
People in the Original-Authors field are not contact points for a ZIP.
"Height" is used elsewhere in the ZIP to refer to block heights.
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
@daira daira dismissed stale reviews from defuse and str4d March 10, 2020 16:15

Resolved

@daira daira merged commit ab4898c into zcash:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.