From 59582a77342d2f806f82bc210f97f0536e8cf10d Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Wed, 21 Aug 2024 16:49:13 -0600 Subject: [PATCH 01/23] Update audits for zcash_client_sqlite --- supply-chain/imports.lock | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 9e94d0893b..0145b6d3ba 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -244,6 +244,13 @@ user-id = 169181 user-login = "nuttycom" user-name = "Kris Nuttycombe" +[[publisher.zcash_client_sqlite]] +version = "0.11.1" +when = "2024-08-21" +user-id = 169181 +user-login = "nuttycom" +user-name = "Kris Nuttycombe" + [[publisher.zcash_encoding]] version = "0.2.0" when = "2022-10-19" From 0348af63dc728c0a362ff8b2a1ef2d92f0b6aa25 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Thu, 22 Aug 2024 15:11:04 +0100 Subject: [PATCH 02/23] Make `zcash_client_backend::fees::{fixed,standard,zip317}::SingleOutputChangeStrategy` doc comments more accurate concerning the choice of output pool. Signed-off-by: Daira-Emma Hopwood --- zcash_client_backend/src/fees/fixed.rs | 6 ++++-- zcash_client_backend/src/fees/standard.rs | 6 ++++-- zcash_client_backend/src/fees/zip317.rs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/zcash_client_backend/src/fees/fixed.rs b/zcash_client_backend/src/fees/fixed.rs index 933b008207..d2033eba0b 100644 --- a/zcash_client_backend/src/fees/fixed.rs +++ b/zcash_client_backend/src/fees/fixed.rs @@ -19,8 +19,10 @@ use super::{ #[cfg(feature = "orchard")] use super::orchard as orchard_fees; -/// A change strategy that proposes change as a single output to the most current supported -/// shielded pool and delegates fee calculation to the provided fee rule. +/// A change strategy that proposes change as a single output. The output pool is chosen +/// as the most current pool that avoids unnecessary pool-crossing (with a specified +/// fallback when the transaction has no shielded inputs). Fee calculation is delegated +/// to the provided fee rule. pub struct SingleOutputChangeStrategy { fee_rule: FixedFeeRule, change_memo: Option, diff --git a/zcash_client_backend/src/fees/standard.rs b/zcash_client_backend/src/fees/standard.rs index 5c08c7b1af..4cad64c5d2 100644 --- a/zcash_client_backend/src/fees/standard.rs +++ b/zcash_client_backend/src/fees/standard.rs @@ -24,8 +24,10 @@ use super::{ #[cfg(feature = "orchard")] use super::orchard as orchard_fees; -/// A change strategy that proposes change as a single output to the most current supported -/// shielded pool and delegates fee calculation to the provided fee rule. +/// A change strategy that proposes change as a single output. The output pool is chosen +/// as the most current pool that avoids unnecessary pool-crossing (with a specified +/// fallback when the transaction has no shielded inputs). Fee calculation is delegated +/// to the provided fee rule. pub struct SingleOutputChangeStrategy { fee_rule: StandardFeeRule, change_memo: Option, diff --git a/zcash_client_backend/src/fees/zip317.rs b/zcash_client_backend/src/fees/zip317.rs index c5cd7d499a..d8813e3611 100644 --- a/zcash_client_backend/src/fees/zip317.rs +++ b/zcash_client_backend/src/fees/zip317.rs @@ -23,8 +23,10 @@ use super::{ #[cfg(feature = "orchard")] use super::orchard as orchard_fees; -/// A change strategy that proposes change as a single output to the most current supported -/// shielded pool and delegates fee calculation to the provided fee rule. +/// A change strategy that proposes change as a single output. The output pool is chosen +/// as the most current pool that avoids unnecessary pool-crossing (with a specified +/// fallback when the transaction has no shielded inputs). Fee calculation is delegated +/// to the provided fee rule. pub struct SingleOutputChangeStrategy { fee_rule: Zip317FeeRule, change_memo: Option, From 7d3e5754d69c9a3014043dba0d057ab59016ad01 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 22 Aug 2024 12:13:20 -0600 Subject: [PATCH 03/23] zcash_client_sqlite: Add missing test of `utxos_to_txos` migration. --- .../src/wallet/init/migrations/utxos_to_txos.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs index 60ab722146..687ddf51f4 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs @@ -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]); + } +} From 8259825d645f36ec383780e737bedb174c4a34a3 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Sun, 25 Aug 2024 10:02:33 -0600 Subject: [PATCH 04/23] zcash_protocol: Remove impl {Add, Sub} for BlockHeight These operations are unused, and block heights form a vector space, not a monoid. --- components/zcash_protocol/CHANGELOG.md | 4 ++++ components/zcash_protocol/src/consensus.rs | 16 ---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/components/zcash_protocol/CHANGELOG.md b/components/zcash_protocol/CHANGELOG.md index 45df906538..e9f8e85647 100644 --- a/components/zcash_protocol/CHANGELOG.md +++ b/components/zcash_protocol/CHANGELOG.md @@ -7,6 +7,10 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Removed +- `impl {Add, Sub} for BlockHeight` - these operations were unused, and block + heights are a vector space, not a monoid. + ## [0.2.0] - 2024-08-19 ### Added - `zcash_protocol::PoolType::{TRANSPARENT, SAPLING, ORCHARD}` diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index 0ad1d04e11..c034da519b 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -107,14 +107,6 @@ impl Add for BlockHeight { } } -impl Add for BlockHeight { - type Output = Self; - - fn add(self, other: Self) -> Self { - self + other.0 - } -} - impl Sub for BlockHeight { type Output = Self; @@ -127,14 +119,6 @@ impl Sub for BlockHeight { } } -impl Sub for BlockHeight { - type Output = Self; - - fn sub(self, other: Self) -> Self { - self - other.0 - } -} - /// Constants associated with a given Zcash network. pub trait NetworkConstants: Clone { /// The coin type for ZEC, as defined by [SLIP 44]. From 529e3be5717c514f754c74f2fc45fde5052e49d1 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 13:50:34 -0600 Subject: [PATCH 05/23] zcash_protocol: Set the public testnet activation height for NU6 --- components/zcash_protocol/src/consensus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index 0ad1d04e11..fe98ec6df0 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -383,7 +383,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, } From a30037be818a43bb60aadf343c650d504b971132 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 15:31:17 -0600 Subject: [PATCH 06/23] Release zcash_protocol version 0.3.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- components/zcash_protocol/CHANGELOG.md | 8 ++++++-- components/zcash_protocol/Cargo.toml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4f3541b89..10903d9b84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6068,7 +6068,7 @@ dependencies = [ [[package]] name = "zcash_protocol" -version = "0.2.0" +version = "0.3.0" dependencies = [ "document-features", "incrementalmerkletree", diff --git a/Cargo.toml b/Cargo.toml index 4fabe1b733..61e8f1b7d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ zcash_address = { version = "0.4", 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" diff --git a/components/zcash_protocol/CHANGELOG.md b/components/zcash_protocol/CHANGELOG.md index e9f8e85647..618e983418 100644 --- a/components/zcash_protocol/CHANGELOG.md +++ b/components/zcash_protocol/CHANGELOG.md @@ -7,9 +7,13 @@ and this library adheres to Rust's notion of ## [Unreleased] +## [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 block - heights are a vector space, not a monoid. +- `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 diff --git a/components/zcash_protocol/Cargo.toml b/components/zcash_protocol/Cargo.toml index 2e88482c80..20ac967d61 100644 --- a/components/zcash_protocol/Cargo.toml +++ b/components/zcash_protocol/Cargo.toml @@ -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 ", "Kris Nuttycombe ", From f54be17169f62c1dbdd0bfdc40b2f76a8cfeef97 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:11:02 -0600 Subject: [PATCH 07/23] Update cargo vet metadata for release of zcash_protocol version 0.3.0 --- supply-chain/imports.lock | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 0145b6d3ba..d29120700c 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -237,13 +237,6 @@ user-id = 169181 user-login = "nuttycom" user-name = "Kris Nuttycombe" -[[publisher.zcash_client_sqlite]] -version = "0.11.0" -when = "2024-08-20" -user-id = 169181 -user-login = "nuttycom" -user-name = "Kris Nuttycombe" - [[publisher.zcash_client_sqlite]] version = "0.11.1" when = "2024-08-21" @@ -300,8 +293,8 @@ user-login = "str4d" user-name = "Jack Grigg" [[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" From 5dcda498100ae4ba0436c51405cd89d214c65c1a Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 15:45:21 -0600 Subject: [PATCH 08/23] release zcash_address version 0.5.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- components/zcash_address/CHANGELOG.md | 4 ++++ components/zcash_address/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10903d9b84..25b3914bdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5802,7 +5802,7 @@ dependencies = [ [[package]] name = "zcash_address" -version = "0.4.0" +version = "0.5.0" dependencies = [ "assert_matches", "bech32", diff --git a/Cargo.toml b/Cargo.toml index 61e8f1b7d2..a3942b66de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ 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" } diff --git a/components/zcash_address/CHANGELOG.md b/components/zcash_address/CHANGELOG.md index 6f864af664..8f9d8a8101 100644 --- a/components/zcash_address/CHANGELOG.md +++ b/components/zcash_address/CHANGELOG.md @@ -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}` diff --git a/components/zcash_address/Cargo.toml b/components/zcash_address/Cargo.toml index 4e2b58b42c..a2be0995c3 100644 --- a/components/zcash_address/Cargo.toml +++ b/components/zcash_address/Cargo.toml @@ -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 ", ] From 76b18c1bec7694f4ad04991b78c29fb28240d47b Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:16:02 -0600 Subject: [PATCH 09/23] Update cargo vet metadata for `zcash_address` release 0.5.0 --- supply-chain/audits.toml | 6 ++++++ supply-chain/imports.lock | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index b425783f52..c14ef21ae8 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -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) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index d29120700c..fc733ef7fe 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -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" From 70e61218414a8ab5a547867c77c4f733f35b2590 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:22:19 -0600 Subject: [PATCH 10/23] Release zcash_primitives version 0.17.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- zcash_primitives/CHANGELOG.md | 5 +++++ zcash_primitives/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25b3914bdd..59451f7ebe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6000,7 +6000,7 @@ dependencies = [ [[package]] name = "zcash_primitives" -version = "0.16.0" +version = "0.17.0" dependencies = [ "aes", "assert_matches", diff --git a/Cargo.toml b/Cargo.toml index a3942b66de..4a4fbd732c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ 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_primitives = { version = "0.17", path = "zcash_primitives", default-features = false } zcash_proofs = { version = "0.16", path = "zcash_proofs", default-features = false } # Shielded protocols diff --git a/zcash_primitives/CHANGELOG.md b/zcash_primitives/CHANGELOG.md index 379ca3f668..0eff56ecb7 100644 --- a/zcash_primitives/CHANGELOG.md +++ b/zcash_primitives/CHANGELOG.md @@ -7,6 +7,11 @@ and this library adheres to Rust's notion of ## [Unreleased] +## [0.17.0] - 2024-08-26 + +### Changed +- Update dependencies to `zcash_protocol 0.3.0`, `zcash_address 0.5.0` + ## [0.16.0] - 2024-08-19 ### Added diff --git a/zcash_primitives/Cargo.toml b/zcash_primitives/Cargo.toml index bb015b0741..c59f186b4e 100644 --- a/zcash_primitives/Cargo.toml +++ b/zcash_primitives/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_primitives" description = "Rust implementations of the Zcash primitives" -version = "0.16.0" +version = "0.17.0" authors = [ "Jack Grigg ", "Kris Nuttycombe " From ab225fc5404c7bc923886bbdcdd05e9c8a10b987 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:37:47 -0600 Subject: [PATCH 11/23] Update supply chain audits for `zcash_primitives 0.17.0` --- supply-chain/audits.toml | 6 ++++++ supply-chain/imports.lock | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index c14ef21ae8..d2d22e1cbc 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -849,6 +849,12 @@ 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) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index fc733ef7fe..9ed506b573 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -279,11 +279,11 @@ 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" From df0679fd8830898e0ed6e94034269729d279cb15 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:40:44 -0600 Subject: [PATCH 12/23] release zcash_proofs version 0.17.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- zcash_proofs/CHANGELOG.md | 5 +++++ zcash_proofs/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59451f7ebe..cd1680e4c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6044,7 +6044,7 @@ dependencies = [ [[package]] name = "zcash_proofs" -version = "0.16.0" +version = "0.17.0" dependencies = [ "bellman", "blake2b_simd", diff --git a/Cargo.toml b/Cargo.toml index 4a4fbd732c..6b2e0e94a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ zip321 = { version = "0.1", path = "components/zip321" } zcash_note_encryption = "0.4" zcash_primitives = { version = "0.17", path = "zcash_primitives", default-features = false } -zcash_proofs = { version = "0.16", path = "zcash_proofs", 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"] } diff --git a/zcash_proofs/CHANGELOG.md b/zcash_proofs/CHANGELOG.md index 9868d6eb0f..d659b0a025 100644 --- a/zcash_proofs/CHANGELOG.md +++ b/zcash_proofs/CHANGELOG.md @@ -7,6 +7,11 @@ and this library adheres to Rust's notion of ## [Unreleased] +## [0.17.0] - 2024-08-26 + +### Changed +- Migrated to `zcash_primitives 0.17`. + ## [0.16.0] - 2024-08-19 ### Changed diff --git a/zcash_proofs/Cargo.toml b/zcash_proofs/Cargo.toml index dbc5045394..45d75615ce 100644 --- a/zcash_proofs/Cargo.toml +++ b/zcash_proofs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_proofs" description = "Zcash zk-SNARK circuits and proving APIs" -version = "0.16.0" +version = "0.17.0" authors = [ "Jack Grigg ", ] From 7094acc5078368fffab813ba8f7d23b6a681f4f6 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 26 Aug 2024 16:58:11 -0600 Subject: [PATCH 13/23] Update audit metadata for zcash_proofs 0.17.0 --- supply-chain/audits.toml | 6 ++++++ supply-chain/imports.lock | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index d2d22e1cbc..83fa292747 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -861,6 +861,12 @@ 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) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 9ed506b573..c3f51ffd4f 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -286,11 +286,11 @@ 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.3.0" From 1b3433e0ddafffedfa834db6f238d93d6f3a8ed9 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 27 Aug 2024 16:44:00 -0600 Subject: [PATCH 14/23] Add correct `BlockHeight` subtraction & remove panics. In contrast to the implementation of `Sub for BlockHeight` 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. Other block height addition and subtraction operations have been made saturating, removing panics and the possibility of overflow. --- components/zcash_protocol/CHANGELOG.md | 10 ++++++++++ components/zcash_protocol/src/consensus.rs | 14 +++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/zcash_protocol/CHANGELOG.md b/components/zcash_protocol/CHANGELOG.md index 618e983418..e2e99084f5 100644 --- a/components/zcash_protocol/CHANGELOG.md +++ b/components/zcash_protocol/CHANGELOG.md @@ -7,6 +7,16 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Added +- `impl Sub 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`. diff --git a/components/zcash_protocol/src/consensus.rs b/components/zcash_protocol/src/consensus.rs index 5f480714c4..43a1b6f863 100644 --- a/components/zcash_protocol/src/consensus.rs +++ b/components/zcash_protocol/src/consensus.rs @@ -103,7 +103,7 @@ impl Add for BlockHeight { type Output = Self; fn add(self, other: u32) -> Self { - BlockHeight(self.0 + other) + BlockHeight(self.0.saturating_add(other)) } } @@ -111,11 +111,15 @@ impl Sub 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.saturating_sub(other)) + } +} + +impl Sub for BlockHeight { + type Output = u32; - BlockHeight(self.0 - other) + fn sub(self, other: BlockHeight) -> u32 { + self.0.saturating_sub(other.0) } } From c91b34ef87a520fea626366b6cf1986df85d8a2b Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 22 Aug 2024 12:03:54 -0600 Subject: [PATCH 15/23] Support older `sqlite` versions. The `FALSE` constant was introduced in sqlite version 3.23.0, but Android does not support this version of sqlite until API level 30; we support back to Android API 27 so we have to use `0` as the constant for `FALSE` instead. --- zcash_client_sqlite/CHANGELOG.md | 5 + zcash_client_sqlite/src/wallet/db.rs | 2 +- .../src/wallet/init/migrations.rs | 4 + .../init/migrations/support_legacy_sqlite.rs | 91 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index e577920ece..6f1bb2f4a7 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -7,6 +7,11 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Changed +- The `v_tx_outputs` view was modified slightly to support older versions of + `sqlite`. + + ## [0.11.1] - 2024-08-21 ### Fixed diff --git a/zcash_client_sqlite/src/wallet/db.rs b/zcash_client_sqlite/src/wallet/db.rs index 22d08b3f3c..3fe97c66c3 100644 --- a/zcash_client_sqlite/src/wallet/db.rs +++ b/zcash_client_sqlite/src/wallet/db.rs @@ -883,7 +883,7 @@ SELECT transactions.txid AS txid, NULL AS to_account_id, sent_notes.to_address AS to_address, sent_notes.value AS value, - FALSE AS is_change, + 0 AS is_change, sent_notes.memo AS memo FROM sent_notes JOIN transactions diff --git a/zcash_client_sqlite/src/wallet/init/migrations.rs b/zcash_client_sqlite/src/wallet/init/migrations.rs index 10c97b7909..ed29f7f484 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations.rs @@ -15,6 +15,7 @@ mod sapling_memo_consistency; mod sent_notes_to_internal; mod shardtree_support; mod spend_key_available; +mod support_legacy_sqlite; mod tx_retrieval_queue; mod ufvk_support; mod utxos_table; @@ -74,6 +75,8 @@ pub(super) fn all_migrations( // \ \ ephemeral_addresses / / // \ \ | / / // ------------------------------ tx_retrieval_queue ---------------------------- + // | + // support_legacy_sqlite vec![ Box::new(initial_setup::Migration {}), Box::new(utxos_table::Migration {}), @@ -131,6 +134,7 @@ pub(super) fn all_migrations( Box::new(tx_retrieval_queue::Migration { params: params.clone(), }), + Box::new(support_legacy_sqlite::Migration), ] } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs b/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs new file mode 100644 index 0000000000..54bd7f1fb1 --- /dev/null +++ b/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs @@ -0,0 +1,91 @@ +//! A migration that removes the use of `FALSE` in sqlite view definitions. +//! This is necessary to support older +use std::collections::HashSet; + +use rusqlite; +use schemer; +use schemer_rusqlite::RusqliteMigration; +use uuid::Uuid; + +use crate::wallet::init::{migrations::tx_retrieval_queue, WalletMigrationError}; + +pub(super) const MIGRATION_ID: Uuid = Uuid::from_u128(0xc9ed1fb5_b2c3_467f_89dc_2591dcca5562); + +const DEPENDENCIES: &[Uuid] = &[tx_retrieval_queue::MIGRATION_ID]; + +pub(super) struct Migration; + +impl schemer::Migration for Migration { + fn id(&self) -> Uuid { + MIGRATION_ID + } + + fn dependencies(&self) -> HashSet { + DEPENDENCIES.iter().copied().collect() + } + + fn description(&self) -> &'static str { + "Removes the FALSE keyword from the v_tx_outputs view definition" + } +} + +impl RusqliteMigration for Migration { + type Error = WalletMigrationError; + + fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { + transaction.execute_batch( + r#" + DROP VIEW v_tx_outputs; + CREATE VIEW v_tx_outputs AS + -- select all outputs received by the wallet + SELECT transactions.txid AS txid, + ro.pool AS output_pool, + ro.output_index AS output_index, + sent_notes.from_account_id AS from_account_id, + ro.account_id AS to_account_id, + NULL AS to_address, + ro.value AS value, + ro.is_change AS is_change, + ro.memo AS memo + FROM v_received_outputs ro + JOIN transactions + ON transactions.id_tx = ro.transaction_id + -- join to the sent_notes table to obtain `from_account_id` + LEFT JOIN sent_notes ON sent_notes.id = ro.sent_note_id + UNION + -- select all outputs sent from the wallet to external recipients + SELECT transactions.txid AS txid, + sent_notes.output_pool AS output_pool, + sent_notes.output_index AS output_index, + sent_notes.from_account_id AS from_account_id, + NULL AS to_account_id, + sent_notes.to_address AS to_address, + sent_notes.value AS value, + 0 AS is_change, + sent_notes.memo AS memo + FROM sent_notes + JOIN transactions + ON transactions.id_tx = sent_notes.tx + LEFT JOIN v_received_outputs ro ON ro.sent_note_id = sent_notes.id + -- exclude any sent notes for which a row exists in the v_received_outputs view + WHERE ro.account_id IS NULL + "#, + )?; + + Ok(()) + } + + fn down(&self, _: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { + 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]); + } +} From 897018a4718d56692bd552fff37898e511246db9 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 30 Aug 2024 14:11:59 -0600 Subject: [PATCH 16/23] zcash_keys: Add `decode_extfvk_with_network` --- zcash_keys/CHANGELOG.md | 3 +++ zcash_keys/src/encoding.rs | 40 ++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/zcash_keys/CHANGELOG.md b/zcash_keys/CHANGELOG.md index 060a70dca1..e7454fb178 100644 --- a/zcash_keys/CHANGELOG.md +++ b/zcash_keys/CHANGELOG.md @@ -6,6 +6,9 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Added +- `zcash_keys::encoding::decode_extfvk_with_network` + ## [0.3.0] - 2024-08-19 ### Notable changes - `zcash_keys`: diff --git a/zcash_keys/src/encoding.rs b/zcash_keys/src/encoding.rs index 8de7125a05..f53931f7da 100644 --- a/zcash_keys/src/encoding.rs +++ b/zcash_keys/src/encoding.rs @@ -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}; @@ -245,9 +245,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, @@ -256,6 +255,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::::from_base32(&data)?[..]) + .map_err(|_| Bech32DecodeError::ReadError)?; + + Ok((network, fvk)) + } +} + /// Writes a [`PaymentAddress`] as a Bech32-encoded string. /// /// # Examples From af695dc1c2989ec910a302e5a1ad5b07b26aed4a Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 30 Aug 2024 14:30:16 -0600 Subject: [PATCH 17/23] Add unstable `UnifiedFullViewingKey::from_sapling_extended_full_viewing_key` --- zcash_keys/src/keys.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index f1f8d6eb6c..cd8b6a18f4 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -37,6 +37,9 @@ use { #[cfg(feature = "orchard")] use orchard::{self, keys::Scope}; +#[cfg(all(feature = "sapling", feature = "unstable"))] +use ::sapling::zip32::ExtendedFullViewingKey; + #[cfg(feature = "sapling")] pub mod sapling { pub use sapling::zip32::{ @@ -674,6 +677,24 @@ impl UnifiedFullViewingKey { vec![], ) } + + #[cfg(all(feature = "sapling", feature = "unstable"))] + pub fn from_sapling_extended_full_viewing_key( + sapling: ExtendedFullViewingKey, + ) -> Result { + Self::from_checked_parts( + #[cfg(feature = "transparent-inputs")] + None, + #[cfg(feature = "sapling")] + Some(sapling.to_diversifiable_full_viewing_key()), + #[cfg(feature = "orchard")] + None, + // We don't currently allow constructing new UFVKs with unknown items, but we store + // this to allow parsing such UFVKs. + vec![], + ) + } + /// Construct a UFVK from its constituent parts, after verifying that UIVK derivation can /// succeed. fn from_checked_parts( From a7329323aa19d47aa85fb1d6bdbe34a29df9963e Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 30 Aug 2024 14:30:16 -0600 Subject: [PATCH 18/23] zcash_keys: implement std::error::Error for decoding errors --- zcash_keys/CHANGELOG.md | 3 +++ zcash_keys/src/encoding.rs | 10 ++++++++++ zcash_keys/src/keys.rs | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/zcash_keys/CHANGELOG.md b/zcash_keys/CHANGELOG.md index e7454fb178..a0bb242d35 100644 --- a/zcash_keys/CHANGELOG.md +++ b/zcash_keys/CHANGELOG.md @@ -8,6 +8,9 @@ and this library adheres to Rust's notion of ### 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 diff --git a/zcash_keys/src/encoding.rs b/zcash_keys/src/encoding.rs index f53931f7da..894103a04b 100644 --- a/zcash_keys/src/encoding.rs +++ b/zcash_keys/src/encoding.rs @@ -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(hrp: &str, s: &str, read: F) -> Result where diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index cd8b6a18f4..dbd8f79346 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -114,6 +114,8 @@ impl Display for DerivationError { } } +impl std::error::Error for DerivationError {} + /// A version identifier for the encoding of unified spending keys. /// /// Each era corresponds to a range of block heights. During an era, the unified spending key @@ -179,6 +181,8 @@ impl std::fmt::Display for DecodingError { } } +impl std::error::Error for DecodingError {} + #[cfg(feature = "unstable")] impl Era { /// Returns the unique identifier for the era. From 5ad432ad6e4fdb6215a340c0170849619fc8cf01 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 30 Aug 2024 16:47:09 -0600 Subject: [PATCH 19/23] zcash_client_sqlite: Do not require a transparent key for migrations. The `reserve_until` method for generating ephemeral addresses is used in database migrations, but it makes no sense to use this in the case that the UFVK for an account contains no transparent component; such accounts can never be used to make ZIP 320 spends. --- .../src/wallet/transparent/ephemeral.rs | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs b/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs index e8811bd37e..9e24bc413a 100644 --- a/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs +++ b/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs @@ -113,7 +113,7 @@ pub(crate) fn get_ephemeral_ivk( conn: &rusqlite::Connection, params: &P, account_id: AccountId, -) -> Result { +) -> Result, SqliteClientError> { let ufvk = conn .query_row( "SELECT ufvk FROM accounts WHERE id = :account_id", @@ -133,8 +133,8 @@ pub(crate) fn get_ephemeral_ivk( let eivk = ufvk .as_ref() .and_then(|ufvk| ufvk.transparent()) - .ok_or(SqliteClientError::UnknownZip32Derivation)? - .derive_ephemeral_ivk()?; + .map(|t| t.derive_ephemeral_ivk()) + .transpose()?; Ok(eivk) } @@ -265,11 +265,11 @@ pub(crate) fn init_account( reserve_until(conn, params, account_id, 0) } -/// Extend the range of stored addresses in an account if necessary so that the -/// index of the next address to reserve will be *at least* `next_to_reserve`. -/// If it would already have been at least `next_to_reserve`, then do nothing. +/// Extend the range of stored addresses in an account if necessary so that the index of the next +/// address to reserve will be *at least* `next_to_reserve`. If no transparent key exists for the +/// given account or it would already have been at least `next_to_reserve`, then do nothing. /// -/// Note that this is called from db migration code. +/// Note that this is called from database migration code. /// /// # Panics /// @@ -282,39 +282,40 @@ fn reserve_until( ) -> Result<(), SqliteClientError> { assert!(next_to_reserve <= 1 << 31); - let first_unstored = first_unstored_index(conn, account_id)?; - let range_to_store = first_unstored..(next_to_reserve.checked_add(GAP_LIMIT).unwrap()); - if range_to_store.is_empty() { - return Ok(()); - } - - let ephemeral_ivk = get_ephemeral_ivk(conn, params, account_id)?; - - // used_in_tx and seen_in_tx are initially NULL - let mut stmt_insert_ephemeral_address = conn.prepare_cached( - "INSERT INTO ephemeral_addresses (account_id, address_index, address) - VALUES (:account_id, :address_index, :address)", - )?; + if let Some(ephemeral_ivk) = get_ephemeral_ivk(conn, params, account_id)? { + let first_unstored = first_unstored_index(conn, account_id)?; + let range_to_store = first_unstored..(next_to_reserve.checked_add(GAP_LIMIT).unwrap()); + if range_to_store.is_empty() { + return Ok(()); + } - for raw_index in range_to_store { - // The range to store may contain indicies that are out of the valid range of non hardened - // child indices; we still store explicit rows in the ephemeral_addresses table for these - // so that it's possible to find the first unused address using dead reckoning with the gap - // limit. - let address_str_opt = NonHardenedChildIndex::from_index(raw_index) - .map(|address_index| { - ephemeral_ivk - .derive_ephemeral_address(address_index) - .map(|addr| addr.encode(params)) - }) - .transpose()?; - - stmt_insert_ephemeral_address.execute(named_params![ - ":account_id": account_id.0, - ":address_index": raw_index, - ":address": address_str_opt, - ])?; + // used_in_tx and seen_in_tx are initially NULL + let mut stmt_insert_ephemeral_address = conn.prepare_cached( + "INSERT INTO ephemeral_addresses (account_id, address_index, address) + VALUES (:account_id, :address_index, :address)", + )?; + + for raw_index in range_to_store { + // The range to store may contain indicies that are out of the valid range of non hardened + // child indices; we still store explicit rows in the ephemeral_addresses table for these + // so that it's possible to find the first unused address using dead reckoning with the gap + // limit. + let address_str_opt = NonHardenedChildIndex::from_index(raw_index) + .map(|address_index| { + ephemeral_ivk + .derive_ephemeral_address(address_index) + .map(|addr| addr.encode(params)) + }) + .transpose()?; + + stmt_insert_ephemeral_address.execute(named_params![ + ":account_id": account_id.0, + ":address_index": raw_index, + ":address": address_str_opt, + ])?; + } } + Ok(()) } From 61584f7cc0b6770b81d49049b6a1af560ad4de68 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 27 Aug 2024 15:03:03 -0600 Subject: [PATCH 20/23] zcash_client_sqlite: Verify sqlite version compatibility on wallet init. --- zcash_client_sqlite/CHANGELOG.md | 18 ++++--- zcash_client_sqlite/Cargo.toml | 2 +- zcash_client_sqlite/src/wallet/init.rs | 51 +++++++++++++++++++ .../init/migrations/support_legacy_sqlite.rs | 7 ++- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 6f1bb2f4a7..0878b3fd46 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -9,8 +9,14 @@ and this library adheres to Rust's notion of ### Changed - The `v_tx_outputs` view was modified slightly to support older versions of - `sqlite`. - + `sqlite`. Queries to the exposed `v_tx_outputs` and `v_transactions` views + are supported for SQLite versions back to `3.19.x`. +- `zcash_client_sqlite::wallet::init::WalletMigrationError` has an additional + variant, `DatabaseNotSupported`. The `init_wallet_db` function now checks + that the sqlite version in use is compatible with the features required by + the wallet and returns this error if not. SQLite version `3.35` or higher + is required for use with `zcash_client_sqlite`. + ## [0.11.1] - 2024-08-21 @@ -23,7 +29,7 @@ and this library adheres to Rust's notion of `zcash_client_sqlite` now provides capabilities for the management of ephemeral transparent addresses in support of the creation of ZIP 320 transaction pairs. -In addition, `zcash_client_sqlite` now provides improved tracking of transparent +In addition, `zcash_client_sqlite` now provides improved tracking of transparent wallet history in support of the API changes in `zcash_client_backend 0.13`, and the `v_transactions` view has been modified to provide additional metadata about the relationship of each transaction to the wallet, in particular whether @@ -70,11 +76,11 @@ or not the transaction represents a wallet-internal shielding operation. ## [0.10.1] - 2024-03-25 ### Fixed -- The `sent_notes` table's `received_note` constraint was excessively restrictive - after zcash/librustzcash#1306. Any databases that have migrations from +- The `sent_notes` table's `received_note` constraint was excessively restrictive + after zcash/librustzcash#1306. Any databases that have migrations from zcash_client_sqlite 0.10.0 applied should be wiped and restored from seed. In order to ensure that the incorrect migration is not used, the migration - id for the `full_account_ids` migration has been changed from + id for the `full_account_ids` migration has been changed from `0x1b104345_f27e_42da_a9e3_1de22694da43` to `0x6d02ec76_8720_4cc6_b646_c4e2ce69221c` ## [0.10.0] - 2024-03-25 diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 069a495b60..2010006245 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -71,6 +71,7 @@ schemer.workspace = true schemer-rusqlite.workspace = true time.workspace = true uuid.workspace = true +regex = "1.4" # Dependencies used internally: # (Breaking upgrades to these are usually backwards-compatible, but check MSRVs.) @@ -87,7 +88,6 @@ orchard = { workspace = true, features = ["test-dependencies"] } proptest.workspace = true rand_chacha.workspace = true rand_core.workspace = true -regex = "1.4" tempfile = "3.5.0" zcash_keys = { workspace = true, features = ["test-dependencies"] } zcash_note_encryption.workspace = true diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index 9b0994e2f6..b69c625e72 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -3,6 +3,7 @@ use std::fmt; use std::rc::Rc; +use regex::Regex; use schemer::{Migrator, MigratorError}; use schemer_rusqlite::RusqliteAdapter; use secrecy::SecretVec; @@ -20,8 +21,15 @@ use crate::{error::SqliteClientError, WalletDb}; mod migrations; +const SQLITE_MAJOR_VERSION: u32 = 3; +const MIN_SQLITE_MINOR_VERSION: u32 = 35; + #[derive(Debug)] pub enum WalletMigrationError { + /// A feature required by the wallet database is not supported by the version of + /// SQLite that the migration is running against. + DatabaseNotSupported(String), + /// The seed is required for the migration. SeedRequired, @@ -100,6 +108,13 @@ impl From for WalletMigrationError { impl fmt::Display for WalletMigrationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &self { + WalletMigrationError::DatabaseNotSupported(version) => { + write!( + f, + "The installed SQLite version {} does not support operations required by the wallet.", + version + ) + } WalletMigrationError::SeedRequired => { write!( f, @@ -305,6 +320,8 @@ fn init_wallet_db_internal( ) -> Result<(), MigratorError> { let seed = seed.map(Rc::new); + verify_sqlite_version_compatibility(&wdb.conn).map_err(MigratorError::Adapter)?; + // Turn off foreign key enforcement, to ensure that table replacement does not break foreign // key references in table definitions. // @@ -357,6 +374,40 @@ fn init_wallet_db_internal( Ok(()) } +/// Verify that the sqlite version in use supports the features required by this library. +/// Note that the version of sqlite available to the database backend may be different +/// from what is used to query the views that are part of the public API. +fn verify_sqlite_version_compatibility( + conn: &rusqlite::Connection, +) -> Result<(), WalletMigrationError> { + let sqlite_version = + conn.query_row("SELECT sqlite_version()", [], |row| row.get::<_, String>(0))?; + + let version_re = Regex::new(r"^(?[0-9]+)\.(?[0-9]+).+$").unwrap(); + let captures = + version_re + .captures(&sqlite_version) + .ok_or(WalletMigrationError::DatabaseNotSupported( + "Unknown".to_owned(), + ))?; + let parse_int = |value: &str| { + value.parse::().map_err(|_| { + WalletMigrationError::CorruptedData(format!( + "Cannot decode SQLite major version {}", + &captures["major"] + )) + }) + }; + let major = parse_int(&captures["major"])?; + let minor = parse_int(&captures["minor"])?; + + if major != SQLITE_MAJOR_VERSION || minor < MIN_SQLITE_MINOR_VERSION { + Err(WalletMigrationError::DatabaseNotSupported(sqlite_version)) + } else { + Ok(()) + } +} + #[cfg(test)] #[allow(deprecated)] mod tests { diff --git a/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs b/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs index 54bd7f1fb1..29385a30ef 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/support_legacy_sqlite.rs @@ -1,5 +1,4 @@ -//! A migration that removes the use of `FALSE` in sqlite view definitions. -//! This is necessary to support older +//! Modifies definitions to avoid keywords that may not be available in older SQLite versions. use std::collections::HashSet; use rusqlite; @@ -9,7 +8,7 @@ use uuid::Uuid; use crate::wallet::init::{migrations::tx_retrieval_queue, WalletMigrationError}; -pub(super) const MIGRATION_ID: Uuid = Uuid::from_u128(0xc9ed1fb5_b2c3_467f_89dc_2591dcca5562); +pub(super) const MIGRATION_ID: Uuid = Uuid::from_u128(0x156d8c8f_2173_4b59_89b6_75697d5a2103); const DEPENDENCIES: &[Uuid] = &[tx_retrieval_queue::MIGRATION_ID]; @@ -25,7 +24,7 @@ impl schemer::Migration for Migration { } fn description(&self) -> &'static str { - "Removes the FALSE keyword from the v_tx_outputs view definition" + "Modifies definitions to avoid keywords that may not be available in older SQLite versions." } } From 1b8334104dae260272e34b8f624612bcd3b1037e Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 3 Sep 2024 12:12:33 -0600 Subject: [PATCH 21/23] zcash_client_sqlite: Accept 2-part `major.minor` SQLite versions. --- zcash_client_sqlite/src/wallet/init.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index b69c625e72..ca6c4b52ef 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -383,23 +383,23 @@ fn verify_sqlite_version_compatibility( let sqlite_version = conn.query_row("SELECT sqlite_version()", [], |row| row.get::<_, String>(0))?; - let version_re = Regex::new(r"^(?[0-9]+)\.(?[0-9]+).+$").unwrap(); + let version_re = Regex::new(r"^(?[0-9]+)\.(?[0-9]+).*$").unwrap(); let captures = version_re .captures(&sqlite_version) .ok_or(WalletMigrationError::DatabaseNotSupported( "Unknown".to_owned(), ))?; - let parse_int = |value: &str| { - value.parse::().map_err(|_| { + let parse_version_part = |part: &str| { + captures[part].parse::().map_err(|_| { WalletMigrationError::CorruptedData(format!( - "Cannot decode SQLite major version {}", - &captures["major"] + "Cannot decode SQLite {} version component {}", + part, &captures[part] )) }) }; - let major = parse_int(&captures["major"])?; - let minor = parse_int(&captures["minor"])?; + let major = parse_version_part("major")?; + let minor = parse_version_part("minor")?; if major != SQLITE_MAJOR_VERSION || minor < MIN_SQLITE_MINOR_VERSION { Err(WalletMigrationError::DatabaseNotSupported(sqlite_version)) From 5e6a8f02508893bce0410c9e3a941ea151d1d92f Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 22 Aug 2024 12:09:33 -0600 Subject: [PATCH 22/23] Release zcash_client_sqlite version 0.11.2 --- Cargo.lock | 2 +- zcash_client_sqlite/CHANGELOG.md | 2 ++ zcash_client_sqlite/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4f3541b89..dc8cb7e205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5877,7 +5877,7 @@ dependencies = [ [[package]] name = "zcash_client_sqlite" -version = "0.11.1" +version = "0.11.2" dependencies = [ "assert_matches", "bip32", diff --git a/zcash_client_sqlite/CHANGELOG.md b/zcash_client_sqlite/CHANGELOG.md index 0878b3fd46..0b5e9865c8 100644 --- a/zcash_client_sqlite/CHANGELOG.md +++ b/zcash_client_sqlite/CHANGELOG.md @@ -7,6 +7,8 @@ and this library adheres to Rust's notion of ## [Unreleased] +## [0.11.2] - 2024-08-21 + ### Changed - The `v_tx_outputs` view was modified slightly to support older versions of `sqlite`. Queries to the exposed `v_tx_outputs` and `v_transactions` views diff --git a/zcash_client_sqlite/Cargo.toml b/zcash_client_sqlite/Cargo.toml index 2010006245..25f2288c51 100644 --- a/zcash_client_sqlite/Cargo.toml +++ b/zcash_client_sqlite/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcash_client_sqlite" description = "An SQLite-based Zcash light client" -version = "0.11.1" +version = "0.11.2" authors = [ "Jack Grigg ", "Kris Nuttycombe " From 01576f10aee25c97530458955df1989a54c9d34c Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 3 Sep 2024 12:26:56 -0600 Subject: [PATCH 23/23] Update audit metadata for zcash_client_sqlite 0.11.2 release. --- supply-chain/imports.lock | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 0145b6d3ba..c464e8c340 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -238,15 +238,8 @@ user-login = "nuttycom" user-name = "Kris Nuttycombe" [[publisher.zcash_client_sqlite]] -version = "0.11.0" -when = "2024-08-20" -user-id = 169181 -user-login = "nuttycom" -user-name = "Kris Nuttycombe" - -[[publisher.zcash_client_sqlite]] -version = "0.11.1" -when = "2024-08-21" +version = "0.11.2" +when = "2024-09-03" user-id = 169181 user-login = "nuttycom" user-name = "Kris Nuttycombe"