V6/Nu7 implementation#73
Conversation
…te (which supports Vanilla and ZSA) - but for now zcash_primitives is not generalised itself and pinned to Vanilla only
…te (which supports Vanilla and ZSA) - but for now zcash_primitives is not generalised itself and pinned to Vanilla only
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.
| let tx = Transaction::read(&tv.tx[..], BranchId::Nu5).unwrap(); | ||
| let tx = Transaction::read( | ||
| &tv.tx[..], | ||
| #[cfg(not(zcash_unstable = "nu6"))] /* TODO nu7 */ BranchId::Nu5, |
There was a problem hiding this comment.
#[cfg(not(zcash_unstable = "nu6")) /* TODO nu7 */ ] + new line
| 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< |
| #[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< |
| ) -> Option< | ||
| orchard::bundle::Bundle<B::OrchardAuth, Amount, OrchardVanilla>, | ||
| >, | ||
| #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] f_zsa_orchard: impl FnOnce( |
| version in Just(version) | ||
| ) -> TransactionData<Authorized> { | ||
| TransactionData { | ||
| TransactionData::<Authorized> { |
There was a problem hiding this comment.
I don't think this is needed.
| use byteorder::WriteBytesExt; | ||
|
|
||
| #[cfg(zcash_unstable = "zfuture")] | ||
| use zcash_encoding::{CompactSize, Vector}; | ||
|
|
||
| #[cfg(zcash_unstable = "zfuture")] | ||
| use crate::transaction::{components::tze, TzeDigests}; |
There was a problem hiding this comment.
indeed, reverted
There was a problem hiding this comment.
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) | ||
| } |
There was a problem hiding this comment.
this file is not connected in mod.rs and function is unused.
| } | ||
|
|
||
| #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
| fn digest_orchard_zsa( |
There was a problem hiding this comment.
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, |
| } | ||
|
|
||
| #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
| fn digest_orchard_zsa( |
There was a problem hiding this comment.
see comment wrt digest_orchard
PaulLaux
left a comment
There was a problem hiding this comment.
Good overall, added final fixes.
| 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; |
There was a problem hiding this comment.
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<()> { |
There was a problem hiding this comment.
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<()> { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
/// 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, |
| /// spend or output was added. | ||
| OrchardBuilderNotAvailable, | ||
| OrchardBundleNotAvailable, | ||
| /// The issuance bundle not initialized. |
There was a problem hiding this comment.
remove one space after ///
| .init_issuance_bundle::<FeeError>(iak, asset.clone(), None) | ||
| .unwrap(); | ||
|
|
||
| let binding = builder.mock_build_no_fee(OsRng).unwrap().into_transaction(); |
There was a problem hiding this comment.
let tx = might be a better name
| 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>>, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Vector::write_nonempty(&mut writer, bundle.actions(), write_action)?;
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