From 600c06a408085251857e40d2d0b938bdb899f548 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 24 Feb 2022 09:24:00 -0700 Subject: [PATCH 1/4] Update MSRV to 1.56.1 --- .github/workflows/ci.yml | 16 ++++++++-------- components/equihash/CHANGELOG.md | 3 +++ components/zcash_note_encryption/CHANGELOG.md | 3 +++ rust-toolchain | 2 +- zcash_client_backend/CHANGELOG.md | 2 +- zcash_client_sqlite/CHANGELOG.md | 2 +- zcash_history/CHANGELOG.md | 1 + zcash_primitives/CHANGELOG.md | 2 +- zcash_proofs/CHANGELOG.md | 2 +- 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b18f582e..9de06130f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 override: true - name: Fetch path to Zcash parameters @@ -55,7 +55,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 override: true - name: Add target run: rustup target add ${{ matrix.target }} @@ -78,7 +78,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 override: true # Build benchmarks to prevent bitrot - name: Build benchmarks @@ -88,20 +88,20 @@ jobs: args: --all --benches clippy: - name: Clippy (1.51.0) + name: Clippy (1.56.1) timeout-minutes: 30 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 components: clippy override: true - name: Run clippy uses: actions-rs/clippy-check@v1 with: - name: Clippy (1.51.0) + name: Clippy (1.56.1) token: ${{ secrets.GITHUB_TOKEN }} args: --all-features --all-targets -- -D warnings @@ -173,7 +173,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 override: true - name: cargo fetch uses: actions-rs/cargo@v1 @@ -196,7 +196,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.51.0 + toolchain: 1.56.1 override: true # cargo fmt does not build the code, and running it in a fresh clone of diff --git a/components/equihash/CHANGELOG.md b/components/equihash/CHANGELOG.md index a0585d64d..3d5392d8a 100644 --- a/components/equihash/CHANGELOG.md +++ b/components/equihash/CHANGELOG.md @@ -7,5 +7,8 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Changed +- MSRV is now 1.56.1. + ## [0.1.0] - 2020-07-10 Initial release. diff --git a/components/zcash_note_encryption/CHANGELOG.md b/components/zcash_note_encryption/CHANGELOG.md index 5dd6dae9c..17634ee17 100644 --- a/components/zcash_note_encryption/CHANGELOG.md +++ b/components/zcash_note_encryption/CHANGELOG.md @@ -7,5 +7,8 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Changed +- MSRV is now 1.56.1. + ## [0.1.0] - 2021-12-17 Initial release. diff --git a/rust-toolchain b/rust-toolchain index ba0a71911..43c989b55 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.51.0 +1.56.1 diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index ec81dbe47..f07a18c28 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -38,7 +38,7 @@ and this library adheres to Rust's notion of - `zcash_client_backend::encoding::encode_transparent_address` ### Changed -- MSRV is now 1.51.0. +- MSRV is now 1.56.1. - Bumped dependencies to `ff 0.11`, `group 0.11`, `bls12_381 0.6`, `jubjub 0.8`. - `epk: jubjub::ExtendedPoint` has been replaced by `ephemeral_key: zcash_note_encryption::EphemeralKeyBytes` in various places: diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 1050aebda..3fe72ef1a 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -18,7 +18,7 @@ and this library adheres to Rust's notion of rewinds exceed supported bounds. ### Changed -- MSRV is now 1.51.0. +- MSRV is now 1.56.1. - Bumped dependencies to `ff 0.11`, `group 0.11`, `jubjub 0.8`. - Renamed the following to use lower-case abbreviations (matching Rust naming conventions): diff --git a/zcash_history/CHANGELOG.md b/zcash_history/CHANGELOG.md index 3cdcb1221..fe2aa696a 100644 --- a/zcash_history/CHANGELOG.md +++ b/zcash_history/CHANGELOG.md @@ -14,6 +14,7 @@ and this library adheres to Rust's notion of - `zcash_history::Entry::new_leaf` ### Changed +- MSRV is now 1.56.1. - `zcash_history::{Entry, IndexedNode, Tree}` now have a `Version` parameter. ### Removed diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index d421bf51f..343e46f31 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -101,7 +101,7 @@ and this library adheres to Rust's notion of - `impl Sum<&Amount> for Option` ### Changed -- MSRV is now 1.51.0. +- MSRV is now 1.56.1. - Bumped dependencies to `ff 0.11`, `group 0.11`, `bls12_381 0.6`, `jubjub 0.8`. - The following modules and helpers have been moved into `zcash_primitives::sapling`: diff --git a/zcash_proofs/CHANGELOG.md b/zcash_proofs/CHANGELOG.md index 124affb4e..b13c262f0 100644 --- a/zcash_proofs/CHANGELOG.md +++ b/zcash_proofs/CHANGELOG.md @@ -7,7 +7,7 @@ and this library adheres to Rust's notion of ## [Unreleased] ### Changed -- MSRV is now 1.51.0. +- MSRV is now 1.56.1. - Bumped dependencies to `ff 0.11`, `group 0.11`, `bellman 0.11.1`, `bls12_381 0.6`, `jubjub 0.8`. - `zcash_proofs::sapling::SaplingVerificationContext::new` now takes a From b97d777361e530b987d42065c02353462fe73409 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 24 Feb 2022 09:24:00 -0700 Subject: [PATCH 2/4] Update the versions of incrementalmerkletree & orchard. This removes unreleased incrementalmerkletree::BridgeTree serialization that was zcashd-specific. --- Cargo.toml | 4 +- .../src/merkle_tree/incremental.rs | 154 +++++------------- 2 files changed, 46 insertions(+), 112 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b57d3c750..4c95ffb05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ panic = 'abort' codegen-units = 1 [patch.crates-io] +hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" } +incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "dd57b430dee7c0b163f4035fef2280cd1935036c" } +orchard = { git = "https://github.com/zcash/orchard.git", rev = "8449fd133c002a349869c09c529a4d214b20c0c0" } zcash_encoding = { path = "components/zcash_encoding" } zcash_note_encryption = { path = "components/zcash_note_encryption" } -hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" } diff --git a/zcash_primitives/src/merkle_tree/incremental.rs b/zcash_primitives/src/merkle_tree/incremental.rs index 3e3e3dc52..94e80bebb 100644 --- a/zcash_primitives/src/merkle_tree/incremental.rs +++ b/zcash_primitives/src/merkle_tree/incremental.rs @@ -1,14 +1,11 @@ //! Implementations of serialization and parsing for Orchard note commitment trees. use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use std::convert::TryFrom; -use std::hash::Hash; +use std::convert::{TryFrom, TryInto}; use std::io::{self, Read, Write}; use incrementalmerkletree::{ - bridgetree::{ - AuthFragment, BridgeTree, Checkpoint, Frontier, Leaf, MerkleBridge, NonEmptyFrontier, - }, + bridgetree::{AuthFragment, Frontier, Leaf, MerkleBridge, NonEmptyFrontier}, Hashable, Position, }; use orchard::tree::MerkleHashOrchard; @@ -18,14 +15,6 @@ use super::{CommitmentTree, HashSer}; pub const SER_V1: u8 = 1; -pub fn read_frontier_v0( - mut reader: R, -) -> io::Result> { - let tree = CommitmentTree::read(&mut reader)?; - - Ok(tree.to_frontier()) -} - impl HashSer for MerkleHashOrchard { fn read(mut reader: R) -> io::Result where @@ -46,6 +35,14 @@ impl HashSer for MerkleHashOrchard { } } +pub fn read_frontier_v0( + mut reader: R, +) -> io::Result> { + let tree = CommitmentTree::read(&mut reader)?; + + Ok(tree.to_frontier()) +} + pub fn write_nonempty_frontier_v1( mut writer: W, frontier: &NonEmptyFrontier, @@ -108,19 +105,32 @@ pub fn read_frontier_v1(reader: R) -> io::Result(mut writer: W, position: Position) -> io::Result<()> { + writer.write_u64::(position.try_into().unwrap()) +} + +pub fn read_position(mut reader: R) -> io::Result { + let p = reader.read_u64::()?; + ::try_from(p).map(Position::from).map_err(|err| { + io::Error::new( + io::ErrorKind::Unsupported, + format!( + "usize could not be decoded to a 64-bit value on this platform: {:?}", + err + ), + ) + }) +} + pub fn write_auth_fragment_v1( mut writer: W, fragment: &AuthFragment, ) -> io::Result<()> { - writer.write_u64::(::from(fragment.position()))?; - writer.write_u64::(fragment.altitudes_observed() as u64)?; + write_position(&mut writer, fragment.position())?; + writer.write_u64::(fragment.altitudes_observed().try_into().unwrap())?; Vector::write(&mut writer, fragment.values(), |w, a| a.write(w)) } -pub fn read_position(mut reader: R) -> io::Result { - Ok(Position::from(reader.read_u64::()? as usize)) -} - #[allow(clippy::redundant_closure)] pub fn read_auth_fragment_v1(mut reader: R) -> io::Result> { let position = read_position(&mut reader)?; @@ -130,7 +140,7 @@ pub fn read_auth_fragment_v1(mut reader: R) -> io::Result( +pub fn write_bridge_v1( mut writer: W, bridge: &MerkleBridge, ) -> io::Result<()> { @@ -143,7 +153,7 @@ pub fn write_bridge_v1( &mut writer, &bridge.auth_fragments().iter().collect::>(), |w, (i, a)| { - w.write_u64::(**i as u64)?; + w.write_u64::(u64::from(**i))?; write_auth_fragment_v1(w, a) }, )?; @@ -152,13 +162,12 @@ pub fn write_bridge_v1( Ok(()) } -pub fn read_bridge_v1(mut reader: R) -> io::Result> { +pub fn read_bridge_v1( + mut reader: R, +) -> io::Result> { let prior_position = Optional::read(&mut reader, read_position)?; - let auth_fragments = Vector::read(&mut reader, |r| { - Ok(( - r.read_u64::()? as usize, - read_auth_fragment_v1(r)?, - )) + let auth_fragments = Vector::read(&mut reader, |mut r| { + Ok((read_position(&mut r)?, read_auth_fragment_v1(r)?)) })? .into_iter() .collect(); @@ -171,99 +180,22 @@ pub fn read_bridge_v1(mut reader: R) -> io::Result< )) } -pub const EMPTY_CHECKPOINT: u8 = 0; -pub const BRIDGE_CHECKPOINT: u8 = 1; - -pub fn write_checkpoint_v1(mut writer: W, checkpoint: &Checkpoint) -> io::Result<()> { - match checkpoint { - Checkpoint::Empty => { - writer.write_u8(EMPTY_CHECKPOINT)?; - } - Checkpoint::AtIndex(i) => { - writer.write_u8(BRIDGE_CHECKPOINT)?; - writer.write_u64::(*i as u64)?; - } - } - - Ok(()) -} - -pub fn read_checkpoint_v1(mut reader: R) -> io::Result { - match reader.read_u8()? { - EMPTY_CHECKPOINT => Ok(Checkpoint::Empty), - BRIDGE_CHECKPOINT => Ok(Checkpoint::AtIndex( - reader.read_u64::()? as usize - )), - flag => Err(io::Error::new( - io::ErrorKind::InvalidInput, - format!("Unrecognized checkpoint variant identifier: {:?}", flag), - )), - } -} - -pub fn write_tree_v1( - mut writer: W, - tree: &BridgeTree, -) -> io::Result<()> { - Vector::write(&mut writer, tree.bridges(), |w, b| write_bridge_v1(w, b))?; - Vector::write( - &mut writer, - &tree.witnessable_leaves().iter().collect::>(), - |mut w, (a, i)| { - a.write(&mut w)?; - w.write_u64::(**i as u64)?; - Ok(()) - }, - )?; - Vector::write(&mut writer, tree.checkpoints(), |w, c| { - write_checkpoint_v1(w, c) - })?; - writer.write_u64::(tree.max_checkpoints() as u64)?; - - Ok(()) -} - -#[allow(clippy::redundant_closure)] -pub fn read_tree_v1( - mut reader: R, -) -> io::Result> { - BridgeTree::from_parts( - Vector::read(&mut reader, |r| read_bridge_v1(r))?, - Vector::read(&mut reader, |mut r| { - Ok((H::read(&mut r)?, r.read_u64::()? as usize)) - })? - .into_iter() - .collect(), - Vector::read(&mut reader, |r| read_checkpoint_v1(r))?, - reader.read_u64::()? as usize, - ) - .map_err(|err| { - io::Error::new( - io::ErrorKind::InvalidInput, - format!( - "Consistency violation found when attempting to deserialize Merkle tree: {:?}", - err - ), - ) - }) -} - -pub fn write_tree( +pub fn write_bridge( mut writer: W, - tree: &BridgeTree, + bridge: &MerkleBridge, ) -> io::Result<()> { writer.write_u8(SER_V1)?; - write_tree_v1(&mut writer, tree) + write_bridge_v1(writer, bridge) } -pub fn read_tree( +pub fn read_bridge( mut reader: R, -) -> io::Result> { +) -> io::Result> { match reader.read_u8()? { - SER_V1 => read_tree_v1(&mut reader), + SER_V1 => read_bridge_v1(&mut reader), flag => Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("Unrecognized tree serialization version: {:?}", flag), + format!("Unrecognized serialization version: {:?}", flag), )), } } From bdaad538325712dadcb5c51f9982b06b5edbcb13 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Feb 2022 21:34:03 +0000 Subject: [PATCH 3/4] Update `orchard` revision --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4c95ffb05..5456f0e36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,6 @@ codegen-units = 1 [patch.crates-io] hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" } incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "dd57b430dee7c0b163f4035fef2280cd1935036c" } -orchard = { git = "https://github.com/zcash/orchard.git", rev = "8449fd133c002a349869c09c529a4d214b20c0c0" } +orchard = { git = "https://github.com/zcash/orchard.git", rev = "a5f701f3186fb619b40f2dee9939e64e4c9eb7cc" } zcash_encoding = { path = "components/zcash_encoding" } zcash_note_encryption = { path = "components/zcash_note_encryption" } From 22ebe95de62e045987f660ed7021eb9219a8a0c3 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Feb 2022 22:39:13 +0000 Subject: [PATCH 4/4] zcash_primitives: Replace custom `Debug` impl on `TransactionData` --- zcash_primitives/src/transaction/mod.rs | 94 ++----------------------- 1 file changed, 5 insertions(+), 89 deletions(-) diff --git a/zcash_primitives/src/transaction/mod.rs b/zcash_primitives/src/transaction/mod.rs index e208860d8..f0ac7d3aa 100644 --- a/zcash_primitives/src/transaction/mod.rs +++ b/zcash_primitives/src/transaction/mod.rs @@ -239,6 +239,7 @@ pub trait Authorization { type TzeAuth: tze::Authorization; } +#[derive(Debug)] pub struct Authorized; impl Authorization for Authorized { @@ -282,6 +283,7 @@ impl PartialEq for Transaction { } } +#[derive(Debug)] pub struct TransactionData { version: TxVersion, consensus_branch_id: BranchId, @@ -434,92 +436,6 @@ impl TransactionData { } } -impl std::fmt::Debug for TransactionData { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - write!( - f, - "TransactionData( - version = {:?}, - consensus_branch_id = {:?}, - lock_time = {:?}, - expiry_height = {:?}, - transparent_fields = {{{}}} - sprout = {{{}}}, - sapling = {{{}}}, - orchard = {{{}}}, - tze = {{{}}} - )", - self.version, - self.consensus_branch_id, - self.lock_time, - self.expiry_height, - if let Some(b) = &self.transparent_bundle { - format!( - " - vin = {:?}, - vout = {:?}, - ", - b.vin, b.vout - ) - } else { - "".to_string() - }, - if let Some(b) = &self.sprout_bundle { - format!( - " - joinsplits = {:?}, - joinsplit_pubkey = {:?}, - ", - b.joinsplits, b.joinsplit_pubkey - ) - } else { - "".to_string() - }, - if let Some(b) = &self.sapling_bundle { - format!( - " - value_balance = {:?}, - shielded_spends = {:?}, - shielded_outputs = {:?}, - binding_sig = {:?}, - ", - b.value_balance, b.shielded_spends, b.shielded_outputs, b.authorization - ) - } else { - "".to_string() - }, - if let Some(b) = &self.orchard_bundle { - format!( - " - value_balance = {:?}, - actions = {:?}, - ", - b.value_balance(), - b.actions().len() - ) - } else { - "".to_string() - }, - { - #[cfg(feature = "zfuture")] - if let Some(b) = &self.tze_bundle { - format!( - " - tze_inputs = {:?}, - tze_outputs = {:?}, - ", - b.vin, b.vout - ) - } else { - "".to_string() - } - #[cfg(not(feature = "zfuture"))] - "" - } - ) - } -} - impl TransactionData { pub fn sapling_value_balance(&self) -> Amount { self.sapling_bundle @@ -988,7 +904,7 @@ impl Transaction { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct TransparentDigests { pub prevout_digest: A, pub sequence_digest: A, @@ -996,14 +912,14 @@ pub struct TransparentDigests { pub per_input_digest: Option, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct TzeDigests { pub inputs_digest: A, pub outputs_digest: A, pub per_input_digest: Option, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct TxDigests { pub header_digest: A, pub transparent_digests: Option>,