Skip to content

Update to ik and issueAuthSig encoding#170

Closed
vivek-arte wants to merge 9 commits intozsa1from
update_to_ik_and_issueauthsig_encoding
Closed

Update to ik and issueAuthSig encoding#170
vivek-arte wants to merge 9 commits intozsa1from
update_to_ik_and_issueauthsig_encoding

Conversation

@vivek-arte
Copy link
Copy Markdown

@vivek-arte vivek-arte commented Jul 7, 2025

This PR makes the updates to the encoding of the issuance validating key and the issuance authorization signature, as done in the specification in zcash/zips#1042, along with the further updates in zcash/zips#1048 and zcash/zips#1053.

The test vectors are updated in QED-it/zcash-test-vectors#31.

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Jul 7, 2025

PR Summary

  • Inclusion of a New Enum in keys.rs
    This is an update to include a new enumeration called IssuanceAuthSigScheme. This defines the ZIP227 signature scheme, a new system of issuing authorization.

  • Structural Modification of IssuanceValidatingKey
    An alteration has been made to the IssuanceValidatingKey structure, where a scheme field has been incorporated and its type has been defined as IssuanceAuthSigScheme.

  • Alteration in to_bytes Method of IssuanceValidatingKey
    The to_bytes method of IssuanceValidatingKey has been adjusted such that it can serialize the key with a scheme byte prefix. As a result, it increments the byte array size from 32 to 33.

  • Modification in from_bytes Method
    The from_bytes method in IssuanceValidatingKey has been updated to manage the scheme byte prefix during the process of deserialization.

  • Tests Aligned with New Byte Array Length
    The tests have been adjusted to match up with the new byte array length of issuance validating keys, and their serialization format.

  • Adopted Changes in asset_digest Function
    The asset_digest function is updated to accept an array of size 66 in place of 65. This change reflects the modifications related to the encoding structure.

  • Changes in encode_asset_id Array Size
    The encode_asset_id array size has been modified from 65 to 66. This aids in accommodating the additional serialization changes essential for issuance keys.

@vivek-arte vivek-arte marked this pull request as draft July 7, 2025 12:08
@vivek-arte vivek-arte force-pushed the update_to_ik_and_issueauthsig_encoding branch from 61ecd79 to 8b371c5 Compare July 8, 2025 14:36
@vivek-arte vivek-arte force-pushed the update_to_ik_and_issueauthsig_encoding branch from 4a25598 to a8d34b1 Compare July 17, 2025 13:28
@vivek-arte vivek-arte marked this pull request as ready for review July 17, 2025 13:28
@vivek-arte vivek-arte requested a review from PaulLaux July 17, 2025 13:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the encoding of the issuance validating key (ik) and issuance authorization signature (issueAuthSig) by changing their serialization format to include a leading algorithm identifier byte, following the specification changes in zcash/zips#1042.

  • Updated ik encoding from 32 to 33 bytes with a 0x00 prefix byte
  • Updated issueAuthSig encoding from 64 to 65 bytes with a 0x00 prefix byte
  • Modified test vectors to reflect the new encoding format

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test_vectors/keys.rs Updated all test vectors for ik field from 32 to 33 bytes with 0x00 prefix
src/test_vectors/issuance_auth_sig.rs Updated test vectors for both ik and sig fields with new encoding format
src/test_vectors/asset_base.rs Updated test vectors for key field and corresponding asset_base values
src/note/asset_base.rs Modified asset_digest function and AssetBase::derive to handle 66-byte asset IDs
src/keys.rs Added issuance signature scheme infrastructure and updated key/signature encoding
src/issuance.rs Added IssuanceAuthorizationSignature struct with scheme-aware encoding
src/bundle/commitments.rs Updated hash computation to use new signature byte encoding

CannotBeFirstIssuance,

/// The generation of the Issuance Authorization Signature failed.
IssueAuthSigGenerationFailed, //TODO: VA: This does not propagate the schnorr::Error, fix it.
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

