Skip to content

Commit

Permalink
Update librustzcash for orchard crate refactoring changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmidem committed Jul 15, 2024
1 parent e49ee6a commit 3f934b7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
24 changes: 18 additions & 6 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sapling = { package = "sapling-crypto", version = "0.1.3" }

# - Orchard
nonempty = "0.7"
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "orchardzsa-backward-compatability-0.8.0-ak" }
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "orchardzsa-backward-compatability-0.8.0" }
pasta_curves = "0.5"

# - Transparent
Expand Down Expand Up @@ -125,4 +125,4 @@ codegen-units = 1

[patch.crates-io]
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "fix-sapling-constants" }
sapling = { package = "sapling-crypto", version = "0.1.3", git = "https://github.com/QED-it/sapling-crypto", branch = "orchard-backward-compatibility" }
sapling = { package = "sapling-crypto", version = "0.1.3", git = "https://github.com/QED-it/sapling-crypto", branch = "orchard-backward-compatibility" }
4 changes: 2 additions & 2 deletions zcash_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ use crate::{
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */
use crate::transaction::builder::Error::{IssuanceBuilder, IssuanceBundle};
use orchard::note::AssetBase;
use orchard::orchard_flavors::OrchardVanilla;
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */ use orchard::orchard_flavors::OrchardZSA;
use orchard::orchard_flavor::OrchardVanilla;
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */ use orchard::orchard_flavor::OrchardZSA;
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */
use orchard::{
issuance::{IssueBundle, IssueInfo},
Expand Down
22 changes: 11 additions & 11 deletions zcash_primitives/src/transaction/components/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::transaction::components::issuance::read_asset;
use byteorder::{ReadBytesExt, WriteBytesExt};
use nonempty::NonEmpty;
use orchard::note::AssetBase;
use orchard::note_encryption::OrchardDomain;
use orchard::orchard_flavors::{OrchardVanilla, OrchardZSA};
use orchard::note_encryption::OrchardDomainCommon;
use orchard::orchard_flavor::{OrchardVanilla, OrchardZSA};
use orchard::{
bundle::{Authorization, Authorized, Flags},
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext},
primitives::redpallas::{self, SigType, Signature, SpendAuth, VerificationKey},
value::ValueCommitment,
value::{NoteValue, ValueCommitment},
Action, Anchor,
};
use zcash_encoding::{Array, CompactSize, Vector};
Expand Down Expand Up @@ -125,8 +125,8 @@ pub fn read_v6_bundle<R: Read>(
}
}

