From aaafe70986ad2814ed67e74abd3a10324b8f466d Mon Sep 17 00:00:00 2001 From: Marek Date: Wed, 12 Jan 2022 22:59:41 +0100 Subject: [PATCH 1/3] Document the consensus rules for Section 3.6 --- zebra-chain/src/sapling/shielded_data.rs | 8 ++++++++ zebra-chain/src/sapling/spend.rs | 14 ++++++++++++++ zebra-chain/src/transaction/serialize.rs | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/zebra-chain/src/sapling/shielded_data.rs b/zebra-chain/src/sapling/shielded_data.rs index b35ad0634a9..5d57a6208b9 100644 --- a/zebra-chain/src/sapling/shielded_data.rs +++ b/zebra-chain/src/sapling/shielded_data.rs @@ -290,6 +290,14 @@ where /// descriptions of the transaction, and the balancing value. /// /// + /// + /// # Consensus + /// + /// > The Spend transfers and Action transfers of a transaction MUST be + /// > consistent with its vbalanceSapling value as specified in § 4.13 + /// > ‘Balance and Binding Signature (Sapling)’ on p. 49. + /// + /// pub fn binding_verification_key(&self) -> redjubjub::VerificationKeyBytes { let cv_old: ValueCommitment = self.spends().map(|spend| spend.cv.into()).sum(); let cv_new: ValueCommitment = self.outputs().map(|output| output.cv.into()).sum(); diff --git a/zebra-chain/src/sapling/spend.rs b/zebra-chain/src/sapling/spend.rs index d0f1e373ea4..578619d23dd 100644 --- a/zebra-chain/src/sapling/spend.rs +++ b/zebra-chain/src/sapling/spend.rs @@ -171,6 +171,20 @@ impl ZcashSerialize for Spend { } impl ZcashDeserialize for Spend { + /// # Consensus + /// + /// > The anchor of each Spend description MUST refer to some earlier + /// > block’s final Sapling treestate. The anchor is encoded separately in + /// > each Spend description for v4 transactions, or encoded once and shared + /// > between all Spend descriptions in a v5 transaction. + /// + /// + /// + /// This rule is also implemented in + /// [`zebra_state::service::check::anchor`] and + /// [`zebra_chain::transaction::serialize`]. + /// + /// The "anchor encoding for v4 transactions" is implemented here. fn zcash_deserialize(mut reader: R) -> Result { Ok(Spend { cv: commitment::NotSmallOrderValueCommitment::zcash_deserialize(&mut reader)?, diff --git a/zebra-chain/src/transaction/serialize.rs b/zebra-chain/src/transaction/serialize.rs index 014cc7fae5e..0aa653a1eb3 100644 --- a/zebra-chain/src/transaction/serialize.rs +++ b/zebra-chain/src/transaction/serialize.rs @@ -224,6 +224,21 @@ impl ZcashDeserialize for Option> { .collect(); // Create transfers + // + // # Consensus + // + // > The anchor of each Spend description MUST refer to some earlier + // > block’s final Sapling treestate. The anchor is encoded separately + // > in each Spend description for v4 transactions, or encoded once and + // > shared between all Spend descriptions in a v5 transaction. + // + // + // + // This rule is also implemented in + // [`zebra_state::service::check::anchor`] and + // [`zebra_chain::sapling::spend`]. + // + // The "anchor encoding for v5 transactions" is implemented here. let transfers = match shared_anchor { Some(shared_anchor) => sapling::TransferData::SpendsAndMaybeOutputs { shared_anchor, From b07b3d0d499fc094d2c39e139e50bc92a475df83 Mon Sep 17 00:00:00 2001 From: Marek Date: Thu, 20 Jan 2022 19:27:09 +0100 Subject: [PATCH 2/3] Refactor the consensus docs for vbalanceSapling --- zebra-chain/src/sapling/shielded_data.rs | 8 -------- zebra-consensus/src/transaction.rs | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/zebra-chain/src/sapling/shielded_data.rs b/zebra-chain/src/sapling/shielded_data.rs index 5d57a6208b9..b35ad0634a9 100644 --- a/zebra-chain/src/sapling/shielded_data.rs +++ b/zebra-chain/src/sapling/shielded_data.rs @@ -290,14 +290,6 @@ where /// descriptions of the transaction, and the balancing value. /// /// - /// - /// # Consensus - /// - /// > The Spend transfers and Action transfers of a transaction MUST be - /// > consistent with its vbalanceSapling value as specified in § 4.13 - /// > ‘Balance and Binding Signature (Sapling)’ on p. 49. - /// - /// pub fn binding_verification_key(&self) -> redjubjub::VerificationKeyBytes { let cv_old: ValueCommitment = self.spends().map(|spend| spend.cv.into()).sum(); let cv_new: ValueCommitment = self.outputs().map(|output| output.cv.into()).sum(); diff --git a/zebra-consensus/src/transaction.rs b/zebra-consensus/src/transaction.rs index 96614bd4325..f8867f252ac 100644 --- a/zebra-consensus/src/transaction.rs +++ b/zebra-consensus/src/transaction.rs @@ -798,6 +798,13 @@ where let bvk = orchard_shielded_data.binding_verification_key(); + /// # Consensus + /// + /// > The Spend transfers and Action transfers of a transaction MUST be + /// > consistent with its vbalanceSapling value as specified in § 4.13 + /// > ‘Balance and Binding Signature (Sapling)’ on p. 49. + /// + /// async_checks.push( primitives::redpallas::VERIFIER .clone() From 3cd6b097b17cc237f68d8287700c5508fa0cc20c Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 24 Jan 2022 19:05:18 +0100 Subject: [PATCH 3/3] Change Doc comments to ordinary comments --- zebra-consensus/src/transaction.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zebra-consensus/src/transaction.rs b/zebra-consensus/src/transaction.rs index f8867f252ac..635b7601ff2 100644 --- a/zebra-consensus/src/transaction.rs +++ b/zebra-consensus/src/transaction.rs @@ -798,13 +798,13 @@ where let bvk = orchard_shielded_data.binding_verification_key(); - /// # Consensus - /// - /// > The Spend transfers and Action transfers of a transaction MUST be - /// > consistent with its vbalanceSapling value as specified in § 4.13 - /// > ‘Balance and Binding Signature (Sapling)’ on p. 49. - /// - /// + // # Consensus + // + // > The Spend transfers and Action transfers of a transaction MUST be + // > consistent with its vbalanceSapling value as specified in § 4.13 + // > ‘Balance and Binding Signature (Sapling)’ on p. 49. + // + // async_checks.push( primitives::redpallas::VERIFIER .clone()