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

Parse received addrv2 messages #3022

Merged
merged 20 commits into from
Nov 12, 2021
Merged

Parse received addrv2 messages #3022

merged 20 commits into from
Nov 12, 2021

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Nov 5, 2021

Motivation

ZIP-155 activates at the same time as NU5 on mainnet.

To implement this ZIP, Zebra needs to parse received addrv2 messages.
Sending addrv2 messages is out of scope.

Specifications

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

Solution

  • add an AddrV2 type for parsing addrv2 messages
  • update the message decoder to use AddrV2 for parsing addrv2 messages
  • limit addr and addrv2 messages to MAX_ADDRS_IN_MESSAGE
    • this is a bug fix for received addr messages
  • add tests for AddrV2

Closes #2681.

Review

I'd like both @jvff and @oxarbitrage to review this change, because it's the riskiest part of the ticket.

This is the last in the series of addrv2 PRs. This PR is based on PR #3032.

Reviewer Checklist

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

Follow Up Work

We should try to get some test vectors from the zcashd team.

@teor2345 teor2345 added A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks P-Medium A-network Area: Network protocol updates or fixes labels Nov 5, 2021
@teor2345 teor2345 requested review from jvff and oxarbitrage November 5, 2021 04:50
@teor2345 teor2345 self-assigned this Nov 5, 2021
@teor2345 teor2345 added the C-bug Category: This is a bug label Nov 5, 2021
@teor2345 teor2345 linked an issue Nov 5, 2021 that may be closed by this pull request
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Looks great! I added two suggestions, but they're optional.

@teor2345 teor2345 force-pushed the addr-v1-serialization branch from 141ac63 to 0f14a64 Compare November 7, 2021 23:01
@teor2345 teor2345 force-pushed the addr-v2-deserialization branch from c5f94de to 96e2078 Compare November 7, 2021 23:02
@teor2345 teor2345 changed the base branch from addr-v1-serialization to preallocate-test-refactor November 8, 2021 00:24
@teor2345 teor2345 marked this pull request as ready for review November 8, 2021 00:25
@teor2345 teor2345 force-pushed the addr-v2-deserialization branch from 6200581 to 626e7e4 Compare November 8, 2021 02:33
@zancas
Copy link
Contributor

zancas commented Nov 9, 2021

OK, I've added a few tests to a zcashd feature branch. The test vectors are composed of addresses and serializations that were already in the tests elsewhere, but they are conveniently adjacent here:

https://github.com/zingolabs/zcash/blob/9ee66e423a3fbf4829ffeec354e82f4fbceff864/src/test/netbase_tests.cpp#L481

jvff
jvff previously approved these changes Nov 9, 2021
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Overall looks good. There's one documentation typo, and I also added some optional suggestions.

@teor2345 teor2345 force-pushed the preallocate-test-refactor branch from 2e9c722 to c371aa1 Compare November 9, 2021 20:51
@teor2345 teor2345 force-pushed the addr-v2-deserialization branch from 626e7e4 to b453056 Compare November 9, 2021 20:57
@teor2345 teor2345 marked this pull request as draft November 10, 2021 06:18
@teor2345
Copy link
Contributor Author

I'm going to put this in draft until I add test vectors from zcashd, and test vectors with extreme service values and address lengths.

Base automatically changed from preallocate-test-refactor to main November 10, 2021 21:53
@teor2345 teor2345 force-pushed the addr-v2-deserialization branch 3 times, most recently from 756f64d to dc225fb Compare November 11, 2021 01:52
@teor2345 teor2345 marked this pull request as ready for review November 11, 2021 01:53
@teor2345 teor2345 force-pushed the addr-v2-deserialization branch from dc225fb to f246cbc Compare November 11, 2021 01:54
@teor2345
Copy link
Contributor Author

OK, I've added a few tests to a zcashd feature branch. The test vectors are composed of addresses and serializations that were already in the tests elsewhere, but they are conveniently adjacent here:

https://github.com/zingolabs/zcash/blob/9ee66e423a3fbf4829ffeec354e82f4fbceff864/src/test/netbase_tests.cpp#L481

@zancas thanks, we're now testing these cases in Zebra as well.

I added some extra addrv1 and addrv2 cases to cover various parsing edge-cases.
You can see them at:

// Extra test cases:

// Extra test cases:

Our test implementation is here, but it's probably not that interesting for you:

/// Test that deserializing [`AddrV1`] into [`MetaAddr`] succeeds,

@teor2345 teor2345 requested a review from jvff November 11, 2021 01:58
jvff
jvff previously approved these changes Nov 11, 2021
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Looks good! I added a few suggestions, but they are all optional 👍

@teor2345 teor2345 force-pushed the addr-v2-deserialization branch from f246cbc to a7f11c2 Compare November 11, 2021 23:43
@teor2345 teor2345 enabled auto-merge (squash) November 11, 2021 23:43
@teor2345
Copy link
Contributor Author

I applied the optional suggestions.

@zancas commit a7f11c2 fixes a mistake in the comments about the Tor v3 address test vectors. (I also listed all the field values in those comments.)

@teor2345 teor2345 merged commit d6f3b3d into main Nov 12, 2021
@teor2345 teor2345 deleted the addr-v2-deserialization branch November 12, 2021 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-network Area: Network protocol updates or fixes A-rust Area: Updates to Rust code C-bug Category: This is a bug C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZIP-155: Parse addrv2 in Zebra
3 participants