From f4988c1fd3fb605c60fbe4e660ded9ed126ef4e2 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 24 Aug 2023 12:32:41 +0200 Subject: [PATCH] fixes after rebase --- docs/docs/dev_docs/contracts/events.md | 18 +++++++++--------- yarn-project/end-to-end/src/fixtures/utils.ts | 4 ++++ .../public_token_contract/src/main.nr | 6 ++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/docs/dev_docs/contracts/events.md b/docs/docs/dev_docs/contracts/events.md index 5eb174bbf47..e115cd4a277 100644 --- a/docs/docs/dev_docs/contracts/events.md +++ b/docs/docs/dev_docs/contracts/events.md @@ -61,6 +61,14 @@ Emitting unencrypted events from private function is a significant privacy leak ::: +To emit unencrypted logs first import the `emit_unencrypted_log` utility function inside your contract: + +#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + +Then you can call the function: + +#include_code unencrypted_log /yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + Once emitted, unencrypted events are stored in AztecNode and can be queried by anyone: @@ -72,19 +80,11 @@ aztec-cli get-logs --from 5 --limit 1 -#include_code logs /yarn-project/end-to-end/src/e2e_public_token_contract.test.ts typescript +#include_code get_logs /yarn-project/end-to-end/src/fixtures/utils.ts typescript -To emit unencrypted logs first import the `emit_unencrypted_log` utility function inside your contract: - -#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust - -Then you can call the function: - -#include_code unencrypted /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust - ### Costs All event data is pushed to Ethereum as calldata by the sequencer and for this reason the cost of emitting an event is non-trivial. diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 27f04ae7ff6..63b13b3c2a6 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -430,8 +430,12 @@ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async ( * @param logMessages - The set of expected log messages. */ export const expectUnencryptedLogsFromLastBlockToBe = async (rpc: AztecRPC, logMessages: string[]) => { + // docs:start:get_logs + // Get the latest block number to retrieve logs from const l2BlockNum = await rpc.getBlockNumber(); + // Get the unencrypted logs from the last block const unencryptedLogs = await rpc.getUnencryptedLogs(l2BlockNum, 1); + // docs:end:get_logs const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs); const asciiLogs = unrolledLogs.map(log => log.toString('ascii')); diff --git a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr index 6ddc646f951..9441e9951b8 100644 --- a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr @@ -8,7 +8,11 @@ contract PublicToken { PrivateContext, PublicContext }; + + // docs:start:unencrypted_import use dep::aztec::oracle::logs::emit_unencrypted_log; + // docs:end:unencrypted_import + use crate::storage::Storage; // Constructs the contract. @@ -30,8 +34,10 @@ contract PublicToken { let storage = Storage::init(); let recipient_balance = storage.balances.at(recipient); let new_amount = recipient_balance.read() + amount; + // docs:start:unencrypted_log // TODO: Remove return value. let _hash = emit_unencrypted_log("Coins minted"); + // docs:end:unencrypted_log recipient_balance.write(new_amount); context.return_values.push(new_amount);