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

ZSA integration (step 1): Integrate ZSA-compatible crates into Zebra while maintaining original Orchard (Vanilla) support for now [to upstream] #24

Open
wants to merge 20 commits into
base: zsa1
Choose a base branch
from

Conversation

dmidem
Copy link

@dmidem dmidem commented Oct 29, 2024

This draft PR updates Zebra to use QED-it's ZSA-compatible versions of the following crates:

  • halo2
  • zcash_note_encryption
  • spling-crypto
  • orchard
  • Crates from the libruszcash repository:
    • zcash_primitives
    • zcash_protocol
    • zcash_address
    • zcash_encoding
    • zcash_history
    • zcash_client_backend

These version of the crates are backward-compatible and support both the current Orchard (Vanilla) protocol and the upcoming ZSA variation.

This PR maintains support for the existing Orchard protocol only, without yet enabling or integrating ZSA-specific features!

@dmidem dmidem assigned PaulLaux and unassigned PaulLaux Oct 29, 2024
@dmidem dmidem requested a review from PaulLaux October 29, 2024 13:50
@dmidem dmidem removed the C-trivial label Oct 29, 2024
…loy related workflows (add .disabled suffix to their .yml files)
@dmidem dmidem removed the C-trivial label Oct 29, 2024
@dmidem dmidem changed the title ZSA integration (step 1): Integrate ZSA-compatible crates into Zebra while maintaining original Orchard (Vanilla) support for now [to upstream ZSA integration (step 1): Integrate ZSA-compatible crates into Zebra while maintaining original Orchard (Vanilla) support for now [to upstream] Oct 29, 2024
@PaulLaux PaulLaux requested a review from arya2 October 30, 2024 13:41
Comment on lines +91 to +98
// FIXME: support OrchardZSA too, 580 works for OrchardVanilla only!
// FIXME: consider more "type safe" way to do the following conversion
// (now it goes through &[u8])
enc_ciphertext: <[u8; 580]>::try_from(
a.encrypted_note().enc_ciphertext.as_ref(),
)
.unwrap()
.into(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// FIXME: support OrchardZSA too, 580 works for OrchardVanilla only!
// FIXME: consider more "type safe" way to do the following conversion
// (now it goes through &[u8])
enc_ciphertext: <[u8; 580]>::try_from(
a.encrypted_note().enc_ciphertext.as_ref(),
)
.unwrap()
.into(),
enc_ciphertext: a.encrypted_note().enc_ciphertext.0.into(),

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

Comment on lines +160 to +163
// FIXME: is this correct?
#[cfg(zcash_unstable = "nu6")]
type OrchardZsaAuth = orchard::bundle::Authorized;

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems unnecessary if it's going to be the same as the OrchardAuth type?

Choose a reason for hiding this comment

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

I tend to agree, why not use OrchardAuth everywhere?

Copy link
Author

Choose a reason for hiding this comment

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

I had to duplicate it because is OrchardZsaAuth required by Authorization trait:

https://github.com/QED-it/librustzcash/blob/zsa1/zcash_primitives/src/transaction/mod.rs#L303

Comment on lines +164 to +166
// FIXME: is this correct?
#[cfg(zcash_unstable = "nu6")]
type IssueAuth = orchard::issuance::Signed;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one does seem necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

Comment on lines +296 to +303
// FIXME: do we need to pass another arg values or orchard_zsa and issue instead of IdentityMap?
.map_authorization(
f_transparent,
IdentityMap,
IdentityMap,
IdentityMap,
IdentityMap,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fine, the transparent outputs are needed for the TransparentAuthorizingContext impl used via the zp_tx::sighash::signature_hash() call just below this impl block, where the shielded bundles aren't accessed at all for v5 transactions and only the SaplingAuth type is constrained for v4.

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

Comment on lines +147 to +154
// FIXME: simplify the flags creation - make `Flags::from_parts` method pub?
// FIXME: support OrchardZSA?
let flags = match (enable_spend, enable_output) {
(false, false) => orchard::builder::BundleType::DISABLED.flags(),
(false, true) => orchard::bundle::Flags::SPENDS_DISABLED_WITHOUT_ZSA,
(true, false) => orchard::bundle::Flags::OUTPUTS_DISABLED,
(true, true) => orchard::bundle::Flags::ENABLED_WITHOUT_ZSA,
};
Copy link
Collaborator

@arya2 arya2 Oct 31, 2024

Choose a reason for hiding this comment

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

The Flags type in zebra_chain::orchard::shielded_data needs a new associated constant like const ENABLE_ZSA = 0b00000100 for its ZcashSerialize/ZcashDeserialize impls to parse the ZSA-enabled bit.

Suggested change
// FIXME: simplify the flags creation - make `Flags::from_parts` method pub?
// FIXME: support OrchardZSA?
let flags = match (enable_spend, enable_output) {
(false, false) => orchard::builder::BundleType::DISABLED.flags(),
(false, true) => orchard::bundle::Flags::SPENDS_DISABLED_WITHOUT_ZSA,
(true, false) => orchard::bundle::Flags::OUTPUTS_DISABLED,
(true, true) => orchard::bundle::Flags::ENABLED_WITHOUT_ZSA,
};
// FIXME: support OrchardZSA?
let flags = orchard::bundle::Flags::from_byte(shielded_data.flags.bits())
.expect("type should not have unexpected bits");

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

@@ -1,5 +1,7 @@
//! Encrypted parts of Orchard notes.

// FIXME: make it a generic and add support for OrchardZSA (encrypted tote size ofr it is not 580!)
Copy link
Collaborator

@arya2 arya2 Oct 31, 2024

Choose a reason for hiding this comment

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

Optional: There are some trait impls in this file that can be removed/derived once const generics have been added.

Nitpick:

Suggested change
// FIXME: make it a generic and add support for OrchardZSA (encrypted tote size ofr it is not 580!)
// FIXME: make it a generic and add support for OrchardZSA (where encrypted note size is not 580!)

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

Copy link

@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,
plus clean FIXME as much as possible.

@@ -68,7 +68,7 @@ bitflags = "2.5.0"
bitflags-serde-legacy = "0.1.1"
blake2b_simd = "1.0.2"
blake2s_simd = "1.0.2"
bridgetree = "0.6.0"
bridgetree = "0.4.0"

Choose a reason for hiding this comment

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

It is worth to comment out this and every downgraded dependency.

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

Comment on lines +536 to +537
// FIXME: remove cfg and process Nu7 properly (uses Self::Nu6 for now)
#[cfg(zcash_unstable = "nu6")]

Choose a reason for hiding this comment

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

All nu6 -> nu7 flags should be marked with:
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(similar to our librustzcash style)

Choose a reason for hiding this comment

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

(all nu6 -> nu7 locations)

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

@@ -137,6 +137,16 @@ impl zp_tx::components::orchard::MapAuth<orchard::bundle::Authorized, orchard::b
}
}

// FIXME: is this implemetation correct?
#[cfg(zcash_unstable = "nu6")]

Choose a reason for hiding this comment

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

nu6 or nu7 ?

Copy link
Author

Choose a reason for hiding this comment

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

Link to this comment copied to #37

fn map_issue_authorization(&self, s: orchard::issuance::Signed) -> orchard::issuance::Signed {
s
}
}

