Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_backend: Make VKs optional for PCZT extraction #1729

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions zcash_client_backend/src/data_api/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,14 +1151,12 @@

let prover = LocalTxProver::bundled();
let (spend_vk, output_vk) = prover.verifying_keys();
let orchard_vk = ::orchard::circuit::VerifyingKey::build();

extract_and_store_transaction_from_pczt(
self.wallet_mut(),
pczt,
&spend_vk,
&output_vk,
&orchard_vk,
Some((&spend_vk, &output_vk)),
None,

Check warning on line 1159 in zcash_client_backend/src/data_api/testing.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api/testing.rs#L1158-L1159

Added lines #L1158 - L1159 were not covered by tests
)
}

Expand Down
28 changes: 21 additions & 7 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,13 +1681,23 @@
/// metadata necessary for the wallet backend.
///
/// Returns the transaction ID for the resulting transaction.
///
/// - `sapling_vk` is optional to allow the caller to check whether a PCZT has Sapling
/// with [`pczt::roles::prover::Prover::requires_sapling_proofs`], and avoid downloading
/// the Sapling parameters if they are not needed. If `sapling_vk` is `None`, and the
/// PCZT has a Sapling bundle, this function will return an error.
/// - `orchard_vk` is optional to allow the caller to control where the Orchard verifying
/// key is generated or cached. If `orchard_vk` is `None`, and the PCZT has an Orchard
/// bundle, an Orchard verifying key will be generated on the fly.
#[cfg(feature = "pczt")]
pub fn extract_and_store_transaction_from_pczt<DbT, N>(
wallet_db: &mut DbT,
pczt: pczt::Pczt,
spend_vk: &sapling::circuit::SpendVerifyingKey,
output_vk: &sapling::circuit::OutputVerifyingKey,
#[cfg(feature = "orchard")] orchard_vk: &orchard::circuit::VerifyingKey,
sapling_vk: Option<(
&sapling::circuit::SpendVerifyingKey,
&sapling::circuit::OutputVerifyingKey,
)>,
#[cfg(feature = "orchard")] orchard_vk: Option<&orchard::circuit::VerifyingKey>,
Copy link
Contributor Author

@str4d str4d Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change not documented in changelog so that this PR doesn't conflict with #1673. This can happen in the release PR (or if the other PR merges before this one, after a rebase).

) -> Result<TxId, ExtractErrT<DbT, N>>
where
DbT: WalletWrite + WalletCommitmentTrees,
Expand Down Expand Up @@ -1853,10 +1863,14 @@
})
.collect::<Result<BTreeMap<_, _>, _>>()?;

let transaction = TransactionExtractor::new(finalized)
.with_sapling(spend_vk, output_vk)
.with_orchard(orchard_vk)
.extract()?;
let mut tx_extractor = TransactionExtractor::new(finalized);
if let Some((spend_vk, output_vk)) = sapling_vk {
tx_extractor = tx_extractor.with_sapling(spend_vk, output_vk);

Check warning on line 1868 in zcash_client_backend/src/data_api/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api/wallet.rs#L1866-L1868

Added lines #L1866 - L1868 were not covered by tests
}
if let Some(orchard_vk) = orchard_vk {
tx_extractor = tx_extractor.with_orchard(orchard_vk);

Check warning on line 1871 in zcash_client_backend/src/data_api/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api/wallet.rs#L1870-L1871

Added lines #L1870 - L1871 were not covered by tests
}
let transaction = tx_extractor.extract()?;

Check warning on line 1873 in zcash_client_backend/src/data_api/wallet.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api/wallet.rs#L1873

Added line #L1873 was not covered by tests
let txid = transaction.txid();

#[allow(clippy::too_many_arguments)]
Expand Down
Loading