-
Notifications
You must be signed in to change notification settings - Fork 111
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
Initial Tx V6 support #7978
Initial Tx V6 support #7978
Conversation
…nsaction methods, fix compilation errors
This commit introduces the initial support for V6 transactions, which include support for Zcash Shielded Assets (ZSA) features, such as burn and issuance. The changes encompass the necessary code adjustments and implementations to enable V6 transactions with these features. Additional testing and further refinements will follow.
…Note directly in arbitrary.rs + other minor changes
… it instead of HAS_BURN etc.
…the last version of the main branch)
…n to OrchardVariant
… Cargo.toml for now to resolve cargo conflict with orchard_zsa
/// A trait representing compile-time settings of Orchard Shielded Protocol used in | ||
/// the transactions `V5` and `V6`. | ||
pub trait OrchardFlavour: Clone + Debug { | ||
/// The size of the encrypted note for this protocol version. | ||
const ENCRYPTED_NOTE_SIZE: usize; | ||
|
||
/// A type representing an encrypted note for this protocol version. | ||
type EncryptedNote: Clone | ||
+ Debug | ||
+ PartialEq | ||
+ Eq | ||
+ DeserializeOwned | ||
+ Serialize | ||
+ ZcashDeserialize | ||
+ ZcashSerialize; | ||
|
||
/// A type representing a burn field for this protocol version. | ||
type BurnType: Clone + Debug + Default + ZcashDeserialize + ZcashSerialize; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trait encapsulate the difference between orchard
and orchardZSA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you for the explicit NoBurn
. (It's much easier to review than ()
.)
#[cfg(feature = "tx-v6")] | ||
/// Assets intended for burning | ||
/// TODO: FIXME: Add ref to spec | ||
pub burn: V::BurnType, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will appreciate the feedback on this extension:
pub struct ShieldedData<V: OrchardFlavour> { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this seems like a useful design. We know it works because we used something similar for v4 and v5 transaction formats for sapling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a useful design, thank you for the clear code!
I'm just checking with the team how many reviewers we want to have a look at it.
// TODO: FIXME: Consider moving it to transaction.rs as it's not used here. Or move its usage here from transaction.rs. | ||
/// A struct that contains references to several fields of an `Action` struct. | ||
/// Those fields are used in other parts of the code that call the `orchard_actions()` method of the `Transaction`. | ||
/// The goal of using `ActionRef` is that it's not a generic, unlike `Action`, so it can be returned from Transaction methods | ||
/// (the fields of `ActionRef` do not depend on the generic parameter `Version` of `Action`). | ||
pub struct ActionRef<'a> { | ||
/// A reference to the value commitment to the net value of the input note minus the output note. | ||
pub cv: &'a super::commitment::ValueCommitment, | ||
/// A reference to the nullifier of the input note being spent. | ||
pub nullifier: &'a super::note::Nullifier, | ||
/// A reference to the randomized validating key for `spendAuthSig`. | ||
pub rk: &'a reddsa::VerificationKeyBytes<SpendAuth>, | ||
/// A reference to the x-coordinate of the note commitment for the output note. | ||
pub cm_x: &'a pallas::Base, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this data is small, it would be ok to clone it. But if it works with lifetimes that's also ok.
For example, we clone anchors to abstract over v4 and v5 sapling transaction structures:
zebra/zebra-chain/src/sapling/shielded_data.rs
Lines 298 to 322 in ca062d0
impl<AnchorV> TransferData<AnchorV> | |
where | |
AnchorV: AnchorVariant + Clone, | |
Spend<PerSpendAnchor>: From<(Spend<AnchorV>, AnchorV::Shared)>, | |
{ | |
/// Iterate over the [`Spend`]s for this transaction, returning | |
/// `Spend<PerSpendAnchor>` regardless of the underlying transaction version. | |
/// | |
/// Allows generic operations over V4 and V5 transactions, including: | |
/// * spend verification, and | |
/// * non-malleable transaction ID generation. | |
/// | |
/// # Correctness | |
/// | |
/// Do not use this function for serialization. | |
pub fn spends_per_anchor(&self) -> impl Iterator<Item = Spend<PerSpendAnchor>> + '_ { | |
self.spends().cloned().map(move |spend| { | |
Spend::<PerSpendAnchor>::from(( | |
spend, | |
self.shared_anchor() | |
.expect("shared anchor must be Some if there are any spends"), | |
)) | |
}) | |
} | |
} |
// TODO: FIXME: Check this: V6 is used as it provides the max size of the action. | ||
// So it's used even for V5 - is this correct? | ||
#[cfg(feature = "tx-v6")] | ||
let result = Action::<super::OrchardZSA>::max_allocation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is acceptable as long as the max allocation is higher than any protocol limits. TrustedPreallocate
just prevents denial of service attacks that preallocate a lot of memory by providing a very large list size.
#[cfg(feature = "tx-v6")] | ||
/// Assets intended for burning | ||
/// TODO: FIXME: Add ref to spec | ||
pub burn: V::BurnType, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this seems like a useful design. We know it works because we used something similar for v4 and v5 transaction formats for sapling.
/// A trait representing compile-time settings of Orchard Shielded Protocol used in | ||
/// the transactions `V5` and `V6`. | ||
pub trait OrchardFlavour: Clone + Debug { | ||
/// The size of the encrypted note for this protocol version. | ||
const ENCRYPTED_NOTE_SIZE: usize; | ||
|
||
/// A type representing an encrypted note for this protocol version. | ||
type EncryptedNote: Clone | ||
+ Debug | ||
+ PartialEq | ||
+ Eq | ||
+ DeserializeOwned | ||
+ Serialize | ||
+ ZcashDeserialize | ||
+ ZcashSerialize; | ||
|
||
/// A type representing a burn field for this protocol version. | ||
type BurnType: Clone + Debug + Default + ZcashDeserialize + ZcashSerialize; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you for the explicit NoBurn
. (It's much easier to review than ()
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent, thank you.
…ts field as copies instead of refs, for clarity and simplicity
I'm going to close this one as I assume there will be a new PR with this work in future |
Motivation
Not to be merged - this is a draft PR to facilitate discussion and collaboration.
This pull request aims to implement the Transaction V6 format as specified in ZIP 230 (https://qed-it.github.io/zips/zip-0230), enabling support for Zcash Shielded Assets (ZSA) features, such as burn and issuance.
This is an early PR to have a discussion around the proposed structure and the way forward.
The main objective is to have an agreement about extending the
ShieldedData
struct:PR Author Checklist
Check before marking the PR as ready for review:
For significant changes:
Specifications
This PR focuses on structural changes in zebra-chain to accommodate the future implementation of the Zcash Transaction Version 6 format. Serialization/deserialization for V6 has not been implemented in this iteration.
Complex Code or Requirements
No significant changes to concurrency, unsafe code, or complex consensus rules have been introduced.
Solution
tx-v6
Rust feature flag to enable conditional compilationTesting
Unit tests have been updated to support the generic ShieldedData and validate the behavior of both V5 and V6 transactions. While new tests specific to V6 have not been added at this stage, existing tests ensure compatibility with V5 transactions.
Review
This PR is not blocking any other work. Reviewers are invited to verify that the scope aligns with the ticket, tests cover the PR's motivation, and any potential blockers have been addressed.
Reviewer Checklist
Check before approving the PR:
PR blockers can be dealt with in new tickets or PRs.
Follow Up Work
The next steps may include implementing V6 serialization/deserialization and adding specific tests for V6 transactions.