Choose a reason for hiding this comment

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

maybe just

impl zp_tx::components::issuance::MapIssueAuth<orchard::issuance::Signed, orchard::issuance::Signed> for IdentityMap {
    fn map_issue_authorization(&self, signed: orchard::issuance::Signed) -> orchard::issuance::Signed {
        signed
    }
}

Copy link
Author

@dmidem dmidem Jan 11, 2025

Choose a reason for hiding this comment

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

I used the existing style of short names used in this file, see other map_authorization functions above in this file. Link for this comment copied to #37.

Comment on lines +160 to +163
// FIXME: is this correct?
#[cfg(zcash_unstable = "nu6")]
type OrchardZsaAuth = orchard::bundle::Authorized;

Choose a reason for hiding this comment

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

I tend to agree, why not use OrchardAuth everywhere?

@@ -75,7 +75,8 @@ pub type ItemVerifyingKey = VerifyingKey;

lazy_static::lazy_static! {
/// The halo2 proof verifying key.
pub static ref VERIFYING_KEY: ItemVerifyingKey = ItemVerifyingKey::build();
// FIXME: support OrchardZSA?
pub static ref VERIFYING_KEY: ItemVerifyingKey = ItemVerifyingKey::build::<OrchardVanilla>();

Choose a reason for hiding this comment

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

yes, but not in this PR

Copy link
Author

Choose a reason for hiding this comment

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

Done in #37.

@@ -143,6 +144,15 @@ impl From<&zebra_chain::orchard::ShieldedData> for Item {
.flags
.contains(zebra_chain::orchard::Flags::ENABLE_OUTPUTS);

// FIXME: simplify the flags creation - make `Flags::from_parts` method pub?
// FIXME: support OrchardZSA?

Choose a reason for hiding this comment

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

not in this PR

Copy link
Author

Choose a reason for hiding this comment

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

Link for this comment copied to #37.

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.

3 participants