Skip to content

Issuance tests and Issue commitments.#17

Merged
alexeykoren merged 6 commits intozsa1-issue2from
zsa1-issue2-tests
Sep 21, 2022
Merged

Issuance tests and Issue commitments.#17
alexeykoren merged 6 commits intozsa1-issue2from
zsa1-issue2-tests

Conversation

@alexeykoren
Copy link

@alexeykoren alexeykoren commented Sep 19, 2022

  • Unit and property tests for issue bundle
  • Commitments for issuance.

Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

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

Great first PR!
Added some comments and additions that we will need.

}

/// Construct the commitment for the issue bundle
/// TODO - investigate if we need different personalizations
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, lets go with

const ZCASH_ORCHARD_ZSA_ISSUE_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcZSAIssue";

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -1,8 +1,10 @@
//! Utility functions for computing bundle commitments

use bitvec::macros::internal::funty::Fundamental;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line doe not seem to be related to anything.

Copy link
Author

Choose a reason for hiding this comment

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

It was needed for "bool.as_u8()" call, but probably importing it is a bit overkill for such a small conversion so I changed it to a simpler way

}
h.update(&bundle.ik().to_bytes());
h.finalize()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

While at it, please add

pub(crate) fn hash_issue_bundle_auth_data(bundle: &IssueBundle<Signed>) -> Blake2bHash {
    let mut h = hasher(ZCASH_ORCHARD_ZSA_ISSUE_SIG_PERSONALIZATION);
    h.update(bundle.authorization().signature().to_bytes());
    
    h.finalize()
}

const ZCASH_ORCHARD_ZSA_ISSUE_SIG_PERSONALIZATION: &[u8; 16] = b"ZTxAuthZSAOrHash";

to comply with zip-244 similar to hash_bundle_auth_data().

Copy link
Author

Choose a reason for hiding this comment

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

Done, using "&<[u8; 64]>::from..." as they do in 'hash_bundle_auth_data'

/// change if the effects of the bundle are altered.
#[derive(Debug)]
pub struct IssueBundleCommitment(pub Blake2bHash);

Copy link
Collaborator

Choose a reason for hiding this comment

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

please add

/// A commitment to the authorizing data within a bundle of actions.
#[derive(Debug)]
pub struct IssueBundleAuthorizingCommitment(pub Blake2bHash);
impl IssueBundle<Signed> {
    pub fn authorizing_commitment(&self) -> IssueBundleAuthorizingCommitment {
        BundleAuthorizingCommitment(hash_issue_bundle_auth_data(self))
    }
}

Copy link
Author

Choose a reason for hiding this comment

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

Added

src/issuance.rs Outdated
) -> Result<&'a mut HashSet<NoteType>, Error> {
if let Err(e) = bundle.ik.verify(&sighash, &bundle.authorization.signature) {
return Err(IssueBundleInvalidSignature(e));
return Err(Error::IssueBundleInvalidSignature(e));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to import then Error::.

Copy link
Author

Choose a reason for hiding this comment

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

100% agree, but before in most cases it was implemented with Error:: so I decided to change to a single standard. Changing all to import now

src/issuance.rs Outdated
)
.unwrap();

let sighash: [u8; 32] = <[u8; 32]>::try_from(bundle.commitment().0.as_bytes()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

should add somthing like

impl From<IssueBundleCommitment> for [u8; 32] {
    fn from(commitment: BundleCommitment) -> Self {
        // The commitment uses BLAKE2b-256.
        commitment.0.as_bytes().try_into().unwrap()
    }
}

let sighash: [u8 ;32] = bundle.commitment().into();

to avoid the custom conversion. We will need it anyway.

Copy link
Author

Choose a reason for hiding this comment

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

Done

src/issuance.rs Outdated
Comment on lines +1005 to +1018
prop_compose! {
/// Generate a uniformly distributed RedDSA issuer authorizing key.
pub fn arb_issuer_authorizing_key()(rng_seed in prop::array::uniform32(prop::num::u8::ANY)) -> IssuerAuthorizingKey {
let mut rng = StdRng::from_seed(rng_seed);
IssuerAuthorizingKey::from(&SpendingKey::random(&mut rng))
}
}

prop_compose! {
/// Generate a uniformly distributed RedDSA issuer validating key.
pub fn arb_issuer_validating_key()(isk in arb_issuer_authorizing_key()) -> IssuerValidatingKey {
IssuerValidatingKey::from(&isk)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's move those to keys.rs

Copy link
Author

Choose a reason for hiding this comment

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

Done

src/issuance.rs Outdated
Comment on lines +1031 to +1034
pub fn arb_issue_action_n(n_actions: usize) -> impl Strategy<Value = IssueAction> {
let value_gen = Strategy::boxed(arb_note_value_bounded(MAX_NOTE_VALUE / n_actions as u64));
value_gen.prop_flat_map(arb_issue_action)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice execution but we do not need to be constrained by MAX_NOTE_VALUE / n_actions. We just need to have valid notes. Please remove and simplify since it might confuse.

Copy link
Author

Choose a reason for hiding this comment

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

Ok

src/issuance.rs Outdated
prop_compose! {
/// Generate an arbitrary issue bundle with fake authorization data. This bundle does not
/// necessarily respect consensus rules; for that use
/// TODO [`crate::builder::testing::arb_issue_bundle`]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the TODO? x3

Copy link
Author

Choose a reason for hiding this comment

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

Repeating the same design they had - current proptests create invalid random data structures, while realistic ones are part of e2e and builder.rs. Since we have separate PRs for units/props and e2e - I decided to work on realistic data structures in e2e context

Copy link
Collaborator

Choose a reason for hiding this comment

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

got it, but lets remove the TODO, I feel that this is quite complete.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@PaulLaux PaulLaux changed the title Issuance tests Issuance tests and Issue commitments. Sep 20, 2022
Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

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

looks good, please resolve #17 (comment) and merge.

@alexeykoren alexeykoren merged commit 46085d7 into zsa1-issue2 Sep 21, 2022
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.

2 participants