diff --git a/src/domain/orchard_domain.rs b/src/domain/orchard_domain.rs index adc67d81e..24f4f9b2f 100644 --- a/src/domain/orchard_domain.rs +++ b/src/domain/orchard_domain.rs @@ -75,7 +75,7 @@ pub trait OrchardDomainCommon: fmt::Debug + Clone { /// with ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION /// * \[(cv, rk, enc_ciphertext\[564..\], out_ciphertext)*\] personalized /// with ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION - /// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244] + /// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244] /// /// [zip244]: https://zips.z.cash/zip-0244 fn update_hash_with_actions>( diff --git a/src/issuance.rs b/src/issuance.rs index 704204a46..1e8217656 100644 --- a/src/issuance.rs +++ b/src/issuance.rs @@ -582,7 +582,7 @@ impl IssueBundle { /// Validates an [`IssueBundle`] by performing the following checks: /// /// - **IssueBundle Auth signature verification**: -/// - Ensures the signature on the provided `sighash` matches the bundle’s authorization. +/// - Ensures the signature on the provided `sighash` matches the bundle's authorization. /// - **Static IssueAction verification**: /// - Runs checks using the `IssueAction::verify` method. /// - **Node global state related verification**: @@ -1738,11 +1738,8 @@ mod tests { rng, ik, recipient, .. } = setup_params(); - // Generated using https://onlinetools.com/utf8/generate-random-utf8 - let asset_desc_1 = "󅞞 򬪗YV8𱈇m0{둛򙎠[㷊V֤]9Ծ̖l󾓨2닯򗏟iȰ䣄˃Oߺ񗗼🦄" - .to_string() - .as_bytes() - .to_vec(); + // UTF heavy test string + let asset_desc_1 = "ΩΣ𐐷कあ한🐍★→".to_string().as_bytes().to_vec(); let asset_desc_hash_1 = compute_asset_desc_hash(&asset_desc_1).unwrap(); diff --git a/src/note/asset_base.rs b/src/note/asset_base.rs index 41d4e57f6..6d9c2a9d3 100644 --- a/src/note/asset_base.rs +++ b/src/note/asset_base.rs @@ -1,4 +1,3 @@ -use alloc::vec::Vec; use blake2b_simd::{Hash as Blake2bHash, Params}; use core::cmp::Ordering; use core::hash::{Hash, Hasher}; @@ -45,10 +44,10 @@ pub const ZSA_ASSET_DIGEST_PERSONALIZATION: &[u8; 16] = b"ZSA-Asset-Digest"; /// AssetDigest for the ZSA asset /// -/// Defined in [ZIP-226: Transfer and Burn of Zcash Shielded Assets][assetdigest]. +/// Defined in [ZIP-227: Issuance of Zcash Shielded Assets][assetdigest]. /// -/// [assetdigest]: https://zips.z.cash/zip-0226.html#asset-identifiers -pub fn asset_digest(asset_id: Vec) -> Blake2bHash { +/// [assetdigest]: https://zips.z.cash/zip-0227.html#specification-asset-identifier-asset-digest-and-asset-base +pub fn asset_digest(asset_id: [u8; 65]) -> Blake2bHash { Params::new() .hash_length(64) .personal(ZSA_ASSET_DIGEST_PERSONALIZATION) @@ -58,12 +57,12 @@ pub fn asset_digest(asset_id: Vec) -> Blake2bHash { } impl AssetBase { - /// Deserialize the asset_id from a byte array. + /// Deserialize the AssetBase from a byte array. pub fn from_bytes(bytes: &[u8; 32]) -> CtOption { pallas::Point::from_bytes(bytes).map(AssetBase) } - /// Serialize the asset_id to its canonical byte representation. + /// Serialize the AssetBase to its canonical byte representation. pub fn to_bytes(self) -> [u8; 32] { self.0.to_bytes() } @@ -76,12 +75,19 @@ impl AssetBase { /// /// # Panics /// - /// Panics if the derived Asset Base is the identity point. + /// Panics if the derived AssetBase is the identity point. #[allow(non_snake_case)] pub fn derive(ik: &IssuanceValidatingKey, asset_desc_hash: &[u8; 32]) -> Self { - // EncodeAssetId(ik, asset_desc_hash) = version_byte || ik || asset_desc_hash let version_byte = [0x00]; - let encode_asset_id = [&version_byte[..], &ik.to_bytes(), asset_desc_hash].concat(); + + // EncodeAssetId(ik, asset_desc_hash) = version_byte || ik || asset_desc_hash + let encode_asset_id: [u8; 65] = { + let mut array = [0u8; 65]; + array[..1].copy_from_slice(&version_byte); + array[1..33].copy_from_slice(&ik.to_bytes()); + array[33..].copy_from_slice(asset_desc_hash); + array + }; let asset_digest = asset_digest(encode_asset_id); diff --git a/src/value.rs b/src/value.rs index 7940af6fd..cd857fbac 100644 --- a/src/value.rs +++ b/src/value.rs @@ -6,8 +6,8 @@ //! - [`ValueSum`], the sum of note values within an Orchard [`Action`] or [`Bundle`]. //! It is a signed 64-bit integer (with range [`VALUE_SUM_RANGE`]). //! - `valueBalanceOrchard`, which is a signed 63-bit integer. This is represented -//! by a user-defined type parameter on [`Bundle`], returned by -//! [`Bundle::value_balance`] and [`Builder::value_balance`]. +//! by a user-defined type parameter on [`Bundle`], returned by +//! [`Bundle::value_balance`] and [`Builder::value_balance`]. //! //! If your specific instantiation of the Orchard protocol requires a smaller bound on //! valid note values (for example, Zcash's `MAX_MONEY` fits into a 51-bit integer), you