-
Notifications
You must be signed in to change notification settings - Fork 0
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
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 <[email protected]>
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.
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.
added some comments
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.
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
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.
done
@@ -345,7 +403,13 @@ impl<A: Authorization> TransactionData<A> { | |||
transparent_bundle: Option<transparent::Bundle<A::TransparentAuth>>, | |||
sprout_bundle: Option<sprout::Bundle>, | |||
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< |
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.
new line
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.
done
#[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< |
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.
new line
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.
done
) -> Option< | ||
orchard::bundle::Bundle<B::OrchardAuth, Amount, OrchardVanilla>, | ||
>, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] f_zsa_orchard: impl FnOnce( |
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.
new line
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.
done
version in Just(version) | ||
) -> TransactionData<Authorized> { | ||
TransactionData { | ||
TransactionData::<Authorized> { |
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.
I don't think this is needed.
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.
removed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change not required
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.
indeed, reverted
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.
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.
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.
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.
not sure we need it
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.
removed
} | ||
|
||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
fn digest_orchard_zsa( |
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.
see comment wrt digest_orchard
@@ -516,6 +578,7 @@ impl TransactionDigest<Authorized> for BlockTxCommitmentDigester { | |||
transparent_digest: Self::TransparentDigest, | |||
sapling_digest: Self::SaplingDigest, | |||
orchard_digest: Self::OrchardDigest, | |||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] issue_digest: Self::IssueDigest, |
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.
new line
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.
done
} | ||
|
||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
fn digest_orchard_zsa( |
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.
see comment wrt digest_orchard
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.
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.
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<()> { |
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.
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.
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. |
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.
/// Writes an [
orchard::Bundle] in the appropriate transaction format
@@ -967,6 +1189,7 @@ pub trait TransactionDigest<A: Authorization> { | |||
transparent_digest: Self::TransparentDigest, | |||
sapling_digest: Self::SaplingDigest, | |||
orchard_digest: Self::OrchardDigest, | |||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] issue_digest: Self::IssueDigest, |
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.
new line plz
@@ -99,7 +111,16 @@ pub enum Error<FE> { | |||
SaplingBuilderNotAvailable, | |||
/// The builder was constructed with a target height before NU5 activation, but an Orchard | |||
/// spend or output was added. | |||
OrchardBuilderNotAvailable, | |||
OrchardBundleNotAvailable, | |||
/// The issuance bundle not initialized. |
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.
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.
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
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.
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.
@@ -113,7 +122,7 @@ pub fn write_v6_bundle<W: Write>( | |||
) -> io::Result<()> { | |||
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.
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)?;
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