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

upgrade rust version to exactly 1.77.0 in Cargo.toml and rust-toolcha… #27

Open
wants to merge 30 commits into
base: main_zingolib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
479098f
removed meta push in create_proposed_transaction
fluidvanadium Apr 7, 2024
4ef584f
change sent to external address
fluidvanadium Apr 7, 2024
c1442fb
removed meta push in create_proposed_transaction
fluidvanadium Apr 7, 2024
b1e70fd
enable build_server
fluidvanadium Apr 7, 2024
bcbae0b
removed store functionality in create_proposed_transaction
fluidvanadium Apr 19, 2024
c9141bd
doc-comment and rename new function
fluidvanadium Apr 19, 2024
1aa9455
Merge pull request #10 from fluidvanadium/avoid_wallet_write
zancas Apr 25, 2024
d876a1c
pub scoped caluculate_proposed_trnsaction
fluidvanadium Apr 29, 2024
4c67b47
Merge pull request #11 from fluidvanadium/pub_calculate
fluidvanadium Apr 29, 2024
84469ad
impl std::fmt::Display for NoteId
fluidvanadium May 1, 2024
239c894
add extra method for non-traditional tkey derevation
AloeareV May 15, 2024
471a062
create 0-value change
fluidvanadium May 30, 2024
c2962db
update changelog
fluidvanadium Jun 17, 2024
b2c17c5
Merge pull request #12 from fluidvanadium/add_changelog
fluidvanadium Jun 17, 2024
527256a
allow override_sapling_change_address so zingo doesnt have to scan so…
fluidvanadium Jun 17, 2024
50ffcd4
no funky extra change output
fluidvanadium Jun 26, 2024
7b12909
Revert "no funky extra change output"
zancas Jun 26, 2024
3ab3029
move the 0-value change case into the dust case
zancas Jun 29, 2024
ae0d477
Merge pull request #18 from zancas/always_require_change_for_memo
zancas Jun 29, 2024
18b4891
update secp256k1 to 0.27
fluidvanadium Sep 8, 2024
028ac12
custom hdwallet version
fluidvanadium Sep 8, 2024
7556383
Cargo.lock
fluidvanadium Sep 8, 2024
401cab5
use tag instead of branch
fluidvanadium Sep 9, 2024
a4c0082
Cargo.lock update
fluidvanadium Sep 9, 2024
cd80ea6
upgraded orchard
fluidvanadium Sep 9, 2024
4e8b208
upgraded bip0039 dependency
fluidvanadium Sep 9, 2024
abffa16
upgraded incrementalmerkletree
fluidvanadium Sep 9, 2024
d6c9357
update sapling_crypt and shardtree
fluidvanadium Sep 9, 2024
be68927
upgrade prost and tonic and rust
fluidvanadium Sep 9, 2024
2bde501
upgrade rust version to exactly 1.77.0 in Cargo.toml and rust-toolcha…
fluidvanadium Sep 11, 2024
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
209 changes: 137 additions & 72 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [

[workspace.package]
edition = "2021"
rust-version = "1.65"
rust-version = "1.77.0"
repository = "https://github.com/zcash/librustzcash"
license = "MIT OR Apache-2.0"
categories = ["cryptography::cryptocurrencies"]
Expand All @@ -42,8 +42,8 @@ zcash_proofs = { version = "0.15", path = "zcash_proofs", default-features = fal
# Shielded protocols
ff = "0.13"
group = "0.13"
incrementalmerkletree = "0.5.1"
shardtree = "0.3"
incrementalmerkletree = "0.6.0"
shardtree = "0.4"
zcash_spec = "0.1"

# Payment protocols
Expand All @@ -52,17 +52,17 @@ bitvec = "1"
blake2s_simd = "1"
bls12_381 = "0.8"
jubjub = "0.10"
sapling = { package = "sapling-crypto", version = "0.1.3" }
sapling = { package = "sapling-crypto", version = "0.2" }

# - Orchard
nonempty = "0.7"
orchard = { version = "0.8.0", default-features = false }
orchard = { version = "0.9", default-features = false }
pasta_curves = "0.5"

# - Transparent
hdwallet = "0.4"
hdwallet = { git = "https://github.com/fluidvanadium/hdwallet.git", tag = "update_secp256k1_to_0.27.0" }
ripemd = "0.1"
secp256k1 = "0.26"
secp256k1 = "0.27"

# CSPRNG
rand = "0.8"
Expand Down Expand Up @@ -93,13 +93,13 @@ maybe-rayon = { version = "0.1.0", default-features = false }
rayon = "1.5"

# Protobuf and gRPC
prost = "0.12"
tonic = { version = "0.10", default-features = false }
tonic-build = { version = "0.10", default-features = false }
prost = "0.13"
tonic = { version = "0.12", default-features = false }
tonic-build = { version = "0.12", default-features = false }

# Secret management
secrecy = "0.8"
subtle = "2.2.3"
subtle = "2.4.1"

# Static constants
lazy_static = "1"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.65.0"
channel = "1.77.0"
components = [ "clippy", "rustfmt" ]
8 changes: 7 additions & 1 deletion zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Zingo]
- replace create_proposed_transaction with `calculate_proposed_transaction`
- dont try to write the calculated transaction to wallet, that will be handled later
- ignore collecting any transaction metadata
- handle usk differently
- modify change algorithm
- added display for NoteId

## [0.12.1] - 2024-03-27

Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn build() -> io::Result<()> {

// Build the gRPC types and client.
tonic_build::configure()
.build_server(false)
.build_server(true)
.client_mod_attribute(
"cash.z.wallet.sdk.rpc",
r#"#[cfg(feature = "lightwalletd-tonic")]"#,
Expand Down
173 changes: 24 additions & 149 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::{
fees::{self, DustOutputPolicy},
keys::UnifiedSpendingKey,
proposal::{self, Proposal, ProposalError},
wallet::{Note, OvkPolicy, Recipient},
wallet::{Note, OvkPolicy, Recipient, TransparentAddressMetadata},
zip321::{self, Payment},
PoolType, ShieldedProtocol,
};
Expand Down Expand Up @@ -605,9 +605,10 @@ where
ParamsT: consensus::Parameters + Clone,
FeeRuleT: FeeRule,
{
unimplemented!();
let mut step_results = Vec::with_capacity(proposal.steps().len());
for step in proposal.steps() {
let step_result = create_proposed_transaction(
let step_result = calculate_proposed_transaction(
wallet_db,
params,
spend_prover,
Expand All @@ -618,6 +619,8 @@ where
proposal.min_target_height(),
&step_results,
step,
None,
None,
)?;
step_results.push((step, step_result));
}
Expand All @@ -631,9 +634,10 @@ where
.expect("proposal.steps is NonEmpty"))
}

/// Zingo uses calculate_proposed_transaction to create the transaction, and then stores it ASYNCRONOUSLY
#[allow(clippy::too_many_arguments)]
#[allow(clippy::type_complexity)]
fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
pub fn calculate_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
wallet_db: &mut DbT,
params: &ParamsT,
spend_prover: &impl SpendProver,
Expand All @@ -644,6 +648,10 @@ fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
min_target_height: BlockHeight,
prior_step_results: &[(&proposal::Step<N>, BuildResult)],
proposal_step: &proposal::Step<N>,
usk_to_tkey: Option<
fn(&UnifiedSpendingKey, &TransparentAddressMetadata) -> hdwallet::secp256k1::SecretKey,
>,
override_sapling_change_address: Option<sapling::PaymentAddress>,
) -> Result<
BuildResult,
Error<
Expand All @@ -654,7 +662,7 @@ fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
>,
>
where
DbT: WalletWrite + WalletCommitmentTrees,
DbT: WalletRead + WalletCommitmentTrees,
ParamsT: consensus::Parameters + Clone,
FeeRuleT: FeeRule,
{
Expand Down Expand Up @@ -822,10 +830,16 @@ where
.clone()
.ok_or_else(|| Error::NoSpendingKey(addr.encode(params)))?;

let secret_key = usk
.transparent()
.derive_secret_key(address_metadata.scope(), address_metadata.address_index())
.unwrap();
let secret_key = usk_to_tkey
.map(|f| f(usk, &address_metadata))
.unwrap_or_else(|| {
usk.transparent()
.derive_secret_key(
address_metadata.scope(),
address_metadata.address_index(),
)
.unwrap()
});

utxos_spent.push(outpoint.clone());
builder.add_transparent_input(secret_key, outpoint, utxo)?;
Expand Down Expand Up @@ -935,10 +949,6 @@ where
Some(sapling_dfvk.to_ovk(Scope::Internal))
};

#[cfg(feature = "orchard")]
let mut orchard_output_meta = vec![];
let mut sapling_output_meta = vec![];
let mut transparent_output_meta = vec![];
for (payment, output_pool) in proposal_step
.payment_pools()
.iter()
Expand Down Expand Up @@ -973,14 +983,6 @@ where
payment.amount.into(),
memo.clone(),
)?;
orchard_output_meta.push((
Recipient::Unified(
ua.clone(),
PoolType::Shielded(ShieldedProtocol::Orchard),
),
payment.amount,
Some(memo),
));
}

