Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Emitting encrypted log by default #2926

Merged
merged 14 commits into from
Oct 20, 2023
233 changes: 119 additions & 114 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -1,158 +1,161 @@
{
"words": [
"tparam",
"abitype",
"accum",
"acir",
"acvm",
"archiver",
"asyncify",
"authwit",
"autonat",
"awslogs",
"awsvpc",
"aztecprotocol",
"barretenberg",
"bbfree",
"bbmalloc",
"bodyparser",
"bootnode",
"Brillig",
"Bufferable",
"bufs",
"buildkit",
"bytecodes",
"calldatacopy",
"callstack",
"callstacks",
"camelcase",
"cbind",
"cbinds",
"chainsafe",
"cheatcode",
"cheatcodes",
"checksummed",
"clonedeep",
"clonedeepwith",
"codegen",
"comlink",
"composability",
"concat",
"customizability",
"danlee",
"Daos",
"dbanks",
"decrementation",
"delegatecall",
"devs",
"diffie",
"direnv",
"dockerfiles",
"dockerhub",
"entrypoints",
"erc",
"fargate",
"filestat",
"flatmap",
"foundryup",
"fullpath",
"fuzzer",
"fuzzers",
"gitmodules",
"gitrepo",
"grumpkin",
"gtest",
"hardlinks",
"hasher",
"herskind",
"ierc",
"indexeddb",
"interruptible",
"isequal",
"jsons",
"Kademlia",
"keccak",
"keypairs",
"leveldb",
"leveldown",
"leveljs",
"libp",
"memdown",
"Merkle",
"messagebox",
"mimc",
"mktemp",
"mload",
"mockify",
"mplex",
"msgpack",
"muldiv",
"multivalue",
"muxers",
"Nargo",
"nixpkgs",
"noirup",
"nullifer",
"otterscan",
"outdir",
"overlayfs",
"pako",
"parallelizable",
"Pedersen",
"permissionless",
"persistable",
"pids",
"pkgs",
"Plookup",
"pnat",
"Pokeable",
"preauthenticated",
"preimage",
"preimages",
"prestat",
"productionify",
"protobuf",
"proxied",
"proxified",
"proxify",
"pubkey",
"pxes",
"quickstart",
"rahul",
"repr",
"rethrown",
"rollup",
"rollups",
"rushstack",
"schnorr",
"secp",
"sigchld",
"Signerless",
"siloes",
"sload",
"snakecase",
"solhint",
"struct",
"structs",
"viem",
"fullpath",
"unexclude",
"hardlinks",
"yarnrc",
"memdown",
"tsbuildinfo",
"leveldown",
"isequal",
"rushstack",
"messagebox",
"buildkit",
"unexcluded",
"devs",
"overlayfs",
"wasms",
"interruptible",
"clonedeep",
"callstack",
"callstacks",
"cheatcode",
"flatmap",
"toplevel",
"productionify",
"repr",
"bufs",
"aztecprotocol",
"dbanks",
"rahul",
"herskind",
"danlee",
"subrepo",
"suyash",
"diffie",
"bootnode",
"fargate",
"awslogs",
"awsvpc",
"multivalue",
"snakecase",
"upperfirst",
"authwit",
"nullifer",
"unshield",
"codegen",
"secp",
"accum",
"bytecodes",
"yamux",
"libp",
"mplex",
"protobuf",
"pnat",
"chainsafe",
"mockify",
"vals",
"pubkey",
"noirup",
"direnv",
"nixpkgs",
"outdir",
"pako",
"webassembly",
"asyncify",
"indexeddb",
"leveljs",
"filestat",
"prestat",
"toplevel",
"tparam",
"transferables",
"proxify",
"proxified",
"proxied",
"typeparam",
"preauthenticated",
"trivago",
"jsons",
"autonat",
"muxers",
"Kademlia",
"mimc",
"gitrepo",
"subrepo",
"typecheck",
"fuzzer",
"fuzzers",
"gtest",
"dockerfiles",
"gitmodules",
"dockerhub",
"utxo",
"sload",
"quickstart",
"otterscan",
"cheatcodes",
"permissionless",
"parallelizable",
"solhint",
"foundryup",
"concat",
"mload",
"calldatacopy",
"ierc",
"erc",
"bbmalloc",
"bbfree",
"archiver",
"sigchld",
"pids",
"comlink",
"checksummed",
"tsbuildinfo",
"tsdoc",
"muldiv",
"clonedeepwith",
"bodyparser",
"pkgs",
"mktemp",
"typecheck",
"typeparam",
"unexclude",
"unexcluded",
"unshield",
"unshielding",
"upperfirst",
"utxo",
"vals",
"viem",
"wasms",
"webassembly",
"workdir",
"leveldb"
"yamux",
"yarnrc"
],
"ignorePaths": [
"node_modules/",
Expand All @@ -174,5 +177,7 @@
"*.snap",
"package.json"
],
"flagWords": ["anonymous"]
"flagWords": [
"anonymous"
]
}
2 changes: 1 addition & 1 deletion docs/docs/concepts/foundation/accounts/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ In a future version, encryption keys will be differentiated between incoming and