The TODO comment indicates incomplete error handling. Consider either implementing proper error propagation from schnorr::Error or removing the TODO if this is intentional for now.

Copilot uses AI. Check for mistakes.
Comment on lines +412 to +414
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![self.scheme as u8];
bytes.extend(self.key.to_bytes());
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

Returning Vec for key serialization is inconsistent with other key types that return fixed-size arrays. Consider returning a fixed-size array like [u8; 33] for better type safety and consistency.

Suggested change
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![self.scheme as u8];
bytes.extend(self.key.to_bytes());
pub fn to_bytes(&self) -> [u8; 33] {
let mut bytes = [0u8; 33];
bytes[0] = self.scheme as u8;
bytes[1..].copy_from_slice(&self.key.to_bytes());

Copilot uses AI. Check for mistakes.
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![self.scheme as u8];
bytes.extend(self.signature.to_bytes());
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

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

Similar to IssuanceValidatingKey, returning Vec instead of a fixed-size array reduces type safety. Consider returning [u8; 65] for consistency with the scheme's defined signature length.

Suggested change
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![self.scheme as u8];
bytes.extend(self.signature.to_bytes());
pub fn to_bytes(&self) -> [u8; 65] {
let mut bytes = [0u8; 65];
bytes[0] = self.scheme as u8;
bytes[1..].copy_from_slice(&self.signature.to_bytes());

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@ConstanceBeguier ConstanceBeguier left a comment

Choose a reason for hiding this comment

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

To simplify the usage of different schemes, we could create a trait with at least a signature function and a verify_signature function.

}

/// Constructs an `IssuanceAuthorizationSignature` from a byte array.
pub fn from_bytes(bytes: &[u8; 65]) -> Result<Self, Error> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace [u8; 65] with [u8] or Vec because the length of the sig depends on the scheme

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssuanceAuthorizationSignature {
scheme: IssuanceAuthSigScheme,
signature: schnorr::Signature,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think signature should be a [u8] or Vec because we would like to have a generic implementation which might not be a Schnorr signature

}

/// Returns the signature.
pub fn signature(&self) -> &schnorr::Signature {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Idem
This function should return &[u8] or &Vec

let scheme = IssuanceAuthSigScheme::from_key_algorithm_byte(bytes[0])
.ok_or(IssueBundleInvalidSignature)?;
let signature =
schnorr::Signature::try_from(&bytes[1..]).map_err(|_| IssueBundleInvalidSignature)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The signature might not be the Schnorr signature


/// Constructs a `Signed` from a byte array containing Schnorr signature bytes.
pub fn from_data(data: [u8; 64]) -> Self {
pub fn from_data(data: [u8; 65]) -> Self {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace [u8; 65] with [u8] or Vec because the length of the sig depends on the scheme

pub struct IssuanceValidatingKey(schnorr::VerifyingKey);
pub struct IssuanceValidatingKey {
scheme: IssuanceAuthSigScheme,
key: schnorr::VerifyingKey,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace schnorr::VerifyingKey by [u8] or Vec

///
/// [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 {
pub fn asset_digest(asset_id: [u8; 66]) -> Blake2bHash {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

asset_id could not have a fixed length because ik has not a fixed length

@PaulLaux PaulLaux marked this pull request as draft July 22, 2025 07:53
@vivek-arte vivek-arte force-pushed the update_to_ik_and_issueauthsig_encoding branch from a8d34b1 to 9ce9c49 Compare July 29, 2025 08:53
@vivek-arte vivek-arte force-pushed the update_to_ik_and_issueauthsig_encoding branch from 9ce9c49 to e84fdcd Compare August 3, 2025 06:03
@vivek-arte
Copy link
Copy Markdown
Author

Closed in favour of #182

@vivek-arte vivek-arte closed this Aug 27, 2025
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