Skip to content

Commit

Permalink
Update shared NU5 dependencies, set the NU5 testnet activation networ…
Browse files Browse the repository at this point in the history
…k upgrade parameters (#2825)

* Check return value of zcash_script_new_precomputed_tx

* Set the NU5 testnet activation height to 1_590_000

* Apply suggestions from code review

Co-authored-by: teor <[email protected]>

* Update Nu5 constants to new values

* Update ZIP-244 test vectors for new branch ID

* Squashed commit of the following:

commit bdb120a
Author: Deirdre Connolly <[email protected]>
Date:   Tue Oct 5 11:54:01 2021 -0400

    Use pallas::Base::from_str_vartime() in sinsemilla tests

commit e99fa49
Author: Deirdre Connolly <[email protected]>
Date:   Tue Oct 5 11:45:24 2021 -0400

    Compiles

commit a520018
Author: Deirdre Connolly <[email protected]>
Date:   Tue Oct 5 10:15:17 2021 -0400

    Incomplete upgrade of deps

* Squashed commit of the following:

commit 8d1b76e
Author: Janito Vaqueiro Ferreira Filho <[email protected]>
Date:   Tue Oct 5 04:02:26 2021 +0000

    Update `zcash_script` to support V5 transactions

    Use a newer version of `zcash_script` that has been updated to support
    V5 transactions.

commit 3712336
Author: Janito Vaqueiro Ferreira Filho <[email protected]>
Date:   Tue Oct 5 03:06:20 2021 +0000

    Update Zcash dependencies

    Update some Zcash crates:

    - `halo2`
    - `incrementalmerkletree' (patch version)
    - `orchard` (patch version)
    - `zcash_history` (patch version)
    - `zcash_note_encryption` (patch version)
    - `zcash_primitives` (patch version)

    And also update the `group` dependency so that the code remains
    compatible.

commit de5cf1e
Author: Janito Vaqueiro Ferreira Filho <[email protected]>
Date:   Tue Oct 5 03:04:13 2021 +0000

    Update error message assertion

    Use the updated message for the expected error variant.

* Update `zcash_script` to support V5 transactions

Use a newer version of `zcash_script` that has been updated to support
V5 transactions.

Co-authored-by: Conrado Gouvea <[email protected]>
Co-authored-by: teor <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2021
1 parent 5d9893c commit 339fefb
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 305 deletions.
419 changes: 337 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tower = { git = "https://github.com/tower-rs/tower", rev = "d4d1c67c6a0e4213a52a

# TODO: remove these after a new librustzcash release.
# These are librustzcash requirements specified in its workspace Cargo.toml that we must replicate here
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "236115917df9db45282fec24d1e1e36f275f71ab" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "37b1b7f357cd34d93f9c55bb96efd05ab4e84408" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "0c3ed159985affa774e44d10172d4471d798a85a" }
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "2c8241f25b943aa05203eacf9905db117c69bd29" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }
12 changes: 5 additions & 7 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bench = ["zebra-test"]
[dependencies]
aes = "0.6"
bech32 = "0.8.1"
bigint = "4"
bigint = "4.4.3"
bitflags = "1.2.1"
bitvec = "0.22"
blake2b_simd = "0.5.11"
Expand All @@ -27,10 +27,8 @@ chrono = { version = "0.4", features = ["serde"] }
displaydoc = "0.2.2"
fpe = "0.4"
futures = "0.3"
group = "0.10"
# TODO: replace w/ crate version when released: https://github.com/ZcashFoundation/zebra/issues/2083
# Note: if updating this, also update the workspace Cargo.toml to match.
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "236115917df9db45282fec24d1e1e36f275f71ab" }
group = "0.11"
halo2 = "=0.1.0-beta.1"
hex = "0.4"
incrementalmerkletree = "0.1.0"
jubjub = "0.7.0"
Expand All @@ -45,8 +43,8 @@ subtle = "2.4"
thiserror = "1"
uint = "0.9.1"
x25519-dalek = { version = "1.1", features = ["serde"] }
zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "0c3ed159985affa774e44d10172d4471d798a85a" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "0c3ed159985affa774e44d10172d4471d798a85a" }
zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }

proptest = { version = "0.10", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/orchard/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ mod tests {
use super::*;
use crate::orchard::tests::vectors;

#[cfg(test)]
fn x_from_str(s: &str) -> pallas::Base {
use group::ff::PrimeField;

pallas::Base::from_str(s).unwrap()
pallas::Base::from_str_vartime(s).unwrap()
}

#[test]
Expand Down
6 changes: 2 additions & 4 deletions zebra-chain/src/orchard/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,14 @@ impl NoteCommitmentTree {
///
/// For Orchard, the tree is capped at 2^32.
pub fn count(&self) -> u64 {
self.inner
.position()
.map_or(0, |pos| usize::from(pos) as u64 + 1)
self.inner.position().map_or(0, |pos| u64::from(pos) + 1)
}
}

impl Default for NoteCommitmentTree {
fn default() -> Self {
Self {
inner: bridgetree::Frontier::new(),
inner: bridgetree::Frontier::empty(),
cached_root: Default::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/parameters/network_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(crate) const TESTNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)]
(block::Height(584_000), Blossom),
(block::Height(903_800), Heartwood),
(block::Height(1_028_500), Canopy),
// TODO: Add Nu5 testnet activation height
(block::Height(1_599_200), Nu5),
];

#[cfg(test_fake_activation_heights)]
Expand Down Expand Up @@ -131,7 +131,7 @@ pub(crate) const CONSENSUS_BRANCH_IDS: &[(NetworkUpgrade, ConsensusBranchId)] =
(Blossom, ConsensusBranchId(0x2bb40e60)),
(Heartwood, ConsensusBranchId(0xf5b9230b)),
(Canopy, ConsensusBranchId(0xe9ff75a6)),
(Nu5, ConsensusBranchId(0xf919a198)),
(Nu5, ConsensusBranchId(0x37519621)),
];

/// The target block spacing before Blossom.
Expand Down
6 changes: 2 additions & 4 deletions zebra-chain/src/sapling/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,14 @@ impl NoteCommitmentTree {
///
/// For Sapling, the tree is capped at 2^32.
pub fn count(&self) -> u64 {
self.inner
.position()
.map_or(0, |pos| usize::from(pos) as u64 + 1)
self.inner.position().map_or(0, |pos| u64::from(pos) + 1)
}
}

impl Default for NoteCommitmentTree {
fn default() -> Self {
Self {
inner: bridgetree::Frontier::new(),
inner: bridgetree::Frontier::empty(),
cached_root: Default::default(),
}
}
Expand Down
1 change: 0 additions & 1 deletion zebra-consensus/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ where

// TODO:
// - verify orchard shielded pool (ZIP-224) (#2105)
// - ZIP-216 (#1798)
// - ZIP-244 (#1874)
// - remaining consensus rules (#2379)
// - remove `should_panic` from tests
Expand Down
71 changes: 35 additions & 36 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,40 +234,47 @@ async fn v5_transaction_is_rejected_before_nu5_activation() {
}

#[tokio::test]
// TODO: Remove `should_panic` once the NU5 activation heights for testnet and mainnet have been
// TODO: Remove `should_panic` once the NU5 activation height for mainnet has been
// defined.
#[should_panic]
async fn v5_transaction_is_accepted_after_nu5_activation() {
async fn v5_transaction_is_accepted_after_nu5_activation_mainnet() {
v5_transaction_is_accepted_after_nu5_activation_for_network(Network::Mainnet).await
}

#[tokio::test]
async fn v5_transaction_is_accepted_after_nu5_activation_testnet() {
v5_transaction_is_accepted_after_nu5_activation_for_network(Network::Testnet).await
}

async fn v5_transaction_is_accepted_after_nu5_activation_for_network(network: Network) {
let nu5 = NetworkUpgrade::Nu5;
let networks = vec![
(Network::Mainnet, zebra_test::vectors::MAINNET_BLOCKS.iter()),
(Network::Testnet, zebra_test::vectors::TESTNET_BLOCKS.iter()),
];
let blocks = match network {
Network::Mainnet => zebra_test::vectors::MAINNET_BLOCKS.iter(),
Network::Testnet => zebra_test::vectors::TESTNET_BLOCKS.iter(),
};

for (network, blocks) in networks {
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
let script_verifier = script::Verifier::new(state_service);
let verifier = Verifier::new(network, script_verifier);
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
let script_verifier = script::Verifier::new(state_service);
let verifier = Verifier::new(network, script_verifier);

let transaction = fake_v5_transactions_for_network(network, blocks)
.rev()
.next()
.expect("At least one fake V5 transaction in the test vectors");
let transaction = fake_v5_transactions_for_network(network, blocks)
.rev()
.next()
.expect("At least one fake V5 transaction in the test vectors");

let expected_hash = transaction.unmined_id();
let expected_hash = transaction.unmined_id();

let result = verifier
.oneshot(Request::Block {
transaction: Arc::new(transaction),
known_utxos: Arc::new(HashMap::new()),
height: nu5
.activation_height(network)
.expect("NU5 activation height is specified"),
})
.await;
let result = verifier
.oneshot(Request::Block {
transaction: Arc::new(transaction),
known_utxos: Arc::new(HashMap::new()),
height: nu5
.activation_height(network)
.expect("NU5 activation height is specified"),
})
.await;

assert_eq!(result, Ok(expected_hash));
}
assert_eq!(result, Ok(expected_hash));
}

/// Test if V4 transaction with transparent funds is accepted.
Expand Down Expand Up @@ -414,9 +421,6 @@ async fn v4_transaction_with_transparent_transfer_is_rejected_by_the_script() {

/// Test if V5 transaction with transparent funds is accepted.
#[tokio::test]
// TODO: Remove `should_panic` once the NU5 activation heights for testnet and mainnet have been
// defined.
#[should_panic]
async fn v5_transaction_with_transparent_transfer_is_accepted() {
let network = Network::Testnet;
let network_upgrade = NetworkUpgrade::Nu5;
Expand Down Expand Up @@ -465,9 +469,6 @@ async fn v5_transaction_with_transparent_transfer_is_accepted() {

/// Test if V5 coinbase transaction is accepted.
#[tokio::test]
// TODO: Remove `should_panic` once the NU5 activation heights for testnet and mainnet have been
// defined.
#[should_panic]
async fn v5_coinbase_transaction_is_accepted() {
let network = Network::Testnet;
let network_upgrade = NetworkUpgrade::Nu5;
Expand Down Expand Up @@ -517,9 +518,6 @@ async fn v5_coinbase_transaction_is_accepted() {
/// This test simulates the case where the script verifier rejects the transaction because the
/// script prevents spending the source UTXO.
#[tokio::test]
// TODO: Remove `should_panic` once the NU5 activation heights for testnet and mainnet have been
// defined.
#[should_panic]
async fn v5_transaction_with_transparent_transfer_is_rejected_by_the_script() {
let network = Network::Testnet;
let network_upgrade = NetworkUpgrade::Nu5;
Expand Down Expand Up @@ -564,7 +562,8 @@ async fn v5_transaction_with_transparent_transfer_is_rejected_by_the_script() {
assert_eq!(
result,
Err(TransactionError::InternalDowncastError(
"downcast to redjubjub::Error failed, original error: ScriptInvalid".to_string()
"downcast to known transaction error type failed, original error: ScriptInvalid"
.to_string()
))
);
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-network/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub const USER_AGENT: &str = "/Zebra:1.0.0-alpha.17/";
///
/// The current protocol version typically changes before Mainnet and Testnet
/// network upgrades.
pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_014);
pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_015);

/// The minimum network protocol version accepted by this crate for each network,
/// represented as a network upgrade.
Expand Down
4 changes: 2 additions & 2 deletions zebra-network/src/protocol/external/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ impl Version {
(Mainnet, Heartwood) => 170_011,
(Testnet, Canopy) => 170_012,
(Mainnet, Canopy) => 170_013,
(Testnet, Nu5) => 170_014,
(Mainnet, Nu5) => 170_015,
(Testnet, Nu5) => 170_015,
(Mainnet, Nu5) => unreachable!("Nu5 Mainnet protocol version not yet defined"),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
zcash_script = "0.1.6-alpha.0"
zcash_script = { git = "https://github.com/ZcashFoundation/zcash_script.git", rev = "1caa29e975405400983f679a376fb1c86527d5f2" }
zebra-chain = { path = "../zebra-chain" }
thiserror = "1.0.29"
displaydoc = "0.2.2"
Expand Down
6 changes: 6 additions & 0 deletions zebra-script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ impl CachedFfiTransaction {
let precomputed = unsafe {
zcash_script::zcash_script_new_precomputed_tx(tx_to_ptr, tx_to_len, &mut err)
};
assert!(
!precomputed.is_null(),
"zcash_script_new_precomputed_tx returned {} ({})",
err,
Error::from(err)
);

Self {
transaction,
Expand Down
2 changes: 1 addition & 1 deletion zebra-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tempdir = "0.3.7"
tokio = { version = "0.3.6", features = ["full"] }
# TODO: replace w/ crate version when released: https://github.com/ZcashFoundation/zebra/issues/2083
# Note: if updating this, also update the workspace Cargo.toml to match.
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "236115917df9db45282fec24d1e1e36f275f71ab" }
halo2 = "=0.1.0-beta.1"
jubjub = "0.7.0"

proptest = "0.10.1"
Expand Down
Loading

0 comments on commit 339fefb

Please sign in to comment.