Skip to content
Open
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
28 changes: 14 additions & 14 deletions Cargo.lock

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

28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "syn
## rc crates (pczt, client_backend, zip321, sqlite) keep the explicit -rc.1 so the pre-release matches.
zcash_keys = { version = "0.15.0", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { version = "0.24.0-rc.1", default-features = false, features = ["sync", "lightwalletd-tonic", "orchard"] }
zcash_client_memory = { git = "https://github.com/red-dev-inc/zcash_client_memory", branch = "feat/snap-nu63", features = ["orchard", "transparent-inputs"] }
# sqhell fork of red-dev-inc "feat/snap-nu63" with the eager block-cache delete, nullifier-map pruning
# and Ironwood (NU6.3) pool support. Switch back to red-dev-inc once those land there.
zcash_client_memory = { git = "https://github.com/sqhell/zcash_client_memory", rev = "e15c962dd84f59b27c06f41a52d89366846dc7be", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { version = "0.29.0" }
zcash_transparent = { version = "0.9.0", default-features = false }
zcash_address = { version = "0.13.0" }
Expand Down Expand Up @@ -95,18 +97,18 @@ byte-unit = { version = "5.1.4", features = ["byte"] }
# while librustzcash pulls the git rev -> two `orchard` versions -> trait mismatch. Drop once it lands
# in an orchard release.
orchard = { git = "https://github.com/zcash/orchard.git", rev = "3bd2b736d1273226595773265313fc3f3428af16" }
equihash = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_encoding = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_keys = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_protocol = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zip321 = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
pczt = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_transparent = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
equihash = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_address = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_client_backend = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_client_sqlite = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_encoding = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_keys = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_protocol = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zip321 = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_primitives = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_proofs = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
pczt = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }
zcash_transparent = { git = "https://github.com/sqhell/librustzcash", rev = "b7b65fe3310eb4c8420469c48303c07ded6a74d5" }

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen)', 'cfg(wasm_bindgen_unstable_test_coverage)'] }
34 changes: 26 additions & 8 deletions crates/webzjs-keys/src/demo_pczt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ use orchard::value::NoteValue as OrchardNoteValue;
use orchard::Address as OrchardAddress;

use pczt::roles::creator::Creator;
use webzjs_common::Network;
use zcash_keys::address::UnifiedAddress;
use zcash_keys::encoding::AddressCodec;
use zcash_keys::keys::{UnifiedFullViewingKey as InnerUfvk, UnifiedSpendingKey};
use zcash_primitives::transaction::builder::PcztParts;
use zcash_primitives::transaction::TxVersion;
use zcash_protocol::consensus::{BlockHeight, BranchId, NetworkConstants, Parameters};
use zcash_protocol::value::Zatoshis;
use webzjs_common::Network;

use zcash_transparent::address::TransparentAddress;
use zcash_transparent::bundle::{OutPoint, TxOut};
use zcash_transparent::builder::TransparentBuilder;
use zcash_transparent::bundle::{OutPoint, TxOut};
use zcash_transparent::keys::{NonHardenedChildIndex, TransparentKeyScope};
use zcash_transparent::pczt::Bip32Derivation;

