Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into sqlite_legacy_support
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Sep 3, 2024
2 parents 01576f1 + 50cdf73 commit f063e7a
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 52 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ categories = ["cryptography::cryptocurrencies"]
[workspace.dependencies]
# Intra-workspace dependencies
equihash = { version = "0.2", path = "components/equihash" }
zcash_address = { version = "0.4", path = "components/zcash_address" }
zcash_address = { version = "0.5", path = "components/zcash_address" }
zcash_client_backend = { version = "0.13", path = "zcash_client_backend" }
zcash_encoding = { version = "0.2.1", path = "components/zcash_encoding" }
zcash_keys = { version = "0.3", path = "zcash_keys" }
zcash_protocol = { version = "0.2", path = "components/zcash_protocol" }
zcash_protocol = { version = "0.3", path = "components/zcash_protocol" }
zip321 = { version = "0.1", path = "components/zip321" }

zcash_note_encryption = "0.4"
zcash_primitives = { version = "0.16", path = "zcash_primitives", default-features = false }
zcash_proofs = { version = "0.16", path = "zcash_proofs", default-features = false }
zcash_primitives = { version = "0.17", path = "zcash_primitives", default-features = false }
zcash_proofs = { version = "0.17", path = "zcash_proofs", default-features = false }

# Shielded protocols
bellman = { version = "0.14", default-features = false, features = ["groth16"] }
Expand Down
4 changes: 4 additions & 0 deletions components/zcash_address/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this library adheres to Rust's notion of

## [Unreleased]

## [0.5.0] - 2024-08-26
### Changed
- Updated `zcash_protocol` dependency to version `0.3`

## [0.4.0] - 2024-08-19
### Added
- `zcash_address::ZcashAddress::{can_receive_memo, can_receive_as, matches_receiver}`
Expand Down
2 changes: 1 addition & 1 deletion components/zcash_address/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zcash_address"
description = "Zcash address parsing and serialization"
version = "0.4.0"
version = "0.5.0"
authors = [
"Jack Grigg <jack@electriccoin.co>",
]
Expand Down
18 changes: 18 additions & 0 deletions components/zcash_protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this library adheres to Rust's notion of

## [Unreleased]

### Added
- `impl Sub<BlockHeight> for BlockHeight` unlike the implementation that was
removed in version `0.3.0`, a saturating subtraction for block heights having
a return type of `u32` makes sense for `BlockHeight`. Subtracting one block
height from another yields the delta between them.

### Changed
- Adding a delta to a `BlockHeight` now uses saturating addition.
- Subtracting a delta to a `BlockHeight` now uses saturating subtraction.

## [0.3.0] - 2024-08-26
### Changed
- Testnet activation height has been set for `consensus::BranchId::Nu6`.

### Removed
- `impl {Add, Sub} for BlockHeight` - these operations were unused, and it
does not make sense to add block heights (it is not a monoid.)

