Reduce OrchardPrimitives generic parameter usage - #261
Conversation
c00574f to
06b2b29
Compare
06b2b29 to
86e91c7
Compare
|
Rebase on zsa1 |
…ion test to Vanilla bundle
There was a problem hiding this comment.
Overall very good result. Added comments. Also
- Burn is unprotected. Lets add a check to
Builder::add_burn()to allow only whenselfis ZSA. - Consider protecting further: add
validate_burn(&burn, bundle_version)returningBurnNotPermitted, called from the three sites that already callvalidate_action_ciphertext_kind - Same check but in
burn_validation.rs(select which set of all options is the most appropriate) - Split the burn logic away from the main logic so it is easier to swallow.
Also,
- please run
cargo clippy --all-targets --all-features: we have new warnings caused by our new code.
| .unwrap(); | ||
| } | ||
| let bundle: Bundle<_, i64, FL> = builder.build(rng).unwrap().unwrap().0; | ||
| let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0; |
There was a problem hiding this comment.
as discussed cargo bench panics somewhere here
|
|
||
| #[test] | ||
| fn commitment_hashes_the_wire_flag_byte(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) { | ||
| fn commitment_hashes_the_wire_flag_byte(bundle in arb_bundle(3)) { |
There was a problem hiding this comment.
This will get a ZSA bundle once in 5 draws due to arb_bundle_version() then will build Bundle::from_parts_unchecked( under the assumbption that this is a vanilla bundle. Need to change to arb_bundle_vanilla() to keep semantics unchanged.
| #[test] | ||
| fn ironwood_rejects_v5_commitment_version(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) { | ||
| let bundle_i64 = Bundle::from_parts_unchecked( | ||
| fn ironwood_rejects_v5_commitment_version(bundle in arb_bundle(3)) { |
There was a problem hiding this comment.
| /// the same bundle commits to distinct transaction-ID digests under each. | ||
| #[test] | ||
| fn anchor_placement_follows_tx_version(bundle in BundleArb::<OrchardVanilla>::arb_bundle(3)) { | ||
| fn anchor_placement_follows_tx_version(bundle in arb_bundle(3)) { |
There was a problem hiding this comment.
|
|
||
| #[test] | ||
| fn try_from_parts_rejects_mismatched_action_ciphertext_kind( | ||
| bundle in arb_bundle(3) |
There was a problem hiding this comment.
This bundle can be ZSA and can be Vanilla. Is this what we want?
There was a problem hiding this comment.
Fixed
- Created arb_bundle_zsa strategy for ZSA bundle
- Used this strategy here.
- Updated this test. Each actions in a bundle created with this new strategy has a ZSA ciphertext. Thus, the first rows of this test are now unnecessary.
| BundleCommitmentFormat::OrchardV6 | BundleCommitmentFormat::IronwoodV6 | ||
| BundleCommitmentFormat::OrchardV6 | ||
| | BundleCommitmentFormat::IronwoodV6 | ||
| | BundleCommitmentFormat::ZSA |
There was a problem hiding this comment.
OK, we added ZSA here but it is unused on the ZSA path. Should probably taken into account in hash_bundle_auth_data_zsa(). At least assert.
There was a problem hiding this comment.
Added an assert in hash_bundle_auth_data_zsa and a comment in includes_anchor_in_authorizing_digest
| /// The arbitrary-bundle strategies generate flags independently of the version; this pairs them | ||
| /// into a combination that a `Bundle` can actually be constructed from. | ||
| fn flags_for_version(bundle_version: BundleVersion, flags: Flags) -> Flags { | ||
| pub(crate) fn flags_for_version(bundle_version: BundleVersion, flags: Flags) -> Flags { |
There was a problem hiding this comment.
Should document the ZSA flag here.
| pub(crate) const ENC_CIPHERTEXT_SIZE_VANILLA: usize = NOTE_PLAINTEXT_SIZE_VANILLA + AEAD_TAG_SIZE; | ||
| /// The size of a ZSA encrypted note ciphertext, accounting for the AEAD tag. | ||
| pub(crate) const ENC_CIPHERTEXT_SIZE_ZSA: usize = NOTE_PLAINTEXT_SIZE_ZSA + AEAD_TAG_SIZE; | ||
|
|
There was a problem hiding this comment.
These 2 should be Public.
There was a problem hiding this comment.
I updated the visibility to public for those two constants.
I am not sure whether these constants are used in other crates.
| fn encrypted_note_for( | ||
| note: Note, | ||
| memo: Vec<u8>, | ||
| cv_net: &ValueCommitment, | ||
| cmx: &ExtractedNoteCommitment, | ||
| mut rng: impl RngCore, | ||
| ) -> TransmittedNoteCiphertext { | ||
| // The Orchard, Ironwood and ZSA encryptor aliases share encryption behavior; | ||
| // `Note::version()` selects the note plaintext lead byte. | ||
| let encryptor = NoteEncryption::<NoteEncryptionDomain<OrchardVersion>>::new( | ||
| None, | ||
| note, | ||
| memo.try_into().unwrap(), | ||
| ); | ||
|
|
||
| TransmittedNoteCiphertext { | ||
| epk_bytes: NoteEncryptionDomain::<OrchardVersion>::epk_bytes(encryptor.epk()).0, | ||
| enc_ciphertext: encryptor.encrypt_note_plaintext(), | ||
| out_ciphertext: encryptor.encrypt_outgoing_plaintext(cv_net, cmx, &mut rng), | ||
| } | ||
| } | ||
|
|
||
| impl<Pr: OrchardPrimitives> ActionArb<Pr> { | ||
| /// Builds a real, decryptable `TransmittedNoteCiphertext` for `note`, | ||
| /// mirroring `OutputInfo::build`: the same encryptor yields a non-identity | ||
| /// ephemeral public key (satisfying the `Action::from_parts` epk invariant) |
There was a problem hiding this comment.
the diff is strange here. can we reduce so it does not look like our change?
There was a problem hiding this comment.
I do not know how to reduce it. It is mainly a diff in indentation because we remove impl<Pr: OrchardPrimitives> ActionArb<Pr>
There was a problem hiding this comment.
You could add "?w=1" at the end of the github url. It will hide whitespace changes and make the diff much easier to read.
This URL for the whole PR diff
https://github.com/QED-it/orchard/pull/261/changes?w=1
This URL for the action.rs file diff
https://github.com/QED-it/orchard/pull/261/changes?w=1#diff-f4ccec926f8a15e422ea29ba8516940bab45ed47ee2845930c70531ef4ffa4c9
| )( | ||
| nf in arb_nullifier(), | ||
| (rsk, rk) in arb_valid_spendauth_keypair(), | ||
| note in arb_note(output_value, note_version), |
There was a problem hiding this comment.
same for strange / unneeded diff
There was a problem hiding this comment.
See previous comment
The diff are due to the indentation changes (I removed an impl block which is no longer required)
You could add "?w=1" at the end of the url to hide whitespace changes
Those digests require only (value_pool, tx_version) to be evaluated.
…tx_version_compatibility
We should update them because we updated ZSA personalizations.
…_bundle_auth_data_zsa
…or_in_authorizing_digest
This PR has two objectives
Also
expected_proof_sizehash_bundle_txid_dataandhash_bundle_auth_data)