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

Rename the NU5 block commitment variant based on what it commits to #1988

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub enum Commitment {
/// Subsequent `Commitment` variants also commit to the `FinalSaplingRoot`,
/// via their `EarliestSaplingRoot` and `LatestSaplingRoot` fields.
///
/// TODO: this field is verified during semantic verification
///
/// Since Zebra checkpoints on Canopy, we don't need to validate this
/// field, but since it's included in the ChainHistoryRoot, we are
/// already calculating it, so we might as well validate it.
///
/// TODO: this field is verified during semantic verification
FinalSaplingRoot(sapling::tree::Root),

/// [Heartwood activation block] Reserved field.
Expand Down Expand Up @@ -63,7 +63,7 @@ pub enum Commitment {
/// chain history hash in their activation block, via the previous block
/// hash field.)
///
/// TODO: this field is verified during semantic verification
/// TODO: this field is verified during contextual verification
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
ChainHistoryRoot(ChainHistoryMmrRootHash),

/// [NU5 activation onwards] A commitment to:
Expand All @@ -79,11 +79,8 @@ pub enum Commitment {
///
/// See also the [`ChainHistoryRoot`] variant.
///
/// TODO: this field is verified during semantic verification
//
// TODO: Do block commitments activate at NU5 activation, or (NU5 + 1)?
// https://github.com/zcash/zips/pull/474
BlockCommitments(BlockCommitmentsHash),
/// TODO: this field is verified during contextual verification
ChainHistoryBlockTxAuthCommitment(ChainHistoryBlockTxAuthCommitmentHash),
}

/// The required value of reserved `Commitment`s.
Expand Down Expand Up @@ -116,7 +113,9 @@ impl Commitment {
}
}
Heartwood | Canopy => Ok(ChainHistoryRoot(ChainHistoryMmrRootHash(bytes))),
Nu5 => Ok(BlockCommitments(BlockCommitmentsHash(bytes))),
Nu5 => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
}
}

Expand All @@ -130,7 +129,7 @@ impl Commitment {
FinalSaplingRoot(hash) => hash.0,
ChainHistoryActivationReserved => RESERVED_BYTES,
ChainHistoryRoot(hash) => hash.0,
BlockCommitments(hash) => hash.0,
ChainHistoryBlockTxAuthCommitment(hash) => hash.0,
}
}
}
Expand All @@ -143,17 +142,19 @@ impl Commitment {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ChainHistoryMmrRootHash([u8; 32]);

/// The Block Commitments for a block. As of NU5, these cover:
/// A block commitment to chain history and transaction auth.
/// - the chain history tree for all ancestors in the current network upgrade,
/// and
/// - the transaction authorising data in this block.
///
/// Introduced in NU5.
//
// TODO:
// - add auth data type
// - add a method for hashing chain history and auth data together
// - move to a separate file
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct BlockCommitmentsHash([u8; 32]);
pub struct ChainHistoryBlockTxAuthCommitmentHash([u8; 32]);

/// Errors that can occur when checking RootHash consensus rules.
///
Expand Down Expand Up @@ -186,8 +187,8 @@ pub enum CommitmentError {
actual: [u8; 32],
},

#[error("invalid block commitment: expected {expected:?}, actual: {actual:?}")]
InvalidBlockCommitment {
#[error("invalid chain history + block transaction auth commitment: expected {expected:?}, actual: {actual:?}")]
InvalidChainHistoryBlockTxAuthCommitment {
expected: [u8; 32],
actual: [u8; 32],
},
Expand Down