An application in Aztec.nr can access the encryption public key for a given address using the oracle call `get_public_key`, which you can then use for calls such as `emit_encrypted_log`:

#include_code encrypted /yarn-project/aztec-nr/value-note/src/utils.nr rust
#include_code encrypted /yarn-project/aztec-nr/address-note/src/address_note.nr rust

:::info
In order to be able to provide the public encryption key for a given address, that public key needs to have been registered in advance. At the moment, there is no broadcasting mechanism for public keys, which means that you will need to manually register all addresses you intend to send encrypted notes to. You can do this via the `registerRecipient` method of the Private Execution Environment (PXE), callable either via aztec.js or the CLI.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/dev_docs/contracts/syntax/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ In the future we will allow emitting arbitrary information.

To emit encrypted logs first import the `emit_encrypted_log` utility function which wraps an [oracle](./functions.md#oracle-functions):

#include_code encrypted_import /yarn-project/aztec-nr/value-note/src/utils.nr rust
#include_code encrypted_import /yarn-project/aztec-nr/address-note/src/address_note.nr rust

Then you can call the function:

#include_code encrypted /yarn-project/aztec-nr/value-note/src/utils.nr rust
#include_code encrypted /yarn-project/aztec-nr/address-note/src/address_note.nr rust

### Processing Encrypted Events

Expand Down
39 changes: 35 additions & 4 deletions yarn-project/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use dep::aztec::note::note_interface::NoteInterface;
use dep::aztec::note::note_header::NoteHeader;
use dep::aztec::note::utils::compute_siloed_note_hash;
use dep::aztec::oracle::get_secret_key::get_secret_key;
// docs:start:encrypted_import
use dep::aztec::log::emit_encrypted_log;
// docs:end:encrypted_import
use dep::aztec::{
note::{
note_header::NoteHeader,
note_interface::NoteInterface,
utils::compute_siloed_note_hash,
},
oracle::{
get_secret_key::get_secret_key,
get_public_key::get_public_key,
},
context::PrivateContext,
};

global ADDRESS_NOTE_LEN: Field = 2;

Expand Down Expand Up @@ -39,6 +50,20 @@ impl AddressNote {
pub fn set_header(&mut self, header: NoteHeader) {
self.header = header;
}

// Broadcasts the note as an encrypted log on L1.
pub fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
// docs:start:encrypted
emit_encrypted_log(
context,
(*context).this_address(),
slot,
encryption_pub_key,
self.serialize(),
);
// docs:end:encrypted
}
}

fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> AddressNote {
Expand Down Expand Up @@ -70,11 +95,17 @@ fn set_header(note: &mut AddressNote, header: NoteHeader) {
note.set_header(header);
}

// Broadcasts the note as an encrypted log on L1.
fn broadcast(context: &mut PrivateContext, slot: Field, note: AddressNote) {
note.broadcast(context, slot);
}

global AddressNoteMethods = NoteInterface {
deserialize,
serialize,
compute_note_hash,
compute_nullifier,
get_header,
set_header,
broadcast,
};
Loading