PoolType::Shielded(ShieldedProtocol::Sapling) => {
Expand All @@ -990,14 +992,6 @@ where
payment.amount,
memo.clone(),
)?;
sapling_output_meta.push((
Recipient::Unified(
ua.clone(),
PoolType::Shielded(ShieldedProtocol::Sapling),
),
payment.amount,
Some(memo),
));
}

PoolType::Transparent => {
Expand All @@ -1023,15 +1017,13 @@ where
payment.amount,
memo.clone(),
)?;
sapling_output_meta.push((Recipient::Sapling(*addr), payment.amount, Some(memo)));
}
Address::Transparent(to) => {
if payment.memo.is_some() {
return Err(Error::MemoForbidden);
} else {
builder.add_transparent_output(to, payment.amount)?;
}
transparent_output_meta.push((to, payment.amount));
}
}
}
Expand All @@ -1044,19 +1036,10 @@ where
ShieldedProtocol::Sapling => {
builder.add_sapling_output(
sapling_internal_ovk(),
sapling_dfvk.change_address().1,
override_sapling_change_address.unwrap_or(sapling_dfvk.change_address().1),
change_value.value(),
memo.clone(),
)?;
sapling_output_meta.push((
Recipient::InternalAccount {
receiving_account: account,
external_address: None,
note: PoolType::Shielded(ShieldedProtocol::Sapling),
},
change_value.value(),
Some(memo),
))
}
ShieldedProtocol::Orchard => {
#[cfg(not(feature = "orchard"))]
Expand All @@ -1068,19 +1051,10 @@ where
{
builder.add_orchard_output(
orchard_internal_ovk(),
orchard_fvk.address_at(0u32, orchard::keys::Scope::Internal),
orchard_fvk.address_at(0u32, orchard::keys::Scope::External),
change_value.value().into(),
memo.clone(),
)?;
orchard_output_meta.push((
Recipient::InternalAccount {
receiving_account: account,
external_address: None,
note: PoolType::Shielded(ShieldedProtocol::Orchard),
},
change_value.value(),
Some(memo),
))
}
}
}
Expand All @@ -1089,105 +1063,6 @@ where
// Build the transaction with the specified fee rule
let build_result = builder.build(OsRng, spend_prover, output_prover, fee_rule)?;

