Skip to content

Commit

Permalink
docs + naming [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Sep 17, 2024
1 parent f934b7f commit f7b1ddc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn compute_raw_note_log<Note, let N: u32, let NB: u32, let M: u32>(

// Number of publicly delivered values is always 0 here because `compute(...)` is only called
// in the non-partial note flow.
let num_publicly_delivered_values = 0;
let num_public_values = 0;
let encrypted_log: [u8; M] = compute_encrypted_note_log(
contract_address,
storage_slot,
Expand All @@ -34,7 +34,7 @@ fn compute_raw_note_log<Note, let N: u32, let NB: u32, let M: u32>(
ivpk,
recipient,
note,
num_publicly_delivered_values
num_public_values
);
let log_hash = sha256_to_field(encrypted_log);

Expand Down
14 changes: 7 additions & 7 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn compute_encrypted_note_log<Note, let N: u32, let NB: u32, let M: u32>(
ivpk: IvpkM,
recipient: AztecAddress,
note: Note,
num_publicly_delivered_values: u8
num_public_values: u8 // Number of values to be appended to the log in public (used in partial note flow).
) -> [u8; M] where Note: NoteInterface<N, NB> {
let (eph_sk, eph_pk) = generate_ephemeral_key_pair();

Expand All @@ -87,7 +87,7 @@ pub fn compute_encrypted_note_log<Note, let N: u32, let NB: u32, let M: u32>(
let mut encrypted_bytes: [u8; M] = [0; M];
// @todo We ignore the tags for now

encrypted_bytes[64] = num_publicly_delivered_values; // TODO(#8558): This can be just a single bit if we store info about partial fields in ABI
encrypted_bytes[64] = num_public_values; // TODO(#8558): This can be just a single bit if we store info about partial fields in ABI
let eph_pk_bytes = point_to_bytes(eph_pk);
for i in 0..32 {
encrypted_bytes[65 + i] = eph_pk_bytes[i];
Expand All @@ -109,7 +109,7 @@ pub fn compute_encrypted_note_log<Note, let N: u32, let NB: u32, let M: u32>(
// Current unoptimized size of the encrypted log
// incoming_tag (32 bytes)
// outgoing_tag (32 bytes)
// num_publicly_delivered_values (1 byte)
// num_public_values (1 byte)
// eph_pk (32 bytes)
// incoming_header (48 bytes)
// outgoing_header (48 bytes)
Expand Down Expand Up @@ -173,7 +173,7 @@ mod test {
let _ = OracleMock::mock("getRandomField").returns(eph_sk);

let recipient = AztecAddress::from_field(0x10ee41ee4b62703b16f61e03cb0d88c4b306a9eb4a6ceeb2aff13428541689a2);
let num_publicly_delivered_values: u8 = 0;
let num_public_values: u8 = 0;

let log: [u8; 449] = compute_encrypted_note_log(
contract_address,
Expand All @@ -183,7 +183,7 @@ mod test {
ivpk_m,
recipient,
note,
num_publicly_delivered_values
num_public_values
);

// The following value was generated by `tagged_log.test.ts`
Expand Down Expand Up @@ -224,7 +224,7 @@ mod test {
let _ = OracleMock::mock("getRandomField").returns(eph_sk);

let recipient = AztecAddress::from_field(0x10ee41ee4b62703b16f61e03cb0d88c4b306a9eb4a6ceeb2aff13428541689a2);
let num_publicly_delivered_values: u8 = 2;
let num_public_values: u8 = 2;

// First we compute the encrypted log without the public values
let log_without_public_values: [u8; 449] = compute_encrypted_note_log(
Expand All @@ -235,7 +235,7 @@ mod test {
ivpk_m,
recipient,
note,
num_publicly_delivered_values
num_public_values
);

// Then we "append" the public values to the log by copying both the original log and the current log into a new byte array
Expand Down
27 changes: 22 additions & 5 deletions yarn-project/circuit-types/src/logs/l1_payload/l1_note_payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export class L1NotePayload extends L1Payload {
}

public encrypt(ephSk: GrumpkinScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) {
// TODO(#8558): numPubliclyDeliveredValues could occupy just a single bit if we store info about partial fields
// TODO(#8558): numPublicValues could occupy just a single bit if we store info about partial fields
// in the ABI
// We always set the value to 0 here as we don't need partial notes encryption support in TS
const numPubliclyDeliveredValues = 0;
const numPublicValues = 0;
const encryptedPayload = super._encrypt(
this.contractAddress,
ephSk,
Expand All @@ -79,7 +79,7 @@ export class L1NotePayload extends L1Payload {
ovKeys,
new EncryptedNoteLogIncomingBody(this.storageSlot, this.noteTypeId, this.note),
);
return Buffer.concat([Buffer.alloc(1, numPubliclyDeliveredValues), encryptedPayload]);
return Buffer.concat([Buffer.alloc(1, numPublicValues), encryptedPayload]);
}

/**
Expand Down Expand Up @@ -148,13 +148,30 @@ export class L1NotePayload extends L1Payload {
);
}

/**
* Extracts the public values and the remaining ciphertext from the input buffer.
* Input byte layout:
* +-----------------------------------+
* | Byte | Description |
* |------|----------------------------|
* | 0 | num_pub_vals |
* |------|----------------------------|
* | 1 to | Ciphertext |
* | N | (N = total_length - 1 |
* | | - num_pub_vals * 32) |
* |------|----------------------------|
* | N+1 | Public values |
* | to | (num_pub_vals * 32 bytes) |
* | end | |
* +-----------------------------------+
*/
static #getPublicValuesAndRemainingCiphertext(input: Buffer): [Fr[], Buffer] {
const reader = BufferReader.asReader(input);
const numPubliclyDeliveredValues = reader.readUInt8();
const numPublicValues = reader.readUInt8();

const remainingData = reader.readToEnd();
const publicValuesData = remainingData.subarray(
remainingData.length - numPubliclyDeliveredValues * Fr.SIZE_IN_BYTES,
remainingData.length - numPublicValues * Fr.SIZE_IN_BYTES,
remainingData.length,
);
if (publicValuesData.length % Fr.SIZE_IN_BYTES !== 0) {
Expand Down

0 comments on commit f7b1ddc

Please sign in to comment.