Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
oracle::{
key_validation_request::get_key_validation_request, arguments, returns,
call_private_function::call_private_function_internal, header::get_header_at,
logs::{emit_encrypted_log, emit_encrypted_note_log, compute_encrypted_log},
logs::{emit_encrypted_log, emit_encrypted_note_log, compute_encrypted_note_log, compute_encrypted_log},
logs_traits::{LensForEncryptedLog, ToBytesForUnencryptedLog},
enqueue_public_function_call::{
enqueue_public_function_call_internal, set_public_teardown_function_call_internal,
Expand Down Expand Up @@ -338,7 +338,7 @@ impl PrivateContext {
let counter = self.next_counter();

// TODO(#1139 | #6408): perform encryption in the circuit
let encrypted_log: [u8; M] = compute_encrypted_log(contract_address, storage_slot, note_type_id, ivpk_m, preimage);
let encrypted_log: [u8; M] = compute_encrypted_note_log(contract_address, storage_slot, note_type_id, ivpk_m, preimage);
emit_encrypted_note_log(note_hash, encrypted_log, counter);

// Current unoptimized size of the encrypted log
Expand Down
22 changes: 21 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ unconstrained pub fn emit_encrypted_log<M>(encrypted_note: [u8; M], counter: u32
emit_encrypted_log_oracle(encrypted_note, counter)
}

// = 480 + 32 * N bytes
#[oracle(computeEncryptedNoteLog)]
fn compute_encrypted_note_log_oracle<N, M>(
_contract_address: AztecAddress,
_storage_slot: Field,
_note_type_id: Field,
_encryption_pub_key: GrumpkinPoint,
_preimage: [Field; N]
) -> [u8; M] {}

unconstrained pub fn compute_encrypted_note_log<N, M>(
contract_address: AztecAddress,
storage_slot: Field,
note_type_id: Field,
ivpk_m: GrumpkinPoint,
preimage: [Field; N]
) -> [u8; M] {
compute_encrypted_note_log_oracle(contract_address, storage_slot, note_type_id, ivpk_m, preimage)
}

// = 480 + 32 * N bytes
#[oracle(computeEncryptedLog)]
fn compute_encrypted_log_oracle<N, M>(
_contract_address: AztecAddress,
_storage_slot: Field,
_note_type_id: Field,
_encryption_pub_key: GrumpkinPoint,
_ivpk_m: GrumpkinPoint,
_preimage: [Field; N]
) -> [u8; M] {}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ members = [
"contracts/schnorr_single_key_account_contract",
"contracts/stateful_test_contract",
"contracts/test_contract",
"contracts/token_contract",
"contracts/log_test_contract",
"contracts/token_blacklist_contract",
"contracts/token_bridge_contract",
"contracts/uniswap_contract",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "log_test_contract"
authors = [""]
compiler_version = ">=0.25.0"
type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
value_note = { path = "../../../aztec-nr/value-note" }
token_portal_content_hash_lib = { path = "../token_portal_content_hash_lib" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
contract LogTest {

use dep::aztec::prelude::{
AztecAddress, EthAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
PrivateContext, PrivateImmutable, PrivateSet, SharedImmutable
};

use dep::aztec::protocol_types::{
abis::private_circuit_public_inputs::PrivateCircuitPublicInputs,
constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, CANONICAL_KEY_REGISTRY_ADDRESS},
traits::{Serialize, ToField, FromField}, grumpkin_point::GrumpkinPoint,
grumpkin_private_key::GrumpkinPrivateKey
};

use dep::aztec::encrypted_logs::header::EncryptedLogHeader;
use dep::aztec::encrypted_logs::incoming_body::EncryptedLogIncomingBody;
use dep::aztec::encrypted_logs::outgoing_body::EncryptedLogOutgoingBody;

use dep::aztec::note::constants::MAX_NOTES_PER_PAGE;

use dep::aztec::state_vars::{shared_mutable::SharedMutablePrivateGetter, map::derive_storage_slot_in_map};

use dep::aztec::{
keys::getters::{get_npk_m, get_ivpk_m, get_npk_m_hash},
context::inputs::private_context_inputs::PrivateContextInputs,
hash::{pedersen_hash, compute_secret_hash, ArgsHasher},
note::{
lifecycle::{create_note, destroy_note}, note_getter::{get_notes, view_notes},
note_getter_options::NoteStatus
},
deploy::deploy_contract as aztec_deploy_contract,
oracle::{encryption::aes128_encrypt, unsafe_rand::unsafe_rand}
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
use dep::value_note::value_note::ValueNote;

#[aztec(event)]
struct ExampleEvent {
value: Field,
}

#[aztec(storage)]
struct Storage {
example_set: PrivateSet<ValueNote>,
}

#[aztec(private)]
fn emit_encrypted_log() {
let msg_sender_ivpk_m = get_ivpk_m(&mut context, context.msg_sender());

context.encrypt_and_emit_log(context.this_address(), 0, 0, msg_sender_ivpk_m, [1, 2, 3]);
}
}
57 changes: 57 additions & 0 deletions yarn-project/end-to-end/src/e2e_logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { createAccounts } from '@aztec/accounts/testing';
import { type AccountWallet, AztecAddress, type AztecNode, Fr, type L2Block, type PXE, LogType, EncryptedL2BlockL2Logs } from '@aztec/aztec.js';
import {
CompleteAddress,
GeneratorIndex,
INITIAL_L2_BLOCK_NUM,
Point,
PublicKeys,
computeAppNullifierSecretKey,
deriveMasterNullifierSecretKey,
} from '@aztec/circuits.js';
import { siloNullifier } from '@aztec/circuits.js/hash';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { KeyRegistryContract, LogTestContract, TestContract } from '@aztec/noir-contracts.js';
import { getCanonicalKeyRegistryAddress } from '@aztec/protocol-contracts/key-registry';

import { jest } from '@jest/globals';

import { publicDeployAccounts, setup } from './fixtures/utils.js';

const TIMEOUT = 120_000;

const SHARED_MUTABLE_DELAY = 5;

describe('Logs', () => {
let pxe: PXE;
let aztecNode: AztecNode;
let logTestContract: LogTestContract;
jest.setTimeout(TIMEOUT);

let wallets: AccountWallet[];

let teardown: () => Promise<void>;

const account = CompleteAddress.random();

beforeAll(async () => {
({ aztecNode, teardown, pxe, wallets } = await setup(2));

await publicDeployAccounts(wallets[0], wallets.slice(0, 2));

logTestContract = await LogTestContract.deploy(wallets[0]).send().deployed();
});

afterAll(() => teardown());

describe('emits an encrypted log', () => {
it('works', async () => {
const res = await logTestContract.methods.emit_encrypted_log().send().wait();

const encryptedLogs = await aztecNode.getLogs(res.blockNumber!, 1, LogType.ENCRYPTED);
const unrolledLogs = EncryptedL2BlockL2Logs.unrollLogs(encryptedLogs);
console.log('Hello');
console.log(unrolledLogs.length);
})
});
});
23 changes: 23 additions & 0 deletions yarn-project/simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,29 @@ export class Oracle {
return bytes;
}

computeEncryptedNoteLog(
[contractAddress]: ACVMField[],
[storageSlot]: ACVMField[],
[noteTypeId]: ACVMField[],
[publicKeyX]: ACVMField[],
[publicKeyY]: ACVMField[],
preimage: ACVMField[],
): ACVMField[] {
const publicKey = new Point(fromACVMField(publicKeyX), fromACVMField(publicKeyY));
const encLog = this.typedOracle.computeEncryptedNoteLog(
AztecAddress.fromString(contractAddress),
Fr.fromString(storageSlot),
Fr.fromString(noteTypeId),
publicKey,
preimage.map(fromACVMField),
);
const bytes: ACVMField[] = [];
encLog.forEach(v => {
bytes.push(toACVMField(v));
});
return bytes;
}

emitUnencryptedLog(
[contractAddress]: ACVMField[],
[eventSelector]: ACVMField[],
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/simulator/src/acvm/oracle/typed_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ export abstract class TypedOracle {
throw new OracleMethodNotAvailableError('computeEncryptedLog');
}

computeEncryptedNoteLog(
_contractAddress: AztecAddress,
_storageSlot: Fr,
_noteTypeId: Fr,
_publicKey: PublicKey,
_preimage: Fr[],
): Buffer {
throw new OracleMethodNotAvailableError('computeEncryptedNoteLog');
}

emitUnencryptedLog(_log: UnencryptedL2Log, _counter: number): void {
throw new OracleMethodNotAvailableError('emitUnencryptedLog');
}
Expand Down
28 changes: 28 additions & 0 deletions yarn-project/simulator/src/client/client_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,34 @@ export class ClientExecutionContext extends ViewDataOracle {
this.noteCache.addNewLog(encryptedLog, noteHash);
}

/**
* Encrypt a note
* @param contractAddress - The contract address of the note.
* @param storageSlot - The storage slot the note is at.
* @param noteTypeId - The type ID of the note.
* @param ivpk - The master incoming viewing public key.
* @param preimage - The note preimage.
*/
public override computeEncryptedNoteLog(
contractAddress: AztecAddress,
storageSlot: Fr,
noteTypeId: Fr,
ivpk: Point,
preimage: Fr[],
) {
const note = new Note(preimage);
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
const taggedNote = new TaggedNote(l1NotePayload);

const ephSk = GrumpkinScalar.random();

// @todo Issue(#6410) Right now we are completely ignoring the outgoing log. Just drawing random data.
const ovsk = GrumpkinScalar.random();
const recipient = AztecAddress.random();

return taggedNote.encrypt(ephSk, recipient, ivpk, ovsk);
}

/**
* Encrypt a note
* @param contractAddress - The contract address of the note.
Expand Down