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

Network Sustainability Mechanism - ZIP 233 implementation #8930

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
55 changes: 30 additions & 25 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,15 @@ dependencies = [
"byteorder",
]

[[package]]
name = "equihash"
version = "0.2.0"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"blake2b_simd",
"byteorder",
]

[[package]]
name = "equivalent"
version = "1.0.1"
Expand Down Expand Up @@ -1372,8 +1381,7 @@ dependencies = [
[[package]]
name = "f4jumble"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a83e8d7fd0c526af4aad893b7c9fe41e2699ed8a776a6c74aecdeafe05afc75"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"blake2b_simd",
]
Expand Down Expand Up @@ -5549,14 +5557,14 @@ dependencies = [

[[package]]
name = "which"
version = "4.4.2"
version = "6.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f"
dependencies = [
"either",
"home",
"once_cell",
"rustix",
"winsafe",
]

[[package]]
Expand Down Expand Up @@ -5806,6 +5814,12 @@ dependencies = [
"windows-sys 0.48.0",
]

[[package]]
name = "winsafe"
version = "0.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"

[[package]]
name = "wyz"
version = "0.5.1"
Expand Down Expand Up @@ -5836,8 +5850,7 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]]
name = "zcash_address"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ff95eac82f71286a79c750e674550d64fb2b7aadaef7b89286b2917f645457d"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"bech32",
"bs58",
Expand All @@ -5849,8 +5862,7 @@ dependencies = [
[[package]]
name = "zcash_client_backend"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbeeede366fdb642710d3c59fc2090489affd075f66db53ed11bb7138d2d0258"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"base64 0.22.1",
"bech32",
Expand Down Expand Up @@ -5889,8 +5901,7 @@ dependencies = [
[[package]]
name = "zcash_encoding"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "052d8230202f0a018cd9b5d1b56b94cd25e18eccc2d8665073bcea8261ab87fc"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"byteorder",
"nonempty",
Expand All @@ -5899,8 +5910,7 @@ dependencies = [
[[package]]
name = "zcash_history"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fde17bf53792f9c756b313730da14880257d7661b5bfc69d0571c3a7c11a76d"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"blake2b_simd",
"byteorder",
Expand All @@ -5910,8 +5920,7 @@ dependencies = [
[[package]]
name = "zcash_keys"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8162c94957f1e379b8e2fb30f97b95cfa93ac9c6bc02895946ca6392d1abb81"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"bech32",
"blake2b_simd",
Expand Down Expand Up @@ -5949,16 +5958,15 @@ dependencies = [
[[package]]
name = "zcash_primitives"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ab47d526d7fd6f88b3a2854ad81b54757a80c2aeadd1d8b06f690556af9743c"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"aes",
"bip32",
"blake2b_simd",
"bs58",
"byteorder",
"document-features",
"equihash",
"equihash 0.2.0 (git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra)",
"ff",
"fpe",
"group",
Expand Down Expand Up @@ -5988,8 +5996,7 @@ dependencies = [
[[package]]
name = "zcash_proofs"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daba607872e60d91a09248d8e1ea3d6801c819fb80d67016d9de02d81323c10d"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"bellman",
"blake2b_simd",
Expand All @@ -6011,8 +6018,7 @@ dependencies = [
[[package]]
name = "zcash_protocol"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bc22b9155b2c7eb20105cd06de170d188c1bc86489b92aa3fda7b8da8d96acf"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"document-features",
"memuse",
Expand Down Expand Up @@ -6054,7 +6060,7 @@ dependencies = [
"criterion",
"dirs",
"ed25519-zebra",
"equihash",
"equihash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures",
"group",
"halo2_proofs",
Expand Down Expand Up @@ -6553,8 +6559,7 @@ dependencies = [
[[package]]
name = "zip321"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3e613defb0940acef1f54774b51c7f48f2fa705613dd800870dc69f35cd2ea"
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
dependencies = [
"base64 0.22.1",
"nom",
Expand Down
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ resolver = "2"
incrementalmerkletree = { version = "0.7.0", features = ["legacy-api"] }
orchard = "0.10.0"
sapling-crypto = "0.3.0"
zcash_address = "0.6.0"
zcash_client_backend = "0.14.0"
zcash_encoding = "0.2.1"
zcash_history = "0.4.0"
zcash_keys = "0.4.0"
zcash_primitives = "0.19.0"
zcash_proofs = "0.19.0"
zcash_protocol = "0.4.0"
# TODO: Revert to a release once librustzcash is released (#8749).
zcash_address = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_client_backend = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_encoding = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_history = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_keys = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_primitives = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_proofs = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_protocol = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }

[workspace.metadata.release]

Expand Down
5 changes: 5 additions & 0 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ categories = ["asynchronous", "cryptography::cryptocurrencies", "encoding"]
[features]
default = []

nsm = []

# Production features that activate extra functionality

# Consensus-critical conversion from JSON to Zcash types
Expand Down Expand Up @@ -178,3 +180,6 @@ required-features = ["bench"]
[[bench]]
name = "redpallas"
harness = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("nsm"))'] }
2 changes: 1 addition & 1 deletion zebra-chain/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl Constraint for NonNegative {
/// -MAX_MONEY..=0,
/// );
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default)]
pub struct NegativeOrZero;

impl Constraint for NegativeOrZero {
Expand Down
4 changes: 4 additions & 0 deletions zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Commitment {
(Nu5 | Nu6, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
#[cfg(zcash_unstable = "nsm")]
(ZFuture, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
}
}

Expand Down
21 changes: 21 additions & 0 deletions zebra-chain/src/history_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ impl NonEmptyHistoryTree {
)?;
InnerHistoryTree::OrchardOnward(tree)
}
#[cfg(zcash_unstable = "nsm")]
NetworkUpgrade::ZFuture => {
let tree = Tree::<OrchardOnward>::new_from_cache(
network,
network_upgrade,
size,
&peaks,
&Default::default(),
)?;
InnerHistoryTree::OrchardOnward(tree)
}
};
Ok(Self {
network: network.clone(),
Expand Down Expand Up @@ -165,6 +176,16 @@ impl NonEmptyHistoryTree {
)?;
(InnerHistoryTree::OrchardOnward(tree), entry)
}
#[cfg(zcash_unstable = "nsm")]
NetworkUpgrade::ZFuture => {
let (tree, entry) = Tree::<OrchardOnward>::new_from_block(
network,
block,
sapling_root,
orchard_root,
)?;
(InnerHistoryTree::OrchardOnward(tree), entry)
}
};
let mut peaks = BTreeMap::new();
peaks.insert(0u32, entry);
Expand Down
17 changes: 15 additions & 2 deletions zebra-chain/src/parameters/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ pub struct ConfiguredActivationHeights {
/// Activation height for `NU6` network upgrade.
#[serde(rename = "NU6")]
pub nu6: Option<u32>,
#[cfg(zcash_unstable = "nsm")]
#[serde(rename = "ZFuture")]
pub zfuture: Option<u32>,
}

/// Builder for the [`Parameters`] struct.
Expand Down Expand Up @@ -336,6 +339,8 @@ impl ParametersBuilder {
canopy,
nu5,
nu6,
#[cfg(zcash_unstable = "nsm")]
zfuture,
}: ConfiguredActivationHeights,
) -> Self {
use NetworkUpgrade::*;
Expand All @@ -348,7 +353,7 @@ impl ParametersBuilder {
//
// These must be in order so that later network upgrades overwrite prior ones
// if multiple network upgrades are configured with the same activation height.
let activation_heights: BTreeMap<_, _> = before_overwinter
let activation_heights = before_overwinter
.into_iter()
.map(|h| (h, BeforeOverwinter))
.chain(overwinter.into_iter().map(|h| (h, Overwinter)))
Expand All @@ -357,7 +362,13 @@ impl ParametersBuilder {
.chain(heartwood.into_iter().map(|h| (h, Heartwood)))
.chain(canopy.into_iter().map(|h| (h, Canopy)))
.chain(nu5.into_iter().map(|h| (h, Nu5)))
.chain(nu6.into_iter().map(|h| (h, Nu6)))
.chain(nu6.into_iter().map(|h| (h, Nu6)));

#[cfg(zcash_unstable = "nsm")]
let activation_heights =
activation_heights.chain(zfuture.into_iter().map(|h| (h, ZFuture)));

let activation_heights: BTreeMap<_, _> = activation_heights
.map(|(h, nu)| (h.try_into().expect("activation height must be valid"), nu))
.collect();

Expand Down Expand Up @@ -604,6 +615,8 @@ impl Parameters {
canopy: Some(1),
nu5: nu5_activation_height,
nu6: nu6_activation_height,
#[cfg(zcash_unstable = "nsm")]
zfuture: nu5_activation_height.map(|height| height + 1),
..Default::default()
})
.with_halving_interval(PRE_BLOSSOM_REGTEST_HALVING_INTERVAL);
Expand Down
9 changes: 8 additions & 1 deletion zebra-chain/src/parameters/network/tests/vectors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Fixed test vectors for the network consensus parameters.

use zcash_primitives::consensus::NetworkConstants as _;
use zcash_primitives::consensus::{self as zp_consensus, Parameters};
use zcash_protocol::consensus::NetworkConstants as _;

use crate::{
block::Height,
Expand Down Expand Up @@ -31,6 +31,8 @@ fn check_parameters_impl() {
zp_consensus::NetworkUpgrade::Heartwood,
zp_consensus::NetworkUpgrade::Canopy,
zp_consensus::NetworkUpgrade::Nu5,
#[cfg(zcash_unstable = "nsm")]
zp_consensus::NetworkUpgrade::ZFuture,
];

for (network, zp_network) in [
Expand Down Expand Up @@ -109,7 +111,10 @@ fn activates_network_upgrades_correctly() {
let expected_activation_height = 1;
let network = testnet::Parameters::build()
.with_activation_heights(ConfiguredActivationHeights {
#[cfg(not(zcash_unstable = "nsm"))]
nu6: Some(expected_activation_height),
#[cfg(zcash_unstable = "nsm")]
zfuture: Some(expected_activation_height),
..Default::default()
})
.to_network();
Expand Down Expand Up @@ -141,6 +146,8 @@ fn activates_network_upgrades_correctly() {
(Height(1), NetworkUpgrade::Canopy),
// TODO: Remove this once the testnet parameters are being serialized (#8920).
(Height(100), NetworkUpgrade::Nu5),
#[cfg(zcash_unstable = "nsm")]
(Height(101), NetworkUpgrade::ZFuture),
];

for (network, expected_activation_heights) in [
Expand Down
Loading
Loading