-
Notifications
You must be signed in to change notification settings - Fork 0
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
ZSA integration (step 4): Refactor Orchard structures to generics and add Orchard ZSA support for Transaction V6 #17
base: zsa-integration-txv6
Are you sure you want to change the base?
Changes from all commits
23e318c
e98bb67
dd741e9
c218fc5
4807dd6
cccadcd
0f9c164
20810ee
986339e
4d8cdef
1adadb1
e9b0d46
e2e160c
5eade11
763cded
083171f
d2917fb
c979861
018203e
d2313fb
6b22fba
ab9a2b5
c7cd215
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ mod action; | |
mod address; | ||
mod commitment; | ||
mod note; | ||
mod orchard_flavor_ext; | ||
mod sinsemilla; | ||
|
||
#[cfg(any(test, feature = "proptest-impl"))] | ||
|
@@ -22,4 +23,13 @@ pub use address::Address; | |
pub use commitment::{CommitmentRandomness, NoteCommitment, ValueCommitment}; | ||
pub use keys::Diversifier; | ||
pub use note::{EncryptedNote, Note, Nullifier, WrappedNoteKey}; | ||
pub use orchard_flavor_ext::{OrchardFlavorExt, OrchardVanilla}; | ||
pub use shielded_data::{AuthorizedAction, Flags, ShieldedData}; | ||
|
||
pub(crate) use shielded_data::ActionCommon; | ||
|
||
#[cfg(feature = "tx-v6")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like |
||
pub use orchard_flavor_ext::OrchardZSA; | ||
|
||
#[cfg(feature = "tx-v6")] | ||
pub(crate) use crate::orchard_zsa::issuance::IssueData; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ use super::{ | |
commitment::{self, ValueCommitment}, | ||
keys, | ||
note::{self, Nullifier}, | ||
OrchardFlavorExt, | ||
}; | ||
|
||
/// An Action description, as described in the [Zcash specification §7.3][actiondesc]. | ||
|
@@ -21,7 +22,7 @@ use super::{ | |
/// | ||
/// [actiondesc]: https://zips.z.cash/protocol/nu5.pdf#actiondesc | ||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct Action { | ||
pub struct Action<V: OrchardFlavorExt> { | ||
/// A value commitment to net value of the input note minus the output note | ||
pub cv: commitment::ValueCommitment, | ||
/// The nullifier of the input note being spent. | ||
|
@@ -35,14 +36,14 @@ pub struct Action { | |
/// encrypted private key in `out_ciphertext`. | ||
pub ephemeral_key: keys::EphemeralPublicKey, | ||
/// A ciphertext component for the encrypted output note. | ||
pub enc_ciphertext: note::EncryptedNote, | ||
pub enc_ciphertext: V::EncryptedNote, | ||
/// A ciphertext component that allows the holder of a full viewing key to | ||
/// recover the recipient diversified transmission key and the ephemeral | ||
/// private key (and therefore the entire note plaintext). | ||
pub out_ciphertext: note::WrappedNoteKey, | ||
} | ||
|
||
impl ZcashSerialize for Action { | ||
impl<V: OrchardFlavorExt> ZcashSerialize for Action<V> { | ||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { | ||
self.cv.zcash_serialize(&mut writer)?; | ||
writer.write_all(&<[u8; 32]>::from(self.nullifier)[..])?; | ||
|
@@ -55,7 +56,7 @@ impl ZcashSerialize for Action { | |
} | ||
} | ||
|
||
impl ZcashDeserialize for Action { | ||
impl<V: OrchardFlavorExt> ZcashDeserialize for Action<V> { | ||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> { | ||
// # Consensus | ||
// | ||
|
@@ -93,7 +94,8 @@ impl ZcashDeserialize for Action { | |
// https://zips.z.cash/protocol/protocol.pdf#concretesym but fixed to | ||
// 580 bytes in https://zips.z.cash/protocol/protocol.pdf#outputencodingandconsensus | ||
// See [`note::EncryptedNote::zcash_deserialize`]. | ||
enc_ciphertext: note::EncryptedNote::zcash_deserialize(&mut reader)?, | ||
// FIXME: don't mention about 580 here as this should work for OrchardZSA too? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, can remove comment. |
||
enc_ciphertext: V::EncryptedNote::zcash_deserialize(&mut reader)?, | ||
// Type is `Sym.C`, i.e. `𝔹^Y^{\[N\]}`, i.e. arbitrary-sized byte arrays | ||
// https://zips.z.cash/protocol/protocol.pdf#concretesym but fixed to | ||
// 80 bytes in https://zips.z.cash/protocol/protocol.pdf#outputencodingandconsensus | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
//! Encrypted parts of Orchard notes. | ||
|
||
// FIXME: make it a generic and add support for OrchardZSA (encrypted tote size ofr it is not 580!) | ||
|
||
use std::{fmt, io}; | ||
|
||
use serde_big_array::BigArray; | ||
|
@@ -12,57 +10,57 @@ use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize} | |
/// | ||
/// Corresponds to the Orchard 'encCiphertext's | ||
#[derive(Deserialize, Serialize)] | ||
pub struct EncryptedNote(#[serde(with = "BigArray")] pub(crate) [u8; 580]); | ||
pub struct EncryptedNote<const N: usize>(#[serde(with = "BigArray")] pub(crate) [u8; N]); | ||
|
||
// These impls all only exist because of array length restrictions. | ||
// TODO: use const generics https://github.com/ZcashFoundation/zebra/issues/2042 | ||
|
||
impl Copy for EncryptedNote {} | ||
impl<const N: usize> Copy for EncryptedNote<N> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: The |
||
|
||
impl Clone for EncryptedNote { | ||
impl<const N: usize> Clone for EncryptedNote<N> { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
impl fmt::Debug for EncryptedNote { | ||
impl<const N: usize> fmt::Debug for EncryptedNote<N> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("EncryptedNote") | ||
.field(&hex::encode(&self.0[..])) | ||
.finish() | ||
} | ||
} | ||
|
||
impl Eq for EncryptedNote {} | ||
impl<const N: usize> Eq for EncryptedNote<N> {} | ||
|
||
impl From<[u8; 580]> for EncryptedNote { | ||
fn from(bytes: [u8; 580]) -> Self { | ||
impl<const N: usize> From<[u8; N]> for EncryptedNote<N> { | ||
fn from(bytes: [u8; N]) -> Self { | ||
EncryptedNote(bytes) | ||
} | ||
} | ||
|
||
impl From<EncryptedNote> for [u8; 580] { | ||
fn from(enc_ciphertext: EncryptedNote) -> Self { | ||
impl<const N: usize> From<EncryptedNote<N>> for [u8; N] { | ||
fn from(enc_ciphertext: EncryptedNote<N>) -> Self { | ||
enc_ciphertext.0 | ||
} | ||
} | ||
|
||
impl PartialEq for EncryptedNote { | ||
impl<const N: usize> PartialEq for EncryptedNote<N> { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.0[..] == other.0[..] | ||
} | ||
} | ||
|
||
impl ZcashSerialize for EncryptedNote { | ||
impl<const N: usize> ZcashSerialize for EncryptedNote<N> { | ||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { | ||
writer.write_all(&self.0[..])?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ZcashDeserialize for EncryptedNote { | ||
impl<const N: usize> ZcashDeserialize for EncryptedNote<N> { | ||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> { | ||
let mut bytes = [0; 580]; | ||
let mut bytes = [0; N]; | ||
reader.read_exact(&mut bytes[..])?; | ||
Ok(Self(bytes)) | ||
} | ||
|
@@ -127,13 +125,16 @@ impl ZcashDeserialize for WrappedNoteKey { | |
} | ||
} | ||
|
||
#[cfg(test)] | ||
use crate::orchard::OrchardFlavorExt; | ||
|
||
#[cfg(test)] | ||
use proptest::prelude::*; | ||
#[cfg(test)] | ||
proptest! { | ||
|
||
#[test] | ||
fn encrypted_ciphertext_roundtrip(ec in any::<EncryptedNote>()) { | ||
fn encrypted_ciphertext_roundtrip(ec in any::<EncryptedNote::<{ crate::orchard::OrchardVanilla::ENCRYPTED_NOTE_SIZE }>>()) { | ||
let _init_guard = zebra_test::init(); | ||
|
||
let mut data = Vec::new(); | ||
|
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.
why comment out?