In order to support note encryption for zsa, we suggest extending the current zcahsh_note_encryption
implementation. Currently, the COMPACT_NOTE_SIZE
is a constant, however we need to support variable note sizes to include the AssetId
field for zsa notes.
Currently, in zcash_note_encryption
:
/// The size of a compact note.
pub const COMPACT_NOTE_SIZE: usize = 1 + // version
11 + // diversifier
8 + // value
32; // rseed (or rcm prior to ZIP 212)
/// The size of [`NotePlaintextBytes`].
pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + 512;
and
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE;
We suggest moving the constants into the specific implementation (impl Domain for OrchardDomain
and Spling) of the Domain
trait by adding abstract types to NotePlaintextBytes
, NoteCiphertextBytes
, CompactNotePlaintextBytes
, CompactNoteCiphertextBytes
.
We get
pub trait Domain {
type EphemeralSecretKey: ConstantTimeEq;
type EphemeralPublicKey;
type PreparedEphemeralPublicKey;
type SharedSecret;
type SymmetricKey: AsRef<[u8]>;
type Note;
type Recipient;
type DiversifiedTransmissionKey;
type IncomingViewingKey;
type OutgoingViewingKey;
type ValueCommitment;
type ExtractedCommitment;
type ExtractedCommitmentBytes: Eq + for<'a> From<&'a Self::ExtractedCommitment>;
type Memo;
// Types for variable note size handling:
type NotePlaintextBytes: AsMut<[u8]> + for<'a> From<&'a [u8]>;
type NoteCiphertextBytes: AsRef<[u8]> + for<'a> From<&'a [u8]>;
type CompactNotePlaintextBytes: AsMut<[u8]> + for<'a> From<&'a [u8]>;
type CompactNoteCiphertextBytes: AsRef<[u8]>;
Also, the constant will be removed from functions' signatures since they are unknown during the compilation time. For example:
pub fn try_note_decryption<D: Domain, Output: ShieldedOutput<D, ENC_CIPHERTEXT_SIZE>>(
Will be replaced with simply
pub fn try_note_decryption<D: Domain, Output: ShieldedOutput<D>>(
We provided our initial implementation to be complemented by the appropriate changes in Orchard::note_encryption.rs
. Currently can be seen here for v2 notes https://github.com/QED-it/orchard/blob/8f02a5fdad2c1750ec5f2d372d6f9bb56346114e/src/note_encryption.rs#L197.
The changes will allow us to implement an Orchard::Domain
for V3
notes while keeping compatibility with the existing Orchard Domain ( for V2
notes ) and Sapling.