diff --git a/Cargo.lock b/Cargo.lock index 37616ff3d..7432609e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,8 +1260,6 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "orchard" version = "0.1.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b48e6e124c3f7e9ed7f48b29f66069288235cecd16aa6053e98f8aff16efe827" dependencies = [ "aes", "arrayvec 0.7.2", diff --git a/Cargo.toml b/Cargo.toml index afe54f261..8fd81ffaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,6 +87,7 @@ codegen-units = 1 [patch.crates-io] hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" } +orchard = { path = "../orchard/" } zcash_address = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" } zcash_encoding = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" } zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" } diff --git a/src/rust/include/rust/builder.h b/src/rust/include/rust/builder.h index a95e5ddfb..f0d0212a8 100644 --- a/src/rust/include/rust/builder.h +++ b/src/rust/include/rust/builder.h @@ -42,6 +42,10 @@ OrchardBuilderPtr* orchard_builder_new( /// Frees an Orchard builder returned from `orchard_builder_new`. void orchard_builder_free(OrchardBuilderPtr* ptr); +bool orchard_builder_duplicate_nullifier_spend( + OrchardBuilderPtr* ptr +); + /// Adds a note to be spent in this bundle. /// /// Returns `false` if the Merkle path in `spend_info` does not have the diff --git a/src/rust/src/builder_ffi.rs b/src/rust/src/builder_ffi.rs index 5e3c4ab12..d4fd7f4a3 100644 --- a/src/rust/src/builder_ffi.rs +++ b/src/rust/src/builder_ffi.rs @@ -66,6 +66,17 @@ pub extern "C" fn orchard_builder_new( ))) } +#[no_mangle] +pub extern "C" fn orchard_builder_duplicate_nullifier_spend( + builder: *mut Builder +) -> bool { + let builder = unsafe { builder.as_mut() }.expect("Builder may not be null."); + + builder.add_duplicate_nullifier_spend(OsRng); + + true +} + #[no_mangle] pub extern "C" fn orchard_builder_add_spend( builder: *mut Builder, diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 2d434b9ea..fea0ddc4b 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -42,6 +42,16 @@ Builder::Builder( inner.reset(orchard_builder_new(spendsEnabled, outputsEnabled, anchor.IsNull() ? nullptr : anchor.begin())); } +void Builder::AddBogusSpends() +{ + if (!inner) { + throw std::logic_error("orchard::Builder has already been used"); + } + + orchard_builder_duplicate_nullifier_spend(inner.get()); + hasActions = true; +} + bool Builder::AddSpend(orchard::SpendInfo spendInfo) { if (!inner) { @@ -292,6 +302,15 @@ bool TransactionBuilder::SupportsOrchard() const { return orchardBuilder.has_value(); } +void TransactionBuilder::AddBogusOrchardSpends() +{ + if (!orchardBuilder.has_value()) { + throw std::runtime_error("TransactionBuilder orchardBuilder not setup"); + } + + orchardBuilder.value().AddBogusSpends(); +} + bool TransactionBuilder::AddOrchardSpend( libzcash::OrchardSpendingKey sk, orchard::SpendInfo spendInfo) diff --git a/src/transaction_builder.h b/src/transaction_builder.h index 4df41ba55..cbfa4cc2a 100644 --- a/src/transaction_builder.h +++ b/src/transaction_builder.h @@ -101,6 +101,8 @@ public: return *this; } + void AddBogusSpends(); + /// Adds a note to be spent in this bundle. /// /// Returns `false` if the given Merkle path does not have the required anchor @@ -337,6 +339,8 @@ public: bool SupportsOrchard() const; + void AddBogusOrchardSpends(); + bool AddOrchardSpend( libzcash::OrchardSpendingKey sk, orchard::SpendInfo spendInfo);