-
Notifications
You must be signed in to change notification settings - Fork 106
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
Sapling keys and addresses #327
Conversation
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.
ACK
43bd8ed
to
786a226
Compare
zebra-chain/src/addresses/sapling.rs
Outdated
} | ||
|
||
impl SaplingShieldedAddress { | ||
fn to_human_readable_address(&self, network: Network) -> Result<String, bech32::Error> { |
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.
Should this be used internally to a Display
impl? Is there a reason that it shouldn't be just a Display
impl? (e.g., is it called elsewhere in some context where Display
can't be used?)
The function takes a network
parameter. Should this be stored as part of the address structure itself, so that the address contains all the information required to render itself?
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.
Unfortunately the actual structure of Sapling addresses is technically independent of the network (unlike Sprout), so when they are serialized/deserialized on the wire the network is not involved at all. So when we deserialize a Sapling z-addr, we know nothing about its network. It's only when they are pretty-printed for human consumption that the network is thrown in basically to help the consuming software look at the right data elsewhere, I think @str4d told me once that the params for prod/test networks in Sapling are the same so this is why???
https://zips.z.cash/protocol/protocol.pdf#saplingpaymentaddrencoding
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.
And this holds for all the Sapling keys etc that define an encoding.
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.
😢
Maybe it's possible to figure out some kind of workaround.... 🤔
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.
Unfortunately the actual structure of Sapling addresses is technically independent of the network (unlike Sprout)
It's true for Sprout as well. It only happens to be the case that Sprout addresses are serialized with a "prefix" such that when Base58Check-encoding them, you get the nice human-readable prefix chars. Those prefix chars are an implementation detail, and the Sprout address itself is network-independent.
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.
Actually, this only helps us when the address is bech32 encoded, but when it's not, it still doesn't include the network data.
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.
In practice, we do associate the use of an address with a particular network, so even though the "raw encoding" doesn't include that data, it's reasonable for the struct to do so. The raw encoding for Sapling is only used publicly as the input to / output of Bech32 encoding (we also use it in zcashd
to move PaymentAddress
structs across the FFI, but that's an internal implementation detail).
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 so. We only encoded network for bech32. The actual raw encoding doesn't include it, for any Sapling types. For addresses, where we really only care about the bech32 encoding, we can just forego our normal Zcash(De)Serialize
impls and just to 'to human readable'.
What about the other key types? The IncomingViewingKey
s, FullViewingKey
s, and SpendingKey
s also have this issue.
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 may want the 'human readable' equivalent of Zcash(De)Serialize instead for these.
None of those key types are inputs to transactions or messages.
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! We're basically going to copy what we've done in Sprout types by including the network field and implementing Display
for all of them as the human-readable component.
Didn't check against the spec yet, but looks good so far! |
4798d7f
to
51e946a
Compare
…t vectors Impl a few From<[u8; 32]>'s for a few key types.
} | ||
} | ||
|
||
impl From<(AuthorizingKey, NullifierDerivingKey)> for IncomingViewingKey { |
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.
@hdevalence Is this considered good style/practice? Seems ok to me but just wondering if there's a better way I'm not aware of.
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.
Hmm, I'm not sure. From
is sort of magical, which is nice when magic is desired. Do we want magic here?
Also, another thing about From
is that it works on owned values. So unless AuthorizingKey, NullifierDerivingKey are Copy, using this conversion might require cloning the keys unnecessarily, unless the From impl was impl<'a, 'b> From<(&'a AuthorizingKey, &'b NullifierDerivingKey)> ...
which is a bit un-fun.
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.
That said, I like From impls, in general..... I think this is sort of an aesthetic choice
This is the _DefaultDiversifier_ method.
And fix SpendingKey Display impl bug.
…jub PublicKey From impl
Add some impl From<T> for [u8; 32] 's
I need test vectors! But otherwise ready for review.Test vectors acquired and passing!