## [0.2.0] - 2024-08-19
### Added
- `zcash_protocol::PoolType::{TRANSPARENT, SAPLING, ORCHARD}`
Expand Down
2 changes: 1 addition & 1 deletion components/zcash_protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zcash_protocol"
description = "Zcash protocol network constants and value types."
version = "0.2.0"
version = "0.3.0"
authors = [
"Jack Grigg <jack@electriccoin.co>",
"Kris Nuttycombe <kris@nutty.land>",
Expand Down
26 changes: 7 additions & 19 deletions components/zcash_protocol/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,35 +103,23 @@ impl Add<u32> for BlockHeight {
type Output = Self;

fn add(self, other: u32) -> Self {
BlockHeight(self.0 + other)
}
}

impl Add for BlockHeight {
type Output = Self;

fn add(self, other: Self) -> Self {
self + other.0
BlockHeight(self.0.saturating_add(other))
}
}

impl Sub<u32> for BlockHeight {
type Output = Self;

fn sub(self, other: u32) -> Self {
if other > self.0 {
panic!("Subtraction resulted in negative block height.");
}

BlockHeight(self.0 - other)
BlockHeight(self.0.saturating_sub(other))
}
}

impl Sub for BlockHeight {
type Output = Self;
impl Sub<BlockHeight> for BlockHeight {
type Output = u32;

fn sub(self, other: Self) -> Self {
self - other.0
fn sub(self, other: BlockHeight) -> u32 {
self.0.saturating_sub(other.0)
}
}

Expand Down Expand Up @@ -383,7 +371,7 @@ impl Parameters for TestNetwork {
NetworkUpgrade::Heartwood => Some(BlockHeight(903_800)),
NetworkUpgrade::Canopy => Some(BlockHeight(1_028_500)),
NetworkUpgrade::Nu5 => Some(BlockHeight(1_842_420)),
NetworkUpgrade::Nu6 => None,
NetworkUpgrade::Nu6 => Some(BlockHeight(2_976_000)),
#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => None,
}
Expand Down
18 changes: 18 additions & 0 deletions supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,12 @@ user-id = 6289 # Jack Grigg (str4d)
start = "2021-03-07"
end = "2025-04-22"

[[trusted.zcash_address]]
criteria = "safe-to-deploy"
user-id = 169181 # Kris Nuttycombe (nuttycom)
start = "2024-08-20"
end = "2025-08-26"

[[trusted.zcash_client_backend]]
criteria = "safe-to-deploy"
user-id = 169181 # Kris Nuttycombe (nuttycom)
Expand Down Expand Up @@ -843,12 +849,24 @@ user-id = 1244 # ebfull
start = "2019-10-08"
end = "2025-04-22"

[[trusted.zcash_primitives]]
criteria = "safe-to-deploy"
user-id = 169181 # Kris Nuttycombe (nuttycom)
start = "2024-08-20"
end = "2025-08-26"

[[trusted.zcash_proofs]]
criteria = ["safe-to-deploy", "crypto-reviewed", "license-reviewed"]
user-id = 6289 # Jack Grigg (str4d)
start = "2021-03-26"
end = "2025-04-22"

[[trusted.zcash_proofs]]
criteria = "safe-to-deploy"
user-id = 169181 # Kris Nuttycombe (nuttycom)
start = "2024-08-20"
end = "2025-08-26"

[[trusted.zcash_protocol]]
criteria = "safe-to-deploy"
user-id = 169181 # Kris Nuttycombe (nuttycom)
Expand Down
34 changes: 17 additions & 17 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ user-login = "str4d"
user-name = "Jack Grigg"

[[publisher.zcash_address]]
version = "0.3.2"
when = "2024-03-06"
user-id = 6289
user-login = "str4d"
user-name = "Jack Grigg"
version = "0.5.0"
when = "2024-08-26"
user-id = 169181
user-login = "nuttycom"
user-name = "Kris Nuttycombe"

[[publisher.zcash_client_backend]]
version = "0.13.0"
Expand Down Expand Up @@ -279,22 +279,22 @@ user-login = "nuttycom"
user-name = "Kris Nuttycombe"

[[publisher.zcash_primitives]]
version = "0.15.1"
when = "2024-05-24"
user-id = 6289
user-login = "str4d"
user-name = "Jack Grigg"
version = "0.17.0"
when = "2024-08-26"
user-id = 169181
user-login = "nuttycom"
user-name = "Kris Nuttycombe"

[[publisher.zcash_proofs]]
version = "0.15.0"
when = "2024-03-25"
user-id = 6289
user-login = "str4d"
user-name = "Jack Grigg"
version = "0.17.0"
when = "2024-08-26"
user-id = 169181
user-login = "nuttycom"
user-name = "Kris Nuttycombe"

[[publisher.zcash_protocol]]
version = "0.2.0"
when = "2024-08-19"
version = "0.3.0"
when = "2024-08-26"
user-id = 169181
user-login = "nuttycom"
user-name = "Kris Nuttycombe"
Expand Down
10 changes: 10 additions & 0 deletions zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,13 @@ impl RusqliteMigration for Migration {
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

#[cfg(test)]
mod tests {
use crate::wallet::init::migrations::tests::test_migrate;

#[test]
fn migrate() {
test_migrate(&[super::MIGRATION_ID]);
}
}
6 changes: 6 additions & 0 deletions zcash_keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this library adheres to Rust's notion of

## [Unreleased]

### Added
- `zcash_keys::encoding::decode_extfvk_with_network`
- `impl std::error::Error for Bech32DecodeError`
- `impl std::error::Error for DecodingError`
- `impl std::error::Error for DerivationError`

## [0.3.0] - 2024-08-19
### Notable changes
- `zcash_keys`:
Expand Down
50 changes: 46 additions & 4 deletions zcash_keys/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::address::UnifiedAddress;
use bs58::{self, decode::Error as Bs58Error};
use std::fmt;
use zcash_primitives::consensus::NetworkConstants;
use zcash_primitives::consensus::{NetworkConstants, NetworkType};

use zcash_address::unified::{self, Encoding};
use zcash_primitives::{consensus, legacy::TransparentAddress};
Expand Down Expand Up @@ -66,6 +66,16 @@ impl fmt::Display for Bech32DecodeError {
}
}

#[cfg(feature = "sapling")]
impl std::error::Error for Bech32DecodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Bech32DecodeError::Bech32Error(e) => Some(e),
_ => None,
}
}
}

