Issuance tests and Issue commitments.#17
Conversation
PaulLaux
left a comment
There was a problem hiding this comment.
Great first PR!
Added some comments and additions that we will need.
src/bundle/commitments.rs
Outdated
| } | ||
|
|
||
| /// Construct the commitment for the issue bundle | ||
| /// TODO - investigate if we need different personalizations |
There was a problem hiding this comment.
yes, lets go with
const ZCASH_ORCHARD_ZSA_ISSUE_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcZSAIssue";
src/bundle/commitments.rs
Outdated
| @@ -1,8 +1,10 @@ | |||
| //! Utility functions for computing bundle commitments | |||
|
|
|||
| use bitvec::macros::internal::funty::Fundamental; | |||
There was a problem hiding this comment.
This line doe not seem to be related to anything.
There was a problem hiding this comment.
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() | ||
| } |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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); | ||
|
|
There was a problem hiding this comment.
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))
}
}
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)); |
There was a problem hiding this comment.
It's better to import then Error::.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
src/issuance.rs
Outdated
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
let's move those to keys.rs
src/issuance.rs
Outdated
| 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) | ||
| } |
There was a problem hiding this comment.
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.
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`] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
got it, but lets remove the TODO, I feel that this is quite complete.
PaulLaux
left a comment
There was a problem hiding this comment.
looks good, please resolve #17 (comment) and merge.
Uh oh!
There was an error while loading. Please reload this page.