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

zcash_address: Add support for ZIP 316, Revision 1 #1135

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Jan 25, 2024

Closes #1153.

@nuttycom nuttycom marked this pull request as draft January 25, 2024 23:50
Copy link

codecov bot commented Jan 26, 2024

Codecov Report

Attention: Patch coverage is 63.99217% with 184 lines in your changes missing coverage. Please review.

Project coverage is 63.65%. Comparing base (1ef11c2) to head (2eba3a5).

Files Patch % Lines
components/zcash_address/src/kind/unified.rs 50.84% 58 Missing ⚠️
zcash_keys/src/keys.rs 69.71% 53 Missing ⚠️
zcash_keys/src/address.rs 50.00% 45 Missing ⚠️
...mponents/zcash_address/src/kind/unified/address.rs 84.84% 10 Missing ⚠️
...ent_backend/src/data_api/wallet/input_selection.rs 0.00% 6 Missing ⚠️
components/zcash_address/src/kind/unified/fvk.rs 77.77% 4 Missing ⚠️
components/zcash_address/src/kind/unified/ivk.rs 77.77% 4 Missing ⚠️
..._sqlite/src/wallet/init/migrations/ufvk_support.rs 66.66% 2 Missing ⚠️
zcash_client_sqlite/src/wallet.rs 50.00% 1 Missing ⚠️
...lite/src/wallet/init/migrations/addresses_table.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1135      +/-   ##
==========================================
- Coverage   63.90%   63.65%   -0.25%     
==========================================
  Files         132      132              
  Lines       15494    15706     +212     
==========================================
+ Hits         9901     9998      +97     
- Misses       5593     5708     +115     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nuttycom nuttycom added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2024
@nuttycom nuttycom marked this pull request as ready for review February 16, 2024 00:19
@nuttycom nuttycom marked this pull request as draft February 16, 2024 04:32
@nuttycom
Copy link
Contributor Author

Returning to draft status to update the parsing of the HRP for ZIP 316, Revision 1

@nuttycom nuttycom changed the title zcash_address: Add handling for Unified Metadata Items zcash_address: Add support for ZIP 316, Revision 1 Feb 16, 2024
@nuttycom nuttycom marked this pull request as ready for review February 16, 2024 22:04
zcash_keys/src/address.rs Outdated Show resolved Hide resolved
zcash_keys/src/address.rs Outdated Show resolved Hide resolved
zcash_keys/src/address.rs Outdated Show resolved Hide resolved
zcash_keys/src/keys.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Some changes needed — see the "(blocking)" comments.

Comment on lines 111 to 112
/// Returns `None` if the receivers would produce an invalid Unified Address (namely,
/// if no shielded receiver is provided).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns `None` if the receivers would produce an invalid Unified Address (namely,
/// if no shielded receiver is provided).
/// Returns `None` if the receivers would produce an invalid Unified Address (namely,
/// if no receiver is provided, or if there is only a transparent receiver and no expiry
/// height or time).

unknown_data: vec![],
expiry_height,
expiry_time,
unknown_metadata: vec![],
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to allow creating a UA with only a transparent receiver plus expiration metadata, consistent with the suggested doc change.

Comment on lines +560 to 619
if !(has_orchard || has_sapling || has_p2pkh) {
panic!("At least one receiver must be requested.")
}

Self {
has_orchard,
has_sapling,
has_p2pkh,
expiry_height: None,
expiry_time: None,
}
Copy link
Contributor

@daira daira Mar 7, 2024

Choose a reason for hiding this comment

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

Suggested change
if !(has_orchard || has_sapling || has_p2pkh) {
panic!("At least one receiver must be requested.")
}
Self {
has_orchard,
has_sapling,
has_p2pkh,
expiry_height: None,
expiry_time: None,
}
Self::new(has_orchard, has_sapling, has_p2pkh, None, None)
.expect("At least one shielded receiver must be requested")

This ensures that the validity checking is consistent between new and unsafe_new_without_expiry. It's correct to panic in the case where only has_p2pkh is true here, because we want to require expiry metadata in that case, and here there isn't any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also depends upon the resolution to #1135 (comment)

#[cfg(feature = "orchard")]
orchard,
#[cfg(feature = "sapling")]
sapling,
transparent,
std::cmp::min(self.expiry_height, request.expiry_height),
std::cmp::min(self.expiry_time, request.expiry_time),
)
.ok_or(AddressGenerationError::ShieldedReceiverRequired)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure that an invalid combination isn't representable as a UnifiedAddressRequest, so that this error is impossible (and can be a panic if it does occur due to some inconsistency).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is certainly the wrong error to return at this point, but what the correct error is depends upon #1135 (comment)

let mut unknown_data = vec![];
let mut expiry_height = None;
let mut expiry_time = None;
let mut unknown_metadata = vec![];
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unclear whether unified::Ufvk::decode(encoding) enforces the requirement on the allowed receivers and metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The decoding of Unified containers currently disallows transparent-only UAs; this needs to change but will depend upon the resolution of #1135 (comment).

unknown_data,
expiry_height,
expiry_time,
unknown_metadata,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not check the requirement on the allowed receivers and metadata. It may be that an invalid combination can't occur here because of checks in unified::Ufvk::decode(encoding), but if so it's not obvious.

Copy link
Contributor

@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 requested.

@nuttycom nuttycom requested a review from daira April 1, 2024 22:14
@nuttycom nuttycom force-pushed the zcash_address/expiry branch 4 times, most recently from 5e60c27 to fa225d4 Compare April 23, 2024 22:31
@nuttycom nuttycom added the C-zip-impl Category: An implementation of a ZIP, or a request to do so label Jun 17, 2024
pub enum MetadataTypecode {
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316)
ExpiryHeight,
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316)
/// Expiration time metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-zip-impl Category: An implementation of a ZIP, or a request to do so S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zcash_address: Support Zip 316, Revision 1 (MUST-understand metadata)
3 participants