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 consensus rules for version group IDs #2719

Merged
merged 3 commits into from
Sep 1, 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
24 changes: 23 additions & 1 deletion zebra-chain/src/transaction/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,12 @@ impl ZcashDeserialize for Transaction {
(header & LOW_31_BITS, header >> 31 != 0)
};

// The overwintered flag MUST NOT be set for version 1 and 2 transactions.
// Consensus rules:
// > The transaction version number MUST be greater than or equal to 1.
// >
// > The overwintered flag MUST NOT be set for version 1 and 2 transactions.
//
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
match (version, overwintered) {
(1, false) => Ok(Transaction::V1 {
inputs: Vec::zcash_deserialize(&mut reader)?,
Expand All @@ -548,6 +553,10 @@ impl ZcashDeserialize for Transaction {
}
(3, true) => {
let id = reader.read_u32::<LittleEndian>()?;
// Consensus rule:
// > [Overwinter only, pre-Sapling] The transaction version number MUST be 3, and the version group ID MUST be 0x03C48270.
//
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
if id != OVERWINTER_VERSION_GROUP_ID {
return Err(SerializationError::Parse(
"expected OVERWINTER_VERSION_GROUP_ID",
Expand All @@ -565,6 +574,13 @@ impl ZcashDeserialize for Transaction {
}
(4, true) => {
let id = reader.read_u32::<LittleEndian>()?;
// Consensus rules:
// > [Sapling to Canopy inclusive, pre-NU5] The transaction version number MUST be 4, and the version group ID MUST be 0x892F2085.
// >
// > [NU5 onward] The transaction version number MUST be 4 or 5.
// > If the transaction version number is 4 then the version group ID MUST be 0x892F2085.
//
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
if id != SAPLING_VERSION_GROUP_ID {
return Err(SerializationError::Parse(
"expected SAPLING_VERSION_GROUP_ID",
Expand Down Expand Up @@ -636,6 +652,12 @@ impl ZcashDeserialize for Transaction {
}
(5, true) => {
// header
//
// Consensus rule:
// > [NU5 onward] The transaction version number MUST be 4 or 5. ...
// > If the transaction version number is 5 then the version group ID MUST be 0x26A7270A.
//
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
let id = reader.read_u32::<LittleEndian>()?;
if id != TX_V5_VERSION_GROUP_ID {
return Err(SerializationError::Parse("expected TX_V5_VERSION_GROUP_ID"));
Expand Down