Skip to content

V3 encryption#38

Merged
PaulLaux merged 72 commits intozsa1from
v3_encryption
Jan 31, 2023
Merged

V3 encryption#38
PaulLaux merged 72 commits intozsa1from
v3_encryption

Conversation

@PaulLaux
Copy link
Collaborator

@PaulLaux PaulLaux commented Dec 20, 2022

Added support for note_encryption_V3 and encryption generalization (QED-it/librustzcash#18)

not for review: note_encryption.rs, note_encryptionv2v3.rs and src/test_vectors/note_encryption.rs. These files represent two possible approaches for backward compatibility and will be finalized down the road. (the files were excluded from the build).

PaulLaux and others added 30 commits November 24, 2022 12:38
* Added .circleci/config.yml
Implements the issuer keys as

    IssuerAuthorizingKey -> isk
    IssuerVerifyingKey -> ik

Test vectors generated with zcash_test_vectors repo
* Added NoteType to Notes
* Added NoteType to value commitment derivation
* Circleci project setup (#1)

* Added .circleci/config.yml

* Added NoteType to Notes

* reformated file

* updated `derive` for NoteType

* added note_type to value commit derivation

* rustfmt

* updated ci config

* updated ci config

* updated ci config

* updated derive for note_type

* added test for arb note_type

* added test for `native` note type

* zsa-note-encryption: introduce AssetType and encode and decode it in note plaintexts

* zsa-note-encryption: extend the size of compact notes to include asset_type

* fixed clippy warrnings

* rustfmt

* zsa-note-encryption: document parsing requirement

* zsa-note-encryption: revert support of ZSA compact action

* zsa_value: add NoteType method is_native

* zsa-note-encryption: remove dependency on changes in the other crate

* zsa-note-encryption: extract memo of ZSA notes

* zsa-note-encryption: tests (zcash_test_vectors 77c73492)

* zsa-note-encryption: simplify roundtrip test

* zsa-note-encryption: more test vectors (zcash_test_vectors c10da464)

* Circleci project setup (#1)

* Added .circleci/config.yml

* issuer keys implementation (#5)

Implements the issuer keys as

    IssuerAuthorizingKey -> isk
    IssuerVerifyingKey -> ik

Test vectors generated with zcash_test_vectors repo

* Added NoteType to Notes (#2)

* Added NoteType to Notes
* Added NoteType to value commitment derivation

* zsa-note-encryption: use both native and ZSA in proptests

* zsa-note-encryption: test vector commit 51398c93

* zsa-note-encryption: fix after merge

Co-authored-by: Paul <3682187+PaulLaux@users.noreply.github.com>
Co-authored-by: Paul <lauxpaul@protonmail.com>
Co-authored-by: Aurélien Nicolas <info@nau.re>
Co-authored-by: Daniel Benarroch <danielbenarroch92@gmail.com>
+ Updated test bsk_consistent_with_bvk to verify mixed note types.
+ Added NoteType support to the builder and the bundle.
+ added split_flag to SpentInfo and as input to the Circuit (currently commented out)
+ added conditional cv_sum calculation (currently commented out)
+ added padding to actions
- added IssueBundle and IssueAction
- added a builder for IssueBundle
- added verify_issue_bundle() for consensus verification.
- unit tests.
added tests in `tests/zsa.rs`
* disabled split notes and proof check for zsa transfer
* fixes and suggestions

* changed "issuer" to "issuance" as per zcash#356 (comment)

* terminology fixes

* updated naming
* rename 2 note_type -> asset as per  zcash#356 (comment)

* added a dedicated type for "IssuanceAuth"

* disabled codecov github action due to bad behavior.

* extracted "is_asset_desc_of_valid_size()" into asset_id.rs
* improved `verify_issue_bundle()`
Copy link

@vivek-arte vivek-arte left a comment

Choose a reason for hiding this comment

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

Looks generally alright, made a few comments. I would prefer to pass through src/note_encryption_v3.rs once more with a diff from the original note_encryption.rs because it is currently difficult to see the changes specific to V3. Will update once I do that.

src/issuance.rs Outdated
pub fn arb_issue_action()(
note in arb_zsa_note(),
note in arb_note(NoteValue::from_raw(10)),
asset_descr in string_regex(".{1,512}").unwrap()
Copy link

@vivek-arte vivek-arte Jan 26, 2023

Choose a reason for hiding this comment

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

This is from a previous merge, but is it not that asset_descr needs to "match" the AssetId value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, fixed it.

}

fn enc_ciphertext_compact(&self) -> CompactNoteCiphertextBytes {
self.enc_ciphertext.clone()

Choose a reason for hiding this comment

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

Do we need to clone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, since we return a value not a ref.

PaulLaux added a commit to QED-it/zcash-test-vectors that referenced this pull request Jan 31, 2023
- Updated to support encryption_v3 as given in QED-it/orchard#38 and QED-it/librustzcash#18.

- This PR breaks compatibility with OrchardDomainV2
@PaulLaux PaulLaux merged commit cec48d7 into zsa1 Jan 31, 2023
let encrypted_note = TransmittedNoteCiphertext {
epk_bytes: [0u8; 32],
enc_ciphertext: [0u8; 580],
enc_ciphertext: [0u8; 612],

Choose a reason for hiding this comment

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

Hardcoded constants make me sad, but that's consistent with current style so probably this is more of a general comment rather than a suggestion

.expect("The spend info is valid");
split_spend.split_flag = true;
split_spend
SpendInfo::new(self.fvk.clone(), self.note, self.merkle_path.clone(), true).unwrap()

Choose a reason for hiding this comment

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

Do we prefer unwrap over expect with comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only when the expect() comment is trivial.

ch.update(&action.cmx().to_bytes());
ch.update(&action.encrypted_note().epk_bytes);
ch.update(&action.encrypted_note().enc_ciphertext[..52]);
ch.update(&action.encrypted_note().enc_ciphertext[..84]); // TODO: make sure it is backward compatible with [..52]

Choose a reason for hiding this comment

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

I don't think it is if I understand correctly. Shall we maybe select proper hasher here based on value of EncCipherText enum? This way we can hash both V2 and V3

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, for sure. Our final aim should be to replace all hardcoded numbers with the relevant constants. But right now, I'm focusing on creating a simple delta to highlight the changes.

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.

5 participants