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 and ZIP-244 commitment validation in non-finalized state #2609

Merged
merged 4 commits into from
Aug 17, 2021

Conversation

conradoplg
Copy link
Collaborator

@conradoplg conradoplg commented Aug 11, 2021

Motivation

ZIP-221 specifies a history tree to which each block must commit to. ZIP-244 expands this commitment to also include the authentication data commitment.

This adds both checks.

Specifications

https://zips.z.cash/zip-0221#block-header-semantics-and-consensus-rules

image

https://zips.z.cash/zip-0244#block-header-changes

image

Designs

N/A

Solution

Compute the correct commitment and compare with the commitment in the block header.

The ZIP-244 path is not tested because there aren't post-Nu5 blocks yet and I couldn't come up with a way to test it. Suggestions are welcome.

Review

#2547 must be reviewed & merged first.

This (hopefully) finishes what we need for minimal validation post-Nu5, so must be reviewed before that.

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

N/A


This change is Reviewable

@conradoplg conradoplg marked this pull request as draft August 11, 2021 21:03
@conradoplg
Copy link
Collaborator Author

Moved to draft because I forgot about the checkpoint verifier. But otherwise it's OK to review.

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This looks good so far.

I'd like to see a NU5 test, can we open a ticket for that?
(We might need to wait until we have the NU5 testnet activation height.)

We could wait for NU5 testnet activation and see if it works.
But if it doesn't, all our CI would fail, even on unrelated work.

@conradoplg conradoplg force-pushed the zip221-validation branch 2 times, most recently from c8a7858 to 988963d Compare August 12, 2021 18:52
@conradoplg conradoplg marked this pull request as ready for review August 12, 2021 19:35
@teor2345
Copy link
Contributor

Would you mind rebasing this PR on main, so it's easier to see the new changes?

@conradoplg
Copy link
Collaborator Author

Would you mind rebasing this PR on main, so it's easier to see the new changes?

Done!

Base automatically changed from auth-digest to main August 13, 2021 16:58
@teor2345 teor2345 changed the title ZIP-221 and ZIP-244 commitment validation ZIP-221 and ZIP-244 commitment validation in non-finalized state Aug 16, 2021
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This all looks great!

I'd like to get the cached state tests passing before we merge this PR, then I think we're good to go here.

I've also updated the name of the PR so I don't get the finalized and non-finalized state confused.

@conradoplg
Copy link
Collaborator Author

I'd like to get the cached state tests passing before we merge this PR, then I think we're good to go here.

I've started a run here https://github.com/ZcashFoundation/zebra/actions/runs/1137516612

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

I'd like to get the cached state tests passing before we merge this PR, then I think we're good to go here.

I've started a run here https://github.com/ZcashFoundation/zebra/actions/runs/1137516612

It passed!

@conradoplg conradoplg merged commit 5c5abf6 into main Aug 17, 2021
@conradoplg conradoplg deleted the zip221-validation branch August 17, 2021 14:49
Comment on lines +519 to +532
// Test committing the next block with the wrong commitment
let next_block = activation_block.make_fake_child();
let err = state
.commit_block(next_block.clone().prepare(), &finalized_state)
.unwrap_err();
match err {
crate::ValidateContextError::InvalidBlockCommitment(
zebra_chain::block::CommitmentError::InvalidChainHistoryRoot { .. },
) => {}
_ => panic!(
"Error must be InvalidBlockCommitment::InvalidChainHistoryRoot instead of {:?}",
err
),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

💟

Comment on lines +534 to +538
// Test committing the next block with the correct commitment
let next_block = next_block.set_block_commitment(tree.hash().into());
state
.commit_block(next_block.prepare(), &finalized_state)
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@dconnolly dconnolly left a comment

Choose a reason for hiding this comment

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

🎉

@conradoplg
Copy link
Collaborator Author

@dconnolly sorry! I think I've merged it before you finished reading through it 😅

@dconnolly
Copy link
Contributor

@dconnolly sorry! I think I've merged it before you finished reading through it 😅

No worries 😁

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

Successfully merging this pull request may close these issues.

3 participants