Skip to content

Refactor enc_ciphertext to return reference instead of copy#13

Merged
dmidem merged 8 commits intozsa1from
return-ref-from-enc-ciphertext
Aug 12, 2024
Merged

Refactor enc_ciphertext to return reference instead of copy#13
dmidem merged 8 commits intozsa1from
return-ref-from-enc-ciphertext

Conversation

@dmidem
Copy link

@dmidem dmidem commented Aug 8, 2024

This PR updates the ShieldedOutput trait to return a reference from the enc_ciphertext method instead of a copy. This change was discussed and suggested in PR zcash#2 review.

Other minor changes:

  • Fix the comment for split_plaintext_at_memo.
  • Restore the original order of const definition to reduce PR diff.
  • Remove extra spaces in rust-toolchain.toml.
  • Remove unused constants COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, ENC_CIPHERTEXT_SIZE.
  • Updated CHANGELOG.md.

These changes were discussed and suggested in PR zcash_note_encryption#2
@dmidem dmidem requested a review from PaulLaux August 8, 2024 12:50
Copy link

@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.

Minor fixes are needed.

src/lib.rs Outdated
use note_bytes::NoteBytes;

/// The size of a compact note for Sapling and Orchard Vanilla.
/// The size of a compact note for Sapling and pre-ZSA Orchard.

Choose a reason for hiding this comment

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

we don't want new term pre-ZSA Orchard.
... for Sapling and Orchard is fine (x2)

Copy link
Author

Choose a reason for hiding this comment

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

Done (removed unused constants COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, ENC_CIPHERTEXT_SIZE with those comments).

src/lib.rs Outdated
32; // esk
const AEAD_TAG_SIZE: usize = 16;
/// The size of an encrypted note plaintext for Sapling and pre-ZSA Orchard.
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE;

Choose a reason for hiding this comment

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

remove COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, ENC_CIPHERTEXT_SIZE from this file.
These are domain specific values and should be part of the implementation.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

CHANGELOG.md Outdated
- Updated the `enc_ciphertext` method of the `ShieldedOutput` trait to return an
`Option` of a reference instead of a copy.
- Moved the specific constants into the `Domain` trait implementations, while
keeping the original constants for backward compatibility.

Choose a reason for hiding this comment

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

I don't think we should keep the original constants. this might create confusion.

Copy link
Author

Choose a reason for hiding this comment

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

Done (removed the constants and updated CHANGELOG accordingly).

…IPHERTEXT_SIZE, and update CHANGELOG accordingly
Copy link

@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.

please replace changelog to

- **Breaking change:** removed the constants `COMPACT_NOTE_SIZE`,
  `NOTE_PLAINTEXT_SIZE`, and `ENC_CIPHERTEXT_SIZE` as they are now 
  implementation spesific (located in `orchard` and `sapling-crypto` crates).
- Generalized the note plaintext size to support variable sizes by adding the
  abstract types `NotePlaintextBytes`, `NoteCiphertextBytes`,
  `CompactNotePlaintextBytes`, and `CompactNoteCiphertextBytes` to the `Domain`
  trait.
- Removed the separate `NotePlaintextBytes` type definition (as it is now an
  associated type).
- Added new `parse_note_plaintext_bytes`, `parse_note_ciphertext_bytes`, and
  `parse_compact_note_plaintext_bytes` methods to the `Domain` trait.
- Updated the `note_plaintext_bytes` method of the `Domain` trait to return the
  `NotePlaintextBytes` associated type.
- Updated the `encrypt_note_plaintext` method of `NoteEncryption` to return the
  `NoteCiphertextBytes` associated type of the `Domain` instead of the explicit
  array.
- Updated the `enc_ciphertext` method of the `ShieldedOutput` trait to return an
  `Option` of a reference instead of a copy.
- Added a new `note_bytes` module with helper trait and struct to deal with note
  bytes data with abstracted underlying array size.

@dmidem
Copy link
Author

dmidem commented Aug 12, 2024

please replace changelog to

- **Breaking change:** removed the constants `COMPACT_NOTE_SIZE`,
  `NOTE_PLAINTEXT_SIZE`, and `ENC_CIPHERTEXT_SIZE` as they are now 
  implementation spesific (located in `orchard` and `sapling-crypto` crates).
- Generalized the note plaintext size to support variable sizes by adding the
  abstract types `NotePlaintextBytes`, `NoteCiphertextBytes`,
  `CompactNotePlaintextBytes`, and `CompactNoteCiphertextBytes` to the `Domain`
  trait.
- Removed the separate `NotePlaintextBytes` type definition (as it is now an
  associated type).
- Added new `parse_note_plaintext_bytes`, `parse_note_ciphertext_bytes`, and
  `parse_compact_note_plaintext_bytes` methods to the `Domain` trait.
- Updated the `note_plaintext_bytes` method of the `Domain` trait to return the
  `NotePlaintextBytes` associated type.
- Updated the `encrypt_note_plaintext` method of `NoteEncryption` to return the
  `NoteCiphertextBytes` associated type of the `Domain` instead of the explicit
  array.
- Updated the `enc_ciphertext` method of the `ShieldedOutput` trait to return an
  `Option` of a reference instead of a copy.
- Added a new `note_bytes` module with helper trait and struct to deal with note
  bytes data with abstracted underlying array size.

Done.

@dmidem dmidem merged commit 663a2e5 into zsa1 Aug 12, 2024
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