Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize Orchard with updates from zcash_note_encryption for zcash PR #2 issues resolve #111

Merged
merged 7 commits into from
Jul 31, 2024

Conversation

dmidem
Copy link

@dmidem dmidem commented Jul 30, 2024

Orchard has been synced with the changes from PR #10 in the zcash_note_encryption repository. This update includes the following changes:

  • Implements new parse_note_plaintext_bytes, parse_note_ciphertext_bytes, and parse_compact_note_plaintext_bytes methods of the Domain trait from zcash_note_encryption.
  • Uses the NoteBytes trait and NoteBytesData structure from zcash_note_encryption instead of having local definitions and implementations.

Note

This PR uses the resolve_zcash_pr2_issues branch of zcash_note_encryption in Cargo.toml. Before merging this PR, PR #10 needs to be merged into the zsa1 branch of zcash_note_encryption. Then, this Orchard PR branch should be updated to use the zsa1 branch of zcash_note_encryption befor merging this PR.

@QED-it QED-it deleted a comment from what-the-diff bot Jul 30, 2024
@dmidem dmidem requested a review from PaulLaux July 30, 2024 08:34
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.

added minor comments and a question

@@ -25,7 +25,11 @@ impl<A, D: OrchardDomainCommon> ShieldedOutput<OrchardDomain<D>> for Action<A, D
}

fn enc_ciphertext_compact(&self) -> D::CompactNoteCiphertextBytes {
self.encrypted_note().enc_ciphertext.as_ref()[..D::COMPACT_NOTE_SIZE].into()
// FIXME: can use unwrap here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

Copy link
Author

Choose a reason for hiding this comment

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

Got it, removed the comment.

fn enc_ciphertext_compact(&self) -> D::CompactNoteCiphertextBytes {
self.enc_ciphertext
// FIXME: can use unwrap here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

Copy link
Author

Choose a reason for hiding this comment

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

Got it, removed the comment.

@@ -70,8 +74,10 @@ impl<D: OrchardDomainCommon> ShieldedOutput<OrchardDomain<D>> for CompactAction<
None
}

// FIXME: shouldn't it return None like enc_ciphertext does?
Copy link
Collaborator

Choose a reason for hiding this comment

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

no, enc_ciphertext should not be used for Orchard. It was used only by sapling.

Copy link
Author

Choose a reason for hiding this comment

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

Got it, removed the comment.

Comment on lines 278 to 293
fn parse_note_plaintext_bytes(plaintext: &[u8]) -> Option<Self::NotePlaintextBytes> {
Self::NotePlaintextBytes::from_slice(plaintext)
}

fn parse_note_ciphertext_bytes(
output: &[u8],
tag: [u8; AEAD_TAG_SIZE],
) -> Option<Self::NoteCiphertextBytes> {
Self::NoteCiphertextBytes::from_slice_with_tag(output, tag)
}

fn parse_compact_note_plaintext_bytes(
plaintext: &[u8],
) -> Option<Self::CompactNotePlaintextBytes> {
Self::CompactNotePlaintextBytes::from_slice(plaintext)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the point in adding this if not being used?

Copy link
Author

@dmidem dmidem Jul 30, 2024

Choose a reason for hiding this comment

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

The idea of introducing these functions came from str4d's review comment. Although these functions are not used in the orchard or sapling-crypto crates directly, they are used in the zcash_note_encryption crate: zcash_note_encryption delegates the implementation of these functions to upper-level crates, and then use them.

Therefore, I added them to the Domain trait as methods and then implemented them in both orchard and sapling-crypto crates.

However, as it turns out, the implementation is the same for both crates and relies solely on the NoteBytes trait methods. Given this, we can simplify the code by moving these function implementations directly to the Domain trait in the zcash_note_encryption crate.

I have tested this change, and it works correctly. I can proceed with moving the implementation (here and in sapling-crypto) if everyone agrees.

@dmidem dmidem merged commit 6e6112c into zsa1 Jul 31, 2024
28 checks passed
@dmidem dmidem deleted the zcne_resolve_zcash_pr2_issues_sync branch July 31, 2024 11:12
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