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 234 & 235 implementation #8948

Open
wants to merge 7 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
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ resolver = "2"
# `cargo release` settings

[workspace.dependencies]
incrementalmerkletree = { version = "0.7.0", features = ["legacy-api"] }
incrementalmerkletree = "0.7.0"
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
3 changes: 2 additions & 1 deletion zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ use crate::{
};

mod commitment;
mod error;
mod hash;
mod header;
mod height;
mod serialize;

pub mod error;
pub mod genesis;
pub mod merkle;
pub mod subsidy;

#[cfg(any(test, feature = "proptest-impl"))]
pub mod arbitrary;
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
15 changes: 14 additions & 1 deletion zebra-chain/src/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

use thiserror::Error;

use crate::error::SubsidyError;

#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;

#[derive(Clone, Error, Debug, PartialEq, Eq)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
#[allow(missing_docs)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum BlockError {
#[error("block has no transactions")]
NoTransactions,

#[error("transaction has wrong consensus branch id for block network upgrade")]
WrongTransactionConsensusBranchId,

#[error("block failed subsidy validation")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Subsidy(#[from] SubsidyError),
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::collections::HashMap;

use zebra_chain::{
use crate::{
amount::{Amount, Error, NonNegative},
block::Height,
parameters::{subsidy::*, Network, NetworkUpgrade::*},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Tests for funding streams.

use color_eyre::Report;
use zebra_chain::parameters::{subsidy::FundingStreamReceiver, NetworkKind};

use crate::block::subsidy::general::block_subsidy;
use crate::{
block::subsidy::general::block_subsidy_pre_nsm,
parameters::{subsidy::FundingStreamReceiver, NetworkKind},
};

use super::*;

Expand Down Expand Up @@ -70,7 +72,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
nu6_fund_height_range.end,
nu6_fund_height_range.end.next().unwrap(),
] {
let fsv = funding_stream_values(height, network, block_subsidy(height, network)?).unwrap();
let fsv = funding_stream_values(height, network, block_subsidy_pre_nsm(height, network)?)
.unwrap();

if height < canopy_activation_height {
assert!(fsv.is_empty());
Expand Down
Loading
Loading