Expand Down Expand Up @@ -155,7 +155,10 @@ fn build_transparent(
.map_err(|e| Error::PcztDescribe(format!("derive t-pubkey: {e:?}")))?;
let taddr = TransparentAddress::from_pubkey(&pk);

let coin = TxOut::new(Zatoshis::from_u64(SPEND_VALUE).unwrap(), taddr.script().into());
let coin = TxOut::new(
Zatoshis::from_u64(SPEND_VALUE).unwrap(),
taddr.script().into(),
);
let mut builder = TransparentBuilder::empty();
builder
.add_p2pkh_input(pk, OutPoint::new([0u8; 32], 0), coin)
Expand Down Expand Up @@ -310,7 +313,11 @@ fn build_orchard(
.clone();
let mut rng = StdRng::seed_from_u64(0x0_C_5A_u64);

let note = make_orchard_note(&mut rng, fvk.address_at(0u32, OrchardScope::External), SPEND_VALUE);
let note = make_orchard_note(
&mut rng,
fvk.address_at(0u32, OrchardScope::External),
SPEND_VALUE,
);
let cmx: ExtractedNoteCommitment = note.commitment().into();
let sibling = MerkleHashOrchard::from_cmx(&cmx);
let path = OrchardMerklePath::from_parts(0, [sibling; 32]);
Expand Down Expand Up @@ -347,7 +354,9 @@ fn build_orchard(
fn make_orchard_note(rng: &mut StdRng, recipient: OrchardAddress, value: u64) -> OrchardNote {
let mut rho_bytes = [0u8; 32];
rho_bytes[0] = 7;
let rho = Rho::from_bytes(&rho_bytes).into_option().expect("valid rho");
let rho = Rho::from_bytes(&rho_bytes)
.into_option()
.expect("valid rho");
loop {
let mut rseed_bytes = [0u8; 32];
rng.fill_bytes(&mut rseed_bytes);
Expand Down Expand Up @@ -388,9 +397,18 @@ mod tests {
let attacker = ufvk_from_seed(&net, ATTACKER_SEED).unwrap();

for (pool, demo) in [
("transparent", transparent_demo(&net, &me, &bridge, &attacker).unwrap()),
("sapling", sapling_demo(&net, &me, &bridge, &attacker).unwrap()),
("orchard", orchard_demo(&net, &me, &bridge, &attacker).unwrap()),
(
"transparent",
transparent_demo(&net, &me, &bridge, &attacker).unwrap(),
),
(
"sapling",
sapling_demo(&net, &me, &bridge, &attacker).unwrap(),
),
(
"orchard",
orchard_demo(&net, &me, &bridge, &attacker).unwrap(),
),
] {
let honest = hex_to_pczt(&demo.honest);
let spoof = hex_to_pczt(&demo.spoof);
Expand Down
8 changes: 4 additions & 4 deletions crates/webzjs-keys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

#[cfg(feature = "demo-builder")]
mod demo_pczt;
mod error;
mod keys;
mod pczt_describe;
mod pczt_sign;
#[cfg(feature = "demo-builder")]
mod demo_pczt;

#[cfg(feature = "demo-builder")]
pub use demo_pczt::*;
pub use error::*;
pub use keys::*;
pub use pczt_describe::*;
pub use pczt_sign::*;
#[cfg(feature = "demo-builder")]
pub use demo_pczt::*;
21 changes: 15 additions & 6 deletions crates/webzjs-keys/src/pczt_describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ fn transparent_addr_is_ours(
};
bip32_derivation.iter().any(|(claimed_pk, deriv)| {
match tfvk.derive_pubkey_at_bip32_path(network, account, deriv.derivation_path()) {
Ok(pk) => &pk.serialize() == claimed_pk && TransparentAddress::from_pubkey(&pk) == *addr,
Ok(pk) => {
&pk.serialize() == claimed_pk && TransparentAddress::from_pubkey(&pk) == *addr
}
Err(_) => false,
}
})
Expand All @@ -378,8 +380,10 @@ fn transparent_addr_is_ours(
/// invariants (spends are ours, value balances / turnstile identity holds, every
/// output is commitment-bound, fee is sane) for migrations as for any PCZT.
fn detect_migration(outputs: &[PcztOutputSummary]) -> Option<MigrationSummary> {
let ironwood: Vec<&PcztOutputSummary> =
outputs.iter().filter(|o| o.pool == pool::IRONWOOD).collect();
let ironwood: Vec<&PcztOutputSummary> = outputs
.iter()
.filter(|o| o.pool == pool::IRONWOOD)
.collect();
if ironwood.is_empty() {
return None;
}
Expand Down Expand Up @@ -499,7 +503,8 @@ fn analyze(
}

for output in bundle.outputs() {
if let Err(sapling::pczt::VerifyError::InvalidValueCommitment) = output.verify_cv() {
if let Err(sapling::pczt::VerifyError::InvalidValueCommitment) = output.verify_cv()
{
cv_mismatch = true;
}
match output.value().map(|v| v.inner()) {
Expand Down Expand Up @@ -562,7 +567,9 @@ fn analyze(
let value = u64::from(*input.value());
total_in += value;
let ours = TransparentAddress::from_script_from_chain(input.script_pubkey())
.map(|addr| transparent_addr_is_ours(&network, tfvk, &addr, input.bip32_derivation()))
.map(|addr| {
transparent_addr_is_ours(&network, tfvk, &addr, input.bip32_derivation())
})
.unwrap_or(false);
if !ours {
foreign_input = true;
Expand All @@ -577,7 +584,9 @@ fn analyze(
let recipient = addr.map(|addr| addr.encode(&network));
// Change = the coin pays back to one of our own transparent keys.
let is_change = addr
.map(|addr| transparent_addr_is_ours(&network, tfvk, &addr, output.bip32_derivation()))
.map(|addr| {
transparent_addr_is_ours(&network, tfvk, &addr, output.bip32_derivation())
})
.unwrap_or(false);
total_out += value;
outputs.push(PcztOutputSummary {
Expand Down
Loading
Loading