Skip to content
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

Document the consensus rules for Section 3.6 #3338

Merged
merged 9 commits into from
Jan 24, 2022
14 changes: 14 additions & 0 deletions zebra-chain/src/sapling/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ impl ZcashSerialize for Spend<PerSpendAnchor> {
}

impl ZcashDeserialize for Spend<PerSpendAnchor> {
/// # 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.
///
/// <https://zips.z.cash/protocol/protocol.pdf#spendsandoutputs>
///
/// 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<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
Ok(Spend {
cv: commitment::NotSmallOrderValueCommitment::zcash_deserialize(&mut reader)?,
Expand Down
15 changes: 15 additions & 0 deletions zebra-chain/src/transaction/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ impl ZcashDeserialize for Option<sapling::ShieldedData<SharedAnchor>> {
.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.
//
// <https://zips.z.cash/protocol/protocol.pdf#spendsandoutputs>
//
// 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,
Expand Down
7 changes: 7 additions & 0 deletions zebra-consensus/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
// <https://zips.z.cash/protocol/protocol.pdf#spendsandoutputs>
async_checks.push(
primitives::redpallas::VERIFIER
.clone()
Expand Down