Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 30, 2024
1 parent ad1f671 commit f74e907
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn compute_payload_and_hash<Event, let N: u32>(
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
) -> ([u8; 416 + N * 32], Field)
) -> ([u8; 384 + N * 32], Field)
where
Event: EventInterface<N>,
{
let contract_address: AztecAddress = context.this_address();
let plaintext = event.private_to_be_bytes(randomness);

// For event logs we never include public values prefix as there are never any public values
let encrypted_log: [u8; 416 + N * 32] = compute_private_log_payload(
let encrypted_log: [u8; 384 + N * 32] = compute_private_log_payload(
contract_address,
ovsk_app,
ovpk,
Expand All @@ -38,7 +38,7 @@ unconstrained fn compute_payload_and_hash_unconstrained<Event, let N: u32>(
randomness: Field,
ovpk: OvpkM,
recipient: AztecAddress,
) -> ([u8; 416 + N * 32], Field)
) -> ([u8; 384 + N * 32], Field)
where
Event: EventInterface<N>,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn compute_payload_and_hash<Note, let N: u32>(
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
) -> (u32, [u8; 417 + N * 32], Field)
) -> (u32, [u8; 385 + N * 32], Field)
where
Note: NoteInterface<N>,
{
Expand All @@ -32,7 +32,7 @@ where
let plaintext = note.to_be_bytes(storage_slot);

// For note logs we always include public values prefix
let encrypted_log: [u8; 417 + N * 32] =
let encrypted_log: [u8; 385 + N * 32] =
compute_private_log_payload(contract_address, ovsk_app, ovpk, recipient, plaintext, true);
let log_hash = sha256_to_field(encrypted_log);

Expand All @@ -44,7 +44,7 @@ unconstrained fn compute_payload_and_hash_unconstrained<Note, let N: u32>(
note: Note,
ovpk: OvpkM,
recipient: AztecAddress,
) -> (u32, [u8; 417 + N * 32], Field)
) -> (u32, [u8; 385 + N * 32], Field)
where
Note: NoteInterface<N>,
{
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn compute_private_log_payload<let P: u32, let M: u32>(

let mut encrypted_bytes: [u8; M] = [0; M];
// @todo We ignore the tags for now
offset += 64;
offset += 32;

let eph_pk_bytes = point_to_bytes(eph_pk);
for i in 0..32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('EncryptedLogPayload', () => {
beforeAll(() => {
const incomingBodyPlaintext = randomBytes(128);
const contract = AztecAddress.random();
original = new EncryptedLogPayload(PLACEHOLDER_TAG, PLACEHOLDER_TAG, contract, incomingBodyPlaintext);
original = new EncryptedLogPayload(PLACEHOLDER_TAG, contract, incomingBodyPlaintext);

const secretKey = Fr.random();
const partialAddress = Fr.random();
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('EncryptedLogPayload', () => {
'00000001301640ceea758391b2e161c92c0513f129020f4125256afdae2646ce31099f5c10f48cd9eff7ae5b209c557c70de2e657ee79166868676b787e9417e19260e040fe46be583b71f4ab5b70c2657ff1d05cccf1d292a9369628d1a194f944e659900001027',
'hex',
);
const log = new EncryptedLogPayload(new Fr(0), new Fr(0), contract, plaintext);
const log = new EncryptedLogPayload(new Fr(0), contract, plaintext);

const ovskM = new GrumpkinScalar(0x1d7f6b3c491e99f32aad05c433301f3a2b4ed68de661ff8255d275ff94de6fc4n);
const ovKeys = getKeyValidationRequest(ovskM, contract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ const OUTGOING_BODY_SIZE = 144;
export class EncryptedLogPayload {
constructor(
/**
* Note discovery tag used by the recipient of the log.
* Note discovery tag.
*/
public readonly incomingTag: Fr,
/**
* Note discovery tag used by the sender of the log.
*/
public readonly outgoingTag: Fr,
public readonly tag: Fr,
/**
* Address of a contract that emitted the log.
*/
Expand Down Expand Up @@ -75,8 +71,7 @@ export class EncryptedLogPayload {
}

return serializeToBuffer(
this.incomingTag,
this.outgoingTag,
this.tag,
ephPk.toCompressedBuffer(),
incomingHeaderCiphertext,
outgoingHeaderCiphertext,
Expand Down Expand Up @@ -104,8 +99,7 @@ export class EncryptedLogPayload {
const reader = BufferReader.asReader(ciphertext);

try {
const incomingTag = reader.readObject(Fr);
const outgoingTag = reader.readObject(Fr);
const tag = reader.readObject(Fr);

const ephPk = Point.fromCompressedBuffer(reader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));

Expand All @@ -119,8 +113,7 @@ export class EncryptedLogPayload {
const incomingBodyPlaintext = decrypt(reader.readToEnd(), addressSecret, ephPk);

return new EncryptedLogPayload(
incomingTag,
outgoingTag,
tag,
AztecAddress.fromBuffer(incomingHeader),
incomingBodyPlaintext,
);
Expand Down Expand Up @@ -160,8 +153,7 @@ export class EncryptedLogPayload {
const reader = BufferReader.asReader(ciphertext);

try {
const incomingTag = reader.readObject(Fr);
const outgoingTag = reader.readObject(Fr);
const tag = reader.readObject(Fr);

const ephPk = Point.fromCompressedBuffer(reader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));

Expand All @@ -188,7 +180,7 @@ export class EncryptedLogPayload {
// Now we decrypt the incoming body using the ephSk and recipientAddressPoint
const incomingBody = decrypt(reader.readToEnd(), ephSk, recipientAddressPoint);

return new EncryptedLogPayload(incomingTag, outgoingTag, contractAddress, incomingBody);
return new EncryptedLogPayload(tag, contractAddress, incomingBody);
} catch (e: any) {
// Following error messages are expected to occur when decryption fails
if (
Expand All @@ -207,8 +199,7 @@ export class EncryptedLogPayload {

public toBuffer() {
return serializeToBuffer(
this.incomingTag,
this.outgoingTag,
this.tag,
this.contractAddress.toBuffer(),
this.incomingBodyPlaintext,
);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,6 @@ describe('Note Processor', () => {
});

function getRandomNoteLogPayload(app = AztecAddress.random()): EncryptedLogPayload {
return new EncryptedLogPayload(Fr.random(), Fr.random(), app, L1NotePayload.random(app).toIncomingBodyPlaintext());
return new EncryptedLogPayload(Fr.random(), app, L1NotePayload.random(app).toIncomingBodyPlaintext());
}
});

0 comments on commit f74e907

Please sign in to comment.