Skip to content

Commit

Permalink
zcash_protocol: Add constants for the Nu7 Network Upgrade
Browse files Browse the repository at this point in the history
Access to the newly-added constants is guarded behind the
`zcash_unstable = "nu7"` config flag.
  • Loading branch information
nuttycom committed Feb 27, 2025
1 parent 7f8f32c commit 0f00e24
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ opt-level = 3
debug = true

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("zfuture"))'] }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("zfuture", "nu7"))'] }
32 changes: 31 additions & 1 deletion components/zcash_protocol/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ impl Parameters for MainNetwork {
NetworkUpgrade::Canopy => Some(BlockHeight(1_046_400)),
NetworkUpgrade::Nu5 => Some(BlockHeight(1_687_104)),
NetworkUpgrade::Nu6 => Some(BlockHeight(2_726_400)),
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7 => None,
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => None,
}
Expand Down Expand Up @@ -435,6 +437,8 @@ impl Parameters for TestNetwork {
NetworkUpgrade::Canopy => Some(BlockHeight(1_028_500)),
NetworkUpgrade::Nu5 => Some(BlockHeight(1_842_420)),
NetworkUpgrade::Nu6 => Some(BlockHeight(2_976_000)),
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7 => None,
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => None,
}
Expand Down Expand Up @@ -503,6 +507,11 @@ pub enum NetworkUpgrade {
///
/// [Nu6]: https://z.cash/upgrade/nu6/
Nu6,
/// The [Nu7 (proposed)] network upgrade.
///
/// [Nu7 (proposed)]: https://z.cash/upgrade/nu7/
#[cfg(zcash_unstable = "nu7")]
Nu7,
/// The ZFUTURE network upgrade.
///
/// This upgrade is expected never to activate on mainnet;
Expand All @@ -525,6 +534,8 @@ impl fmt::Display for NetworkUpgrade {
NetworkUpgrade::Canopy => write!(f, "Canopy"),
NetworkUpgrade::Nu5 => write!(f, "Nu5"),
NetworkUpgrade::Nu6 => write!(f, "Nu6"),
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7 => write!(f, "Nu7"),
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => write!(f, "ZFUTURE"),
}
Expand All @@ -541,6 +552,8 @@ impl NetworkUpgrade {
NetworkUpgrade::Canopy => BranchId::Canopy,
NetworkUpgrade::Nu5 => BranchId::Nu5,
NetworkUpgrade::Nu6 => BranchId::Nu6,
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7 => BranchId::Nu7,
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => BranchId::ZFuture,
}
Expand All @@ -559,6 +572,8 @@ const UPGRADES_IN_ORDER: &[NetworkUpgrade] = &[
NetworkUpgrade::Canopy,
NetworkUpgrade::Nu5,
NetworkUpgrade::Nu6,
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7,
];

/// The "grace period" defined in [ZIP 212].
Expand Down Expand Up @@ -597,6 +612,9 @@ pub enum BranchId {
Nu5,
/// The consensus rules deployed by [`NetworkUpgrade::Nu6`].
Nu6,
/// The consensus rules to be deployed by [`NetworkUpgrade::Nu7`].
#[cfg(zcash_unstable = "nu7")]
Nu7,
/// Candidates for future consensus rules; this branch will never
/// activate on mainnet.
#[cfg(zcash_unstable = "zfuture")]
Expand All @@ -619,6 +637,8 @@ impl TryFrom<u32> for BranchId {
0xe9ff_75a6 => Ok(BranchId::Canopy),
0xc2d6_d0b4 => Ok(BranchId::Nu5),
0xc8e7_1055 => Ok(BranchId::Nu6),
#[cfg(zcash_unstable = "nu7")]
0xffff_ffff => Ok(BranchId::Nu7),
#[cfg(zcash_unstable = "zfuture")]
0xffff_ffff => Ok(BranchId::ZFuture),
_ => Err("Unknown consensus branch ID"),
Expand All @@ -637,6 +657,8 @@ impl From<BranchId> for u32 {
BranchId::Canopy => 0xe9ff_75a6,
BranchId::Nu5 => 0xc2d6_d0b4,
BranchId::Nu6 => 0xc8e7_1055,
#[cfg(zcash_unstable = "nu7")]
BranchId::Nu7 => 0xffff_ffff,
#[cfg(zcash_unstable = "zfuture")]
BranchId::ZFuture => 0xffff_ffff,
}
Expand Down Expand Up @@ -706,12 +728,18 @@ impl BranchId {
.activation_height(NetworkUpgrade::Nu5)
.map(|lower| (lower, params.activation_height(NetworkUpgrade::Nu6))),
BranchId::Nu6 => params.activation_height(NetworkUpgrade::Nu6).map(|lower| {
#[cfg(zcash_unstable = "nu7")]
let upper = params.activation_height(NetworkUpgrade::Nu7);

Check warning on line 732 in components/zcash_protocol/src/consensus.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/consensus.rs#L731-L732

Added lines #L731 - L732 were not covered by tests
#[cfg(zcash_unstable = "zfuture")]
let upper = params.activation_height(NetworkUpgrade::ZFuture);
#[cfg(not(zcash_unstable = "zfuture"))]
#[cfg(not(any(zcash_unstable = "nu7", zcash_unstable = "zfuture")))]

Check warning on line 735 in components/zcash_protocol/src/consensus.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/consensus.rs#L735

Added line #L735 was not covered by tests
let upper = None;
(lower, upper)
}),
#[cfg(zcash_unstable = "nu7")]
BranchId::Nu7 => params
.activation_height(NetworkUpgrade::Nu7)
.map(|lower| (lower, None)),

Check warning on line 742 in components/zcash_protocol/src/consensus.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/consensus.rs#L740-L742

Added lines #L740 - L742 were not covered by tests
#[cfg(zcash_unstable = "zfuture")]
BranchId::ZFuture => params
.activation_height(NetworkUpgrade::ZFuture)
Expand Down Expand Up @@ -741,6 +769,8 @@ pub mod testing {
BranchId::Canopy,
BranchId::Nu5,
BranchId::Nu6,
#[cfg(zcash_unstable = "nu7")]
BranchId::Nu7,

Check warning on line 773 in components/zcash_protocol/src/consensus.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/consensus.rs#L772-L773

Added lines #L772 - L773 were not covered by tests
#[cfg(zcash_unstable = "zfuture")]
BranchId::ZFuture,
])
Expand Down
7 changes: 7 additions & 0 deletions components/zcash_protocol/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ pub const V5_TX_VERSION: u32 = 5;
/// The version group id for Zcash Nu5 transactions.
pub const V5_VERSION_GROUP_ID: u32 = 0x26A7270A;

/// The transaction version introduced by ZIP 230.
#[cfg(zcash_unstable = "nu7")]
pub const V6_TX_VERSION: u32 = 6;
/// The version group id for Zcash ZIP 230 transactions.
#[cfg(zcash_unstable = "nu7")]
pub const V6_VERSION_GROUP_ID: u32 = 0xFFFFFFFF;

/// These versions are used exclusively for in-development transaction
/// serialization, and will never be active under the consensus rules.
/// When new consensus transaction versions are added, all call sites
Expand Down
25 changes: 24 additions & 1 deletion components/zcash_protocol/src/local_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct LocalNetwork {
pub canopy: Option<BlockHeight>,
pub nu5: Option<BlockHeight>,
pub nu6: Option<BlockHeight>,
#[cfg(zcash_unstable = "nu7")]
pub nu7: Option<BlockHeight>,
#[cfg(zcash_unstable = "zfuture")]
pub z_future: Option<BlockHeight>,
}
Expand All @@ -59,6 +61,8 @@ impl Parameters for LocalNetwork {
NetworkUpgrade::Canopy => self.canopy,
NetworkUpgrade::Nu5 => self.nu5,
NetworkUpgrade::Nu6 => self.nu6,
#[cfg(zcash_unstable = "nu7")]
NetworkUpgrade::Nu7 => self.nu7,
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => self.z_future,
}
Expand All @@ -82,6 +86,8 @@ mod tests {
let expected_canopy = BlockHeight::from_u32(5);
let expected_nu5 = BlockHeight::from_u32(6);
let expected_nu6 = BlockHeight::from_u32(7);
#[cfg(zcash_unstable = "nu7")]
let expected_nu7 = BlockHeight::from_u32(8);
#[cfg(zcash_unstable = "zfuture")]
let expected_z_future = BlockHeight::from_u32(8);

Expand All @@ -93,6 +99,8 @@ mod tests {
canopy: Some(expected_canopy),
nu5: Some(expected_nu5),
nu6: Some(expected_nu6),
#[cfg(zcash_unstable = "nu7")]
nu7: Some(expected_nu7),
#[cfg(zcash_unstable = "zfuture")]
z_future: Some(expected_z_future),
};
Expand All @@ -104,8 +112,10 @@ mod tests {
assert!(regtest.is_nu_active(NetworkUpgrade::Canopy, expected_canopy));
assert!(regtest.is_nu_active(NetworkUpgrade::Nu5, expected_nu5));
assert!(regtest.is_nu_active(NetworkUpgrade::Nu6, expected_nu6));
#[cfg(zcash_unstable = "nu7")]
assert!(!regtest.is_nu_active(NetworkUpgrade::Nu7, expected_nu6));
#[cfg(zcash_unstable = "zfuture")]
assert!(!regtest.is_nu_active(NetworkUpgrade::ZFuture, expected_nu5));
assert!(!regtest.is_nu_active(NetworkUpgrade::ZFuture, expected_nu6));
}

#[test]
Expand All @@ -117,6 +127,8 @@ mod tests {
let expected_canopy = BlockHeight::from_u32(5);
let expected_nu5 = BlockHeight::from_u32(6);
let expected_nu6 = BlockHeight::from_u32(7);
#[cfg(zcash_unstable = "nu7")]
let expected_nu7 = BlockHeight::from_u32(8);
#[cfg(zcash_unstable = "zfuture")]
let expected_z_future = BlockHeight::from_u32(8);

Expand All @@ -128,6 +140,8 @@ mod tests {
canopy: Some(expected_canopy),
nu5: Some(expected_nu5),
nu6: Some(expected_nu6),
#[cfg(zcash_unstable = "nu7")]
nu7: Some(expected_nu7),
#[cfg(zcash_unstable = "zfuture")]
z_future: Some(expected_z_future),
};
Expand Down Expand Up @@ -156,6 +170,11 @@ mod tests {
regtest.activation_height(NetworkUpgrade::Nu5),
Some(expected_nu5)
);
#[cfg(zcash_unstable = "nu7")]
assert_eq!(
regtest.activation_height(NetworkUpgrade::Nu7),
Some(expected_nu7)
);
#[cfg(zcash_unstable = "zfuture")]
assert_eq!(
regtest.activation_height(NetworkUpgrade::ZFuture),
Expand All @@ -172,6 +191,8 @@ mod tests {
let expected_canopy = BlockHeight::from_u32(5);
let expected_nu5 = BlockHeight::from_u32(6);
let expected_nu6 = BlockHeight::from_u32(7);
#[cfg(zcash_unstable = "nu7")]
let expected_nu7 = BlockHeight::from_u32(8);
#[cfg(zcash_unstable = "zfuture")]
let expected_z_future = BlockHeight::from_u32(8);

Expand All @@ -183,6 +204,8 @@ mod tests {
canopy: Some(expected_canopy),
nu5: Some(expected_nu5),
nu6: Some(expected_nu6),
#[cfg(zcash_unstable = "nu7")]
nu7: Some(expected_nu7),
#[cfg(zcash_unstable = "zfuture")]
z_future: Some(expected_z_future),
};
Expand Down
5 changes: 5 additions & 0 deletions pczt/src/roles/creator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ impl Creator {

use crate::common::FLAG_HAS_SIGHASH_SINGLE;

#[cfg(zcash_unstable = "nu7")]
use zcash_protocol::constants::V6_TX_VERSION;

let tx_version = match parts.version {
zcash_primitives::transaction::TxVersion::Sprout(_)
| zcash_primitives::transaction::TxVersion::Overwinter => None,
zcash_primitives::transaction::TxVersion::Sapling => Some(SAPLING_TX_VERSION),
zcash_primitives::transaction::TxVersion::Zip225 => Some(V5_TX_VERSION),
#[cfg(zcash_unstable = "nu7")]
zcash_primitives::transaction::TxVersion::Zip230 => Some(V6_TX_VERSION),

Check warning on line 122 in pczt/src/roles/creator/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/creator/mod.rs#L122

Added line #L122 was not covered by tests
#[cfg(zcash_unstable = "zfuture")]
zcash_primitives::transaction::TxVersion::ZFuture => None,
}?;
Expand Down
2 changes: 2 additions & 0 deletions zcash_client_backend/src/data_api/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@ impl TestBuilder<(), ()> {
canopy: Some(BlockHeight::from_u32(100_000)),
nu5: Some(BlockHeight::from_u32(100_000)),
nu6: None,
#[cfg(zcash_unstable = "nu7")]
nu7: None,
#[cfg(zcash_unstable = "zfuture")]
z_future: None,
};
Expand Down
29 changes: 28 additions & 1 deletion zcash_primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ use zcash_protocol::constants::{
SAPLING_VERSION_GROUP_ID, V5_TX_VERSION, V5_VERSION_GROUP_ID,
};

#[cfg(zcash_unstable = "nu7")]
use zcash_protocol::constants::{V6_TX_VERSION, V6_VERSION_GROUP_ID};

#[cfg(zcash_unstable = "zfuture")]
use zcash_protocol::constants::{ZFUTURE_TX_VERSION, ZFUTURE_VERSION_GROUP_ID};

Expand All @@ -63,6 +66,8 @@ pub enum TxVersion {
Overwinter,
Sapling,
Zip225,
#[cfg(zcash_unstable = "nu7")]
Zip230,
#[cfg(zcash_unstable = "zfuture")]
ZFuture,
}
Expand All @@ -78,6 +83,8 @@ impl TxVersion {
(OVERWINTER_TX_VERSION, OVERWINTER_VERSION_GROUP_ID) => Ok(TxVersion::Overwinter),
(SAPLING_TX_VERSION, SAPLING_VERSION_GROUP_ID) => Ok(TxVersion::Sapling),
(V5_TX_VERSION, V5_VERSION_GROUP_ID) => Ok(TxVersion::Zip225),
#[cfg(zcash_unstable = "nu7")]
(V6_TX_VERSION, V6_VERSION_GROUP_ID) => Ok(TxVersion::Zip230),

Check warning on line 87 in zcash_primitives/src/transaction/mod.rs

View check run for this annotation

Codecov / codecov/patch

zcash_primitives/src/transaction/mod.rs#L87

Added line #L87 was not covered by tests
#[cfg(zcash_unstable = "zfuture")]
(ZFUTURE_TX_VERSION, ZFUTURE_VERSION_GROUP_ID) => Ok(TxVersion::ZFuture),
_ => Err(io::Error::new(
Expand Down Expand Up @@ -108,6 +115,8 @@ impl TxVersion {
TxVersion::Overwinter => OVERWINTER_TX_VERSION,
TxVersion::Sapling => SAPLING_TX_VERSION,
TxVersion::Zip225 => V5_TX_VERSION,
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => V6_TX_VERSION,
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => ZFUTURE_TX_VERSION,
}
Expand All @@ -119,6 +128,8 @@ impl TxVersion {
TxVersion::Overwinter => OVERWINTER_VERSION_GROUP_ID,
TxVersion::Sapling => SAPLING_VERSION_GROUP_ID,
TxVersion::Zip225 => V5_VERSION_GROUP_ID,
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => V6_VERSION_GROUP_ID,
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => ZFUTURE_VERSION_GROUP_ID,
}
Expand All @@ -138,8 +149,10 @@ impl TxVersion {
TxVersion::Sprout(v) => *v >= 2u32,
TxVersion::Overwinter | TxVersion::Sapling => true,
TxVersion::Zip225 => false,
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => false,
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => true,
TxVersion::ZFuture => false,
}
}

Expand All @@ -153,6 +166,8 @@ impl TxVersion {
TxVersion::Sprout(_) | TxVersion::Overwinter => false,
TxVersion::Sapling => true,
TxVersion::Zip225 => true,
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => true,
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => true,
}
Expand All @@ -163,6 +178,8 @@ impl TxVersion {
match self {
TxVersion::Sprout(_) | TxVersion::Overwinter | TxVersion::Sapling => false,
TxVersion::Zip225 => true,
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => true,
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => true,
}
Expand All @@ -183,6 +200,8 @@ impl TxVersion {
}
BranchId::Nu5 => TxVersion::Zip225,
BranchId::Nu6 => TxVersion::Zip225,
#[cfg(zcash_unstable = "nu7")]
BranchId::Nu7 => TxVersion::Zip230,
#[cfg(zcash_unstable = "zfuture")]
BranchId::ZFuture => TxVersion::ZFuture,
}
Expand Down Expand Up @@ -538,6 +557,8 @@ impl Transaction {
Self::from_data_v4(data)
}
TxVersion::Zip225 => Ok(Self::from_data_v5(data)),
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => todo!(),
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => Ok(Self::from_data_v5(data)),
}
Expand Down Expand Up @@ -581,6 +602,8 @@ impl Transaction {
Self::read_v4(reader, version, consensus_branch_id)
}
TxVersion::Zip225 => Self::read_v5(reader.into_base_reader(), version),
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => todo!(),
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => Self::read_v5(reader.into_base_reader(), version),
}
Expand Down Expand Up @@ -764,6 +787,8 @@ impl Transaction {
self.write_v4(writer)
}
TxVersion::Zip225 => self.write_v5(writer),
#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => todo!(),
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => self.write_v5(writer),
}
Expand Down Expand Up @@ -983,6 +1008,8 @@ pub mod testing {
}
BranchId::Nu5 => Just(TxVersion::Zip225).boxed(),
BranchId::Nu6 => Just(TxVersion::Zip225).boxed(),
#[cfg(zcash_unstable = "nu7")]
BranchId::Nu7 => Just(TxVersion::Zip230).boxed(),
#[cfg(zcash_unstable = "zfuture")]
BranchId::ZFuture => Just(TxVersion::ZFuture).boxed(),
}
Expand Down
2 changes: 2 additions & 0 deletions zcash_primitives/src/transaction/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub fn signature_hash<

TxVersion::Zip225 => v5_signature_hash(tx, signable_input, txid_parts),

#[cfg(zcash_unstable = "nu7")]
TxVersion::Zip230 => todo!(),

Check warning on line 77 in zcash_primitives/src/transaction/sighash.rs

View check run for this annotation

Codecov / codecov/patch

zcash_primitives/src/transaction/sighash.rs#L76-L77

Added lines #L76 - L77 were not covered by tests
#[cfg(zcash_unstable = "zfuture")]
TxVersion::ZFuture => v5_signature_hash(tx, signable_input, txid_parts),
})
Expand Down

0 comments on commit 0f00e24

Please sign in to comment.