Skip to content

V6/Nu7 implementation#73

Merged
PaulLaux merged 85 commits into
zsa1from
txv6-separate-bundles-rebased
Oct 10, 2024
Merged

V6/Nu7 implementation#73
PaulLaux merged 85 commits into
zsa1from
txv6-separate-bundles-rebased

Conversation

@alexeykoren
Copy link
Copy Markdown
Collaborator

ZSA is implemented across all the codebase, including:

TransactionData now contains 2 extra components - OrchardZsaBundle and IssueBundle

Serialization/deserialization of the new components

Digests of the new components are taken into account during calculation of sighash/txid.
TODO: we are waiting for test vectors and small ordering fixes to be merged to be able to check txid calculation

Nu7 network upgrade is introduced, although currently "nu6" zcash_unstable flag is used to separate ZSA from regular build. All nu7-related "nu6" flags are annotated with /* TODO nu7 */ comment

Builder methods for ZSAs

Wallet-related functionality (zcash_client_backend, zcash_client_sqlite) are disabled since they do not support ZSAs

alexeykoren and others added 11 commits July 30, 2024 15:20
This PR updates the `zcash_primitives` crate to align with the recent
changes in the `sapling-crypto` crate, which was updated to sync with
the latest changes in `zcash_note_encryption`.

### Changes:
- Updated the usage of `enc_ciphertext` to call `.as_ref()` to match the
new return type.
- Adjusted the import of the `ENC_CIPHERTEXT_SIZE` constant to use the
definition from `sapling-crypto` instead of `zcash_note_encryption`, as
the constant has been moved to `sapling-crypto`.

Co-authored-by: Dmitry Demin <dmitry@qed-it.com>
This updates the test vectors to be of version 6 (as opposed to
version 7).

It also provides a new file for the V6 test vectors, an improvement to
having them in the same file but behind feature flags.

It provides a error for when the asset description string is not a UTF8
encoding.
@alexeykoren alexeykoren changed the title Txv6 separate bundles rebased V6/Nu7 implementation Sep 22, 2024
@alexeykoren alexeykoren mentioned this pull request Sep 22, 2024
Copy link
Copy Markdown
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

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

added some comments

Comment thread .github/workflows/ci.yml
let tx = Transaction::read(&tv.tx[..], BranchId::Nu5).unwrap();
let tx = Transaction::read(
&tv.tx[..],
#[cfg(not(zcash_unstable = "nu6"))] /* TODO nu7 */ BranchId::Nu5,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#[cfg(not(zcash_unstable = "nu6")) /* TODO nu7 */ ] + new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread zcash_primitives/src/transaction/mod.rs Outdated
sapling_bundle: Option<sapling::Bundle<A::SaplingAuth, Amount>>,
orchard_bundle: Option<orchard::Bundle<A::OrchardAuth, Amount>>,
orchard_bundle: Option<orchard::Bundle<A::OrchardAuth, Amount, OrchardVanilla>>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] orchard_zsa_bundle: Option<
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread zcash_primitives/src/transaction/mod.rs Outdated
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] orchard_zsa_bundle: Option<
orchard::Bundle<A::OrchardZsaAuth, Amount, OrchardZSA>,
>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] issue_bundle: Option<
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread zcash_primitives/src/transaction/mod.rs Outdated
) -> Option<
orchard::bundle::Bundle<B::OrchardAuth, Amount, OrchardVanilla>,
>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] f_zsa_orchard: impl FnOnce(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread zcash_primitives/src/transaction/mod.rs Outdated
version in Just(version)
) -> TransactionData<Authorized> {
TransactionData {
TransactionData::<Authorized> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this is needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed

Comment on lines +20 to +26
use byteorder::WriteBytesExt;

#[cfg(zcash_unstable = "zfuture")]
use zcash_encoding::{CompactSize, Vector};

#[cfg(zcash_unstable = "zfuture")]
use crate::transaction::{components::tze, TzeDigests};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Change not required

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

indeed, reverted

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

indeed, reverted

) -> Blake2bHash {
// Currently to_hash is designed in a way that it supports both v5 and v6 signature hash
v5_v6_signature_hash(tx, signable_input, txid_parts)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this file is not connected in mod.rs and function is unused.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not sure we need it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed

}

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
fn digest_orchard_zsa(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

see comment wrt digest_orchard

transparent_digest: Self::TransparentDigest,
sapling_digest: Self::SaplingDigest,
orchard_digest: Self::OrchardDigest,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] issue_digest: Self::IssueDigest,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

}

#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
fn digest_orchard_zsa(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

see comment wrt digest_orchard

Copy link
Copy Markdown
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

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

Good overall, added final fixes.

Comment thread components/zcash_protocol/src/consensus.rs
let asset_descr: String = String::from_utf8(asset_descr_bytes)
.map_err(|_| Error::new(ErrorKind::InvalidData, "Asset Description not valid UTF-8"))?;
let notes = Vector::read(&mut reader, |r| read_note(r))?;
let finalize = reader.read_u8()? != 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If Muhammad won't go to the mountain, then the mountain must come to Muhammad.

    let finalize = match reader.read_u8()? {
        0 => false,
        1 => true,
        _ => return Err(Error::new(ErrorKind::InvalidData, "Invalid value for finalize")),
    };

Ok(())
}

fn write_action<W: Write>(action: &IssueAction, mut writer: W) -> io::Result<()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider changing the parameters order to be compatible with existing code (ie CompactSize::write())
also it will be more compatible with the order in Vector::write(&mut writer, action.notes(), |w, note| write_note(note, w))?; and will allow to omit the parameters completely in some places (same for write_note())

Ok(())
}

pub fn write_note<W: Write>(note: &Note, writer: &mut W) -> io::Result<()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

replacing the order will allow:

fn write_action<W: Write>(action: &IssueAction, mut writer: W) -> io::Result<()> {
    ...
    Vector::write(&mut writer, action.notes(),  write_note)?;
    ...
    Ok(())
}

pub fn write_note<W: Write>( writer: &mut W,note: &Note) -> io::Result<()> {
...
}

}
}

/// Writes an [`orchard::Bundle`] in the v6 transaction format.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/// Writes an [orchard::Bundle] in the appropriate transaction format

transparent_digest: Self::TransparentDigest,
sapling_digest: Self::SaplingDigest,
orchard_digest: Self::OrchardDigest,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] issue_digest: Self::IssueDigest,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new line plz

Comment thread zcash_primitives/src/transaction/mod.rs
/// spend or output was added.
OrchardBuilderNotAvailable,
OrchardBundleNotAvailable,
/// The issuance bundle not initialized.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove one space after ///

.init_issuance_bundle::<FeeError>(iak, asset.clone(), None)
.unwrap();

let binding = builder.mock_build_no_fee(OsRng).unwrap().into_transaction();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let tx = might be a better name

Comment on lines +386 to +388
orchard_bundle: Option<orchard::bundle::Bundle<A::OrchardAuth, Amount, OrchardVanilla>>,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
orchard_zsa_bundle: Option<orchard::bundle::Bundle<A::OrchardZsaAuth, Amount, OrchardZSA>>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For safety we should make them mutually exclusive using Enum as discussed.

if let Some(bundle) = bundle {
Vector::write_nonempty(&mut writer, bundle.actions(), |w, action| {
write_action(action, w)
write_action(w, action)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Vector::write_nonempty(&mut writer, bundle.actions(), write_action)?;

@PaulLaux PaulLaux merged commit 7301f78 into zsa1 Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants