Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 24, 2023
1 parent 93cc396 commit f4988c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/docs/dev_docs/contracts/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<Tabs groupId="events">
<TabItem value="cli" label="Aztec CLI">
Expand All @@ -72,19 +80,11 @@ aztec-cli get-logs --from 5 --limit 1
</TabItem>
<TabItem value="js" label="Aztec.js">

#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

</TabItem>
</Tabs>

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.
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit f4988c1

Please sign in to comment.