document transaction orchard types (#3507)

This commit is contained in:
Alfredo Garcia 2022-02-11 00:16:35 -03:00 committed by GitHub
parent 62750c8192
commit 9ede0fb52a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 21 deletions

View File

@ -26,16 +26,22 @@ use crate::{
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ShieldedData { pub struct ShieldedData {
/// The orchard flags for this transaction. /// The orchard flags for this transaction.
/// Denoted as `flagsOrchard` in the spec.
pub flags: Flags, pub flags: Flags,
/// The net value of Orchard spends minus outputs. /// The net value of Orchard spends minus outputs.
/// Denoted as `valueBalanceOrchard` in the spec.
pub value_balance: Amount, pub value_balance: Amount,
/// The shared anchor for all `Spend`s in this transaction. /// The shared anchor for all `Spend`s in this transaction.
/// Denoted as `anchorOrchard` in the spec.
pub shared_anchor: tree::Root, pub shared_anchor: tree::Root,
/// The aggregated zk-SNARK proof for all the actions in this transaction. /// The aggregated zk-SNARK proof for all the actions in this transaction.
/// Denoted as `proofsOrchard` in the spec.
pub proof: Halo2Proof, pub proof: Halo2Proof,
/// The Orchard Actions, in the order they appear in the transaction. /// The Orchard Actions, in the order they appear in the transaction.
/// Denoted as `vActionsOrchard` and `vSpendAuthSigsOrchard` in the spec.
pub actions: AtLeastOne<AuthorizedAction>, pub actions: AtLeastOne<AuthorizedAction>,
/// A signature on the transaction `sighash`. /// A signature on the transaction `sighash`.
/// Denoted as `bindingSigOrchard` in the spec.
pub binding_sig: Signature<Binding>, pub binding_sig: Signature<Binding>,
} }

View File

@ -305,14 +305,13 @@ impl ZcashSerialize for Option<orchard::ShieldedData> {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> { fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
match self { match self {
None => { None => {
// nActionsOrchard // Denoted as `nActionsOrchard` in the spec.
zcash_serialize_empty_list(writer)?; zcash_serialize_empty_list(writer)?;
// We don't need to write anything else here. // We don't need to write anything else here.
// "The fields flagsOrchard, valueBalanceOrchard, anchorOrchard, sizeProofsOrchard, // "The fields flagsOrchard, valueBalanceOrchard, anchorOrchard, sizeProofsOrchard,
// proofsOrchard , and bindingSigOrchard are present if and only if nActionsOrchard > 0." // proofsOrchard , and bindingSigOrchard are present if and only if nActionsOrchard > 0."
// https://zips.z.cash/protocol/nu5.pdf#txnencodingandconsensus notes of the second // `§` note of the second table of https://zips.z.cash/protocol/protocol.pdf#txnencoding
// table, section sign.
} }
Some(orchard_shielded_data) => { Some(orchard_shielded_data) => {
orchard_shielded_data.zcash_serialize(&mut writer)?; orchard_shielded_data.zcash_serialize(&mut writer)?;
@ -332,25 +331,25 @@ impl ZcashSerialize for orchard::ShieldedData {
.map(orchard::AuthorizedAction::into_parts) .map(orchard::AuthorizedAction::into_parts)
.unzip(); .unzip();
// nActionsOrchard and vActionsOrchard // Denoted as `nActionsOrchard` and `vActionsOrchard` in the spec.
actions.zcash_serialize(&mut writer)?; actions.zcash_serialize(&mut writer)?;
// flagsOrchard // Denoted as `flagsOrchard` in the spec.
self.flags.zcash_serialize(&mut writer)?; self.flags.zcash_serialize(&mut writer)?;
// valueBalanceOrchard // Denoted as `valueBalanceOrchard` in the spec.
self.value_balance.zcash_serialize(&mut writer)?; self.value_balance.zcash_serialize(&mut writer)?;
// anchorOrchard // Denoted as `anchorOrchard` in the spec.
self.shared_anchor.zcash_serialize(&mut writer)?; self.shared_anchor.zcash_serialize(&mut writer)?;
// sizeProofsOrchard and proofsOrchard // Denoted as `sizeProofsOrchard` and `proofsOrchard` in the spec.
self.proof.zcash_serialize(&mut writer)?; self.proof.zcash_serialize(&mut writer)?;
// vSpendAuthSigsOrchard // Denoted as `vSpendAuthSigsOrchard` in the spec.
zcash_serialize_external_count(&sigs, &mut writer)?; zcash_serialize_external_count(&sigs, &mut writer)?;
// bindingSigOrchard // Denoted as `bindingSigOrchard` in the spec.
self.binding_sig.zcash_serialize(&mut writer)?; self.binding_sig.zcash_serialize(&mut writer)?;
Ok(()) Ok(())
@ -361,32 +360,33 @@ impl ZcashSerialize for orchard::ShieldedData {
// because the counts are read along with the arrays. // because the counts are read along with the arrays.
impl ZcashDeserialize for Option<orchard::ShieldedData> { impl ZcashDeserialize for Option<orchard::ShieldedData> {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> { fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
// nActionsOrchard and vActionsOrchard // Denoted as `nActionsOrchard` and `vActionsOrchard` in the spec.
let actions: Vec<orchard::Action> = (&mut reader).zcash_deserialize_into()?; let actions: Vec<orchard::Action> = (&mut reader).zcash_deserialize_into()?;
// "sizeProofsOrchard ... [is] present if and only if nActionsOrchard > 0" // "The fields flagsOrchard, valueBalanceOrchard, anchorOrchard, sizeProofsOrchard,
// https://zips.z.cash/protocol/nu5.pdf#txnencodingandconsensus // proofsOrchard , and bindingSigOrchard are present if and only if nActionsOrchard > 0."
// `§` note of the second table of https://zips.z.cash/protocol/protocol.pdf#txnencoding
if actions.is_empty() { if actions.is_empty() {
return Ok(None); return Ok(None);
} }
// flagsOrchard // Denoted as `flagsOrchard` in the spec.
let flags: orchard::Flags = (&mut reader).zcash_deserialize_into()?; let flags: orchard::Flags = (&mut reader).zcash_deserialize_into()?;
// valueBalanceOrchard // Denoted as `valueBalanceOrchard` in the spec.
let value_balance: amount::Amount = (&mut reader).zcash_deserialize_into()?; let value_balance: amount::Amount = (&mut reader).zcash_deserialize_into()?;
// anchorOrchard // Denoted as `anchorOrchard` in the spec.
let shared_anchor: orchard::tree::Root = (&mut reader).zcash_deserialize_into()?; let shared_anchor: orchard::tree::Root = (&mut reader).zcash_deserialize_into()?;
// sizeProofsOrchard and proofsOrchard // Denoted as `sizeProofsOrchard` and `proofsOrchard` in the spec.
let proof: Halo2Proof = (&mut reader).zcash_deserialize_into()?; let proof: Halo2Proof = (&mut reader).zcash_deserialize_into()?;
// vSpendAuthSigsOrchard // Denoted as `vSpendAuthSigsOrchard` in the spec.
let sigs: Vec<Signature<SpendAuth>> = let sigs: Vec<Signature<SpendAuth>> =
zcash_deserialize_external_count(actions.len(), &mut reader)?; zcash_deserialize_external_count(actions.len(), &mut reader)?;
// bindingSigOrchard // Denoted as `bindingSigOrchard` in the spec.
let binding_sig: Signature<Binding> = (&mut reader).zcash_deserialize_into()?; let binding_sig: Signature<Binding> = (&mut reader).zcash_deserialize_into()?;
// Create the AuthorizedAction from deserialized parts // Create the AuthorizedAction from deserialized parts
@ -615,7 +615,9 @@ impl ZcashSerialize for Transaction {
// `bindingSigSapling`. // `bindingSigSapling`.
sapling_shielded_data.zcash_serialize(&mut writer)?; sapling_shielded_data.zcash_serialize(&mut writer)?;
// orchard // A bundle of fields denoted in the spec as `nActionsOrchard`, `vActionsOrchard`,
// `flagsOrchard`,`valueBalanceOrchard`, `anchorOrchard`, `sizeProofsOrchard`,
// `proofsOrchard`, `vSpendAuthSigsOrchard`, and `bindingSigOrchard`.
orchard_shielded_data.zcash_serialize(&mut writer)?; orchard_shielded_data.zcash_serialize(&mut writer)?;
} }
} }
@ -856,7 +858,9 @@ impl ZcashDeserialize for Transaction {
// `bindingSigSapling`. // `bindingSigSapling`.
let sapling_shielded_data = (&mut limited_reader).zcash_deserialize_into()?; let sapling_shielded_data = (&mut limited_reader).zcash_deserialize_into()?;
// orchard // A bundle of fields denoted in the spec as `nActionsOrchard`, `vActionsOrchard`,
// `flagsOrchard`,`valueBalanceOrchard`, `anchorOrchard`, `sizeProofsOrchard`,
// `proofsOrchard`, `vSpendAuthSigsOrchard`, and `bindingSigOrchard`.
let orchard_shielded_data = (&mut limited_reader).zcash_deserialize_into()?; let orchard_shielded_data = (&mut limited_reader).zcash_deserialize_into()?;
Ok(Transaction::V5 { Ok(Transaction::V5 {