-
Notifications
You must be signed in to change notification settings - Fork 251
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
New component: zcash_address crate #352
Conversation
Codecov Report
@@ Coverage Diff @@
## master #352 +/- ##
==========================================
- Coverage 64.46% 64.17% -0.30%
==========================================
Files 73 72 -1
Lines 7229 7212 -17
==========================================
- Hits 4660 4628 -32
- Misses 2569 2584 +15
Continue to review full report at Codecov.
|
_ => { | ||
// Use some heuristics to try and guess whether this might be a Zcash | ||
// address from the future: | ||
// - Zcash HRPs always start with a 'z'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite possible that we may want to add transparent address formats that use bech32[m] encoding. I would suggest that we allow "t" followed by any single character as an HRP for transparent addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK.
Is it intended that this be able to parse address bundles/unified addresses? I think the API is already compatible with that.
Yes; if/when we decide to use Unified Addresses, the Orchard key type would be replaced by UA parsing and serialization. |
This provides round-trip encoding for Zcash addresses.
This enables easy conversion of an encoded Zcash address to a target type, with automatic handling of Zcash address types that are not supported by the target.
This places parsing documentation front and centre, while also making it clear that `str::parse` is the anticipated main entry point.
Using two separate `impl ZcashAddress` blocks resulted in separate blocks in the documentation, which is unnecessary.
This commit removes the now-undefined Orchard encoding logic, and adds the general Bech32m encoding/decoding logic for Unified Addresses. The internal data format of Unified Addresses is not correct in this commit.
I'm not sure whether this is the ideal API now that it includes UA support; I'm going to do some more thinking about it. But this should be mergeable as-is. |
Co-authored-by: Daira Hopwood <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the point at which f4jumble is being applied in the encoding process is incorrect. Otherwise, this looks good.
fn from_sprout(net: Network, data: sprout::Data) -> Self { | ||
ZcashAddress { | ||
net: if let Network::Regtest = net { | ||
Network::Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does sprout not exist on regtest or something? Why is this different from sapling? As a third-party user, I think the impls that are written like this are rather surprising; if I pass in Network::Regtest and get back Network::Test I'll be rather confused as to what's going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addendum: I later found the comment where Network::Regtest
was defined; I think that the correct thing to do is handle the network values separately at the use site, not to rewrite them in this location.
These need to be applied to the entire UA encoding, not to the encoding of each individual receiver.
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
|
|||
Copyright (c) 2021 Electric Coin Company |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Electric Coin Company, or "Zcash developers"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ECC (matches the license text in zcash_primitives/LICENSE-MIT
which is where the F4Jumble impl was moved from, and also matches ECC having copyright assignment for the rest of the code I've written in this module).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but it'll need to be changed as soon as we get any external contributions, unless we intend to require copyright assignment (which we don't do for any of our other MIT/Apache code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been accepting external contributions for quite some time with the rest of the repo licensed in this way. If there's a change that needs making, it should be made uniformly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been accepting external contributions for quite some time with the rest of the repo licensed in this way.
I think this is violating the external contributors' copyrights, strictly speaking.
If there's a change that needs making, it should be made uniformly.
Agreed. Filed #393.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK ff94f66
use super::{Address, Receiver}; | ||
|
||
prop_compose! { | ||
fn uniform43()(a in uniform11(0u8..), b in uniform32(0u8..)) -> [u8; 43] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is a nice technique for larger byte arrays, I should have thought of this before! I've used vec(any::<u8>(), size)
before but then had to convert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One downside to this is the separate halves shrink separately (though that's less of an issue here given that these addresses are composite types). In theory we can implement our own custom array sizes directly, but I couldn't figure out how to set up the UniformArrayStrategy
type properly.
fn from_sprout(net: Network, data: sprout::Data) -> Self; | ||
|
||
fn from_sapling(net: Network, data: sapling::Data) -> Self; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code is ideally supposed to be constructing only unified, P2SH, and P2PKH addresses, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True; I added these for maximum compatibility (so you could replace your current parsing and serialization stack with zcash_address
), but I guess until the old addresses go away, devs can use their existing serialization code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't object to including them, but let's document that they are not preferred.
unified::MAINNET => Network::Main, | ||
unified::TESTNET => Network::Test, | ||
unified::REGTEST => Network::Regtest, | ||
// We will not define new Bech32m address encodings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible that we will. For instance, we may find a way to reduce the overhead currently imposed by the 16 bytes of redundancy, or some other way to mitigate address replacement attacks that doesn't use F4Jumble. Or there could be some cryptographic flaw in that design that we need to fix later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmk, I'll remove this comment. But since there's no way to predict how we might make that kind of change, I can't do what I was previously doing (returning ParseError::MaybeZcash
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should reserve another Bech32m HRP for such purposes (just one for each network should be sufficient).
.chain(iter::repeat(0).take(PADDING_LEN)) | ||
.collect(); | ||
|
||
f4jumble::f4jumble(&encoded).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this could panic if the length of encoded
were greater than 16448 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there is no way to construct a unified::Address
other than decoding one (which checks the length), so this cannot panic. When we add other constructors, we can similarly enforce correctness there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK modulo previous comments.
Co-authored-by: Daira Hopwood <[email protected]>
Co-authored-by: Daira Hopwood <[email protected]>
The idea is that
zcash_address
encapsulates parsing and serialization logic for Zcash address encodings, in such a way that downstream users:Part of #371.