fn read_burn<R: Read>(reader: &mut R) -> io::Result<(AssetBase, Amount)> {
Ok((read_asset(reader)?, Transaction::read_amount(reader)?))
fn read_burn<R: Read>(reader: &mut R) -> io::Result<(AssetBase, NoteValue)> {
Ok((read_asset(reader)?, Transaction::read_note_value(reader)?))
}

pub fn read_value_commitment<R: Read>(mut reader: R) -> io::Result<ValueCommitment> {
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn read_note_ciphertext<R: Read>(
) -> io::Result<TransmittedNoteCiphertext<OrchardVanilla>> {
let mut tnc = TransmittedNoteCiphertext::<OrchardVanilla> {
epk_bytes: [0u8; 32],
enc_ciphertext: <OrchardVanilla as OrchardDomain>::NoteCiphertextBytes::from(
enc_ciphertext: <OrchardVanilla as OrchardDomainCommon>::NoteCiphertextBytes::from(
[0u8; OrchardVanilla::ENC_CIPHERTEXT_SIZE].as_ref(),
),
out_ciphertext: [0u8; 80],
Expand All @@ -204,7 +204,7 @@ pub fn read_zsa_note_ciphertext<R: Read>(
) -> io::Result<TransmittedNoteCiphertext<OrchardZSA>> {
let mut tnc = TransmittedNoteCiphertext::<OrchardZSA> {
epk_bytes: [0u8; 32],
enc_ciphertext: <OrchardZSA as OrchardDomain>::NoteCiphertextBytes::from(
enc_ciphertext: <OrchardZSA as OrchardDomainCommon>::NoteCiphertextBytes::from(
[0u8; OrchardZSA::ENC_CIPHERTEXT_SIZE].as_ref(),
),
out_ciphertext: [0u8; 80],
Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn write_v6_bundle<W: Write>(

Vector::write(&mut writer, bundle.burn(), |w, (asset, amount)| {
w.write_all(&asset.to_bytes())?;
w.write_all(&amount.to_i64_le_bytes())?;
w.write_all(&amount.to_bytes())?;
Ok(())
})?;

Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn write_cmx<W: Write>(mut writer: W, cmx: &ExtractedNoteCommitment) -> io::
writer.write_all(&cmx.to_bytes())
}

pub fn write_note_ciphertext<W: Write, D: OrchardDomain>(
pub fn write_note_ciphertext<W: Write, D: OrchardDomainCommon>(
mut writer: W,
nc: &TransmittedNoteCiphertext<D>,
) -> io::Result<()> {
Expand All @@ -380,7 +380,7 @@ pub fn write_note_ciphertext<W: Write, D: OrchardDomain>(
writer.write_all(&nc.out_ciphertext)
}

pub fn write_action_without_auth<W: Write, D: OrchardDomain>(
pub fn write_action_without_auth<W: Write, D: OrchardDomainCommon>(
mut writer: W,
act: &Action<<Authorized as Authorization>::SpendAuth, D>,
) -> io::Result<()> {
Expand All @@ -403,7 +403,7 @@ pub mod testing {
testing::{self as t_orch},
Authorized, Bundle,
};
use orchard::orchard_flavors::{OrchardVanilla, OrchardZSA};
use orchard::orchard_flavor::{OrchardVanilla, OrchardZSA};

prop_compose! {
pub fn arb_bundle(n_actions: usize)(
Expand Down
11 changes: 8 additions & 3 deletions zcash_primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ mod tests;
use blake2b_simd::Hash as Blake2bHash;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use memuse::DynamicUsage;
use orchard::builder::Unproven;
use orchard::orchard_flavors::OrchardVanilla;
use orchard::{builder::Unproven, orchard_flavor::OrchardVanilla, value::NoteValue};
use std::convert::TryFrom;
use std::fmt;
use std::fmt::Debug;
Expand All @@ -31,7 +30,7 @@ use crate::{

#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */ use crate::transaction::components::issuance;
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */
use orchard::{issuance::IssueBundle, orchard_flavors::OrchardZSA};
use orchard::{issuance::IssueBundle, orchard_flavor::OrchardZSA};

use self::{
components::{
Expand Down Expand Up @@ -864,6 +863,12 @@ impl Transaction {
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "valueBalance out of range"))
}

fn read_note_value<R: Read>(mut reader: R) -> io::Result<NoteValue> {
let mut tmp = [0; 8];
reader.read_exact(&mut tmp)?;
Ok(NoteValue::from_bytes(tmp))
}

fn read_v5<R: Read>(mut reader: R, version: TxVersion) -> io::Result<Self> {
let (consensus_branch_id, lock_time, expiry_height) =
Self::read_v5_header_fragment(&mut reader)?;
Expand Down
4 changes: 2 additions & 2 deletions zcash_primitives/src/transaction/txid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use blake2b_simd::{Hash as Blake2bHash, Params, State};
use byteorder::{LittleEndian, WriteBytesExt};
use ff::PrimeField;
use orchard::bundle;
use orchard::orchard_flavors::OrchardVanilla;
use orchard::orchard_flavor::OrchardVanilla;
#[cfg(zcash_unstable = "nu6")] /* TODO nu7 */
use orchard::{
issuance::{IssueBundle, Signed},
orchard_flavors::OrchardZSA,
orchard_flavor::OrchardZSA,
};

use crate::{
Expand Down

0 comments on commit 3f934b7

Please sign in to comment.