#[cfg(feature = "orchard")]
let orchard_internal_ivk = orchard_fvk.to_ivk(orchard::keys::Scope::Internal);
#[cfg(feature = "orchard")]
let orchard_outputs =
orchard_output_meta
.into_iter()
.enumerate()
.map(|(i, (recipient, value, memo))| {
let output_index = build_result
.orchard_meta()
.output_action_index(i)
.expect("An action should exist in the transaction for each Orchard output.");

let recipient = recipient
.map_internal_account_note(|pool| {
assert!(pool == PoolType::Shielded(ShieldedProtocol::Orchard));
build_result
.transaction()
.orchard_bundle()
.and_then(|bundle| {
bundle
.decrypt_output_with_key(output_index, &orchard_internal_ivk)
.map(|(note, _, _)| Note::Orchard(note))
})
})
.internal_account_note_transpose_option()
.expect("Wallet-internal outputs must be decryptable with the wallet's IVK");

SentTransactionOutput::from_parts(output_index, recipient, value, memo)
});

let sapling_internal_ivk =
PreparedIncomingViewingKey::new(&sapling_dfvk.to_ivk(Scope::Internal));
let sapling_outputs =
sapling_output_meta
.into_iter()
.enumerate()
.map(|(i, (recipient, value, memo))| {
let output_index = build_result
.sapling_meta()
.output_index(i)
.expect("An output should exist in the transaction for each Sapling payment.");

let recipient = recipient
.map_internal_account_note(|pool| {
assert!(pool == PoolType::Shielded(ShieldedProtocol::Sapling));
build_result
.transaction()
.sapling_bundle()
.and_then(|bundle| {
try_sapling_note_decryption(
&sapling_internal_ivk,
&bundle.shielded_outputs()[output_index],
zip212_enforcement(params, min_target_height),
)
.map(|(note, _, _)| Note::Sapling(note))
})
})
.internal_account_note_transpose_option()
.expect("Wallet-internal outputs must be decryptable with the wallet's IVK");

SentTransactionOutput::from_parts(output_index, recipient, value, memo)
});

let transparent_outputs = transparent_output_meta.into_iter().map(|(addr, value)| {
let script = addr.script();
let output_index = build_result
.transaction()
.transparent_bundle()
.and_then(|b| {
b.vout
.iter()
.enumerate()
.find(|(_, tx_out)| tx_out.script_pubkey == script)
})
.map(|(index, _)| index)
.expect("An output should exist in the transaction for each transparent payment.");

SentTransactionOutput::from_parts(output_index, Recipient::Transparent(*addr), value, None)
});

let mut outputs = vec![];
#[cfg(feature = "orchard")]
outputs.extend(orchard_outputs);
outputs.extend(sapling_outputs);
outputs.extend(transparent_outputs);

wallet_db
.store_sent_tx(&SentTransaction {
tx: build_result.transaction(),
created: time::OffsetDateTime::now_utc(),
account,
outputs,
fee_amount: proposal_step.balance().fee_required(),
#[cfg(feature = "transparent-inputs")]
utxos_spent,
})
.map_err(Error::DataSource)?;

Ok(build_result)
}

Expand Down
Loading
Loading