#[cfg(feature = "sapling")]
fn bech32_decode<T, F>(hrp: &str, s: &str, read: F) -> Result<T, Bech32DecodeError>
where
Expand Down Expand Up @@ -245,9 +255,8 @@ pub fn encode_extended_full_viewing_key(hrp: &str, extfvk: &ExtendedFullViewingK
bech32_encode(hrp, |w| extfvk.write(w))
}

/// Decodes an [`ExtendedFullViewingKey`] from a Bech32-encoded string.
///
/// [`ExtendedFullViewingKey`]: sapling::zip32::ExtendedFullViewingKey
/// Decodes an [`ExtendedFullViewingKey`] from a Bech32-encoded string, verifying that it matches
/// the provided human-readable prefix.
#[cfg(feature = "sapling")]
pub fn decode_extended_full_viewing_key(
hrp: &str,
Expand All @@ -256,6 +265,39 @@ pub fn decode_extended_full_viewing_key(
bech32_decode(hrp, s, |data| ExtendedFullViewingKey::read(&data[..]).ok())
}

/// Decodes an [`ExtendedFullViewingKey`] and the [`NetworkType`] that it is intended for use with
/// from a Bech32-encoded string.
#[cfg(feature = "sapling")]
pub fn decode_extfvk_with_network(
s: &str,
) -> Result<(NetworkType, ExtendedFullViewingKey), Bech32DecodeError> {
use zcash_protocol::constants::{mainnet, regtest, testnet};

let (decoded_hrp, data, variant) = bech32::decode(s)?;
if variant != Variant::Bech32 {
Err(Bech32DecodeError::IncorrectVariant(variant))
} else {
let network = match &decoded_hrp[..] {
mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY => Ok(NetworkType::Main),
testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY => Ok(NetworkType::Test),
regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY => Ok(NetworkType::Regtest),
other => Err(Bech32DecodeError::HrpMismatch {
expected: format!(
"One of {}, {}, or {}",
mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
),
actual: other.to_string(),
}),
}?;
let fvk = ExtendedFullViewingKey::read(&Vec::<u8>::from_base32(&data)?[..])
.map_err(|_| Bech32DecodeError::ReadError)?;

Ok((network, fvk))
}
}

/// Writes a [`PaymentAddress`] as a Bech32-encoded string.
///
/// # Examples
Expand Down
Loading

0 comments on commit f063e7a

Please sign in to comment.