-
Notifications
You must be signed in to change notification settings - Fork 0
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
Resolve Issues from PR #2 in zcash/zcash_note_encryption repository #10
Conversation
* Add NoteBytes * Implement concat manually for wasm * Fix slice bounds in concat * Fmt * Split interface and implementation of NoteBytes * Add new method to NoteBytes --------- Co-authored-by: alexeykoren <[email protected]>
…rom ShieldedOutput methods)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved with some minor comments. Please update orchard and sapling crypto after merge
src/lib.rs
Outdated
// FIXME: we can't return a ref to NoteCiphertextBytes as it's not a member of self or | ||
// a static object in saplic-crypto crate (but it is a mamber of self in orchard crate) | ||
// Should we really need to return Option here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
src/lib.rs
Outdated
// FIXME: we can't return a ref to CompactNoteCiphertextBytes as it's not a member of self or | ||
// a static object neither in orchard nor in saplic-crypto crate | ||
// FIXME: Should we return Option<...> instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace comment with
// FIXME: Should we return `Option<D::CompactNoteCiphertextBytes>` or `&D::CompactNoteCiphertextBytes` instead? (complexity)
src/lib.rs
Outdated
|
||
let (plaintext, tail) = enc_ciphertext.split_at_mut(tag_loc); | ||
let tag: [u8; AEAD_TAG_SIZE] = tail.try_into().expect("tag is correct length"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the length of the tag is correct"
src/lib.rs
Outdated
@@ -410,7 +453,7 @@ impl<D: Domain> NoteEncryption<D> { | |||
let tag = ChaCha20Poly1305::new(key.as_ref().into()) | |||
.encrypt_in_place_detached([0u8; 12][..].into(), &[], output) | |||
.unwrap(); | |||
D::NoteCiphertextBytes::from((output, tag.as_ref())) | |||
D::parse_note_ciphertext_bytes(output, tag.into()).expect("output is correct length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the output length is correct"
src/note_bytes.rs
Outdated
return None; | ||
} | ||
|
||
let mut data: [u8; N] = [0; N]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: [u8; N]
is redundant
src/lib.rs
Outdated
@@ -675,12 +712,17 @@ pub fn try_output_recovery_with_ock<D: Domain, Output: ShieldedOutput<D>>( | |||
} | |||
} | |||
|
|||
// FIXME: rename to split_ciphertext_at_tag? make it a method of ShieldedOutput trait? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
output: &[u8], | ||
tag: [u8; TAG_SIZE], | ||
) -> Option<NoteBytesData<N>> { | ||
let expected_output_len = N.checked_sub(TAG_SIZE)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
… PR #2 issues resolve (#111) Orchard has been synced with the changes from [PR #10](QED-it/zcash_note_encryption#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](https://github.com/zcash/zcash_note_encryption/pull/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. --------- Co-authored-by: Dmitry Demin <[email protected]>
This PR addresses the issues and suggestions raised in PR #2 of the
zcash/zcash_note_encryption
repository. The changes made in this branch include:Reintroduced constants such as
COMPACT_NOTE_SIZE
,NOTE_PLAINTEXT_SIZE
, andENC_CIPHERTEXT_SIZE
.Introduced a new
NoteBytes
trait to handle fixed-size byte arrays used in note encryption. AddedNoteBytesData
generict structure and ImplementedNoteBytes
forNoteBytesData
to encapsulate byte handling and parsing logic.Updated the
Domain
trait to use theNoteBytes
trait forNotePlaintextBytes
,NoteCiphertextBytes
,CompactNotePlaintextBytes
, andCompactNoteCiphertextBytes
.Added new parsing methods (
parse_note_plaintext_bytes
,parse_note_ciphertext_bytes
,parse_compact_note_plaintext_bytes
) to theDomain
trait to handle conversions safely. These methods replace the previous use ofFrom
traits, which did not handle possible failures due to incorrect byte slice sizes. Updated the encryption and decryption functions to use these new parsing methods.Renamed
extract_memo
tosplit_plaintext_at_memo
to better reflect its functionality.Refactored the
extract_tag
function to work with the newNoteBytes
trait and renamed it tosplit_ciphertext_at_tag
.Additional Notes
The
ShieldedOutput
trait methodsenc_ciphertext
andenc_ciphertext_compact
still return copies instead of references due to implementation constraints. Further refactoring may be required to address this.