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: implement canonical key registry 5609 and implement shared mutable getter from another contract 5689 #5723

Merged
merged 40 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c149e2c
initial
sklppy88 Apr 11, 2024
7365b17
test
sklppy88 Apr 12, 2024
4549dd8
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 12, 2024
a1907b0
go
sklppy88 Apr 12, 2024
01bbd3b
sadf
sklppy88 Apr 12, 2024
f976ac0
adf
sklppy88 Apr 12, 2024
8545e23
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 12, 2024
f742400
test
sklppy88 Apr 12, 2024
6a86b9d
fix
sklppy88 Apr 12, 2024
b58da64
fix
sklppy88 Apr 12, 2024
32a24e8
fix ci
sklppy88 Apr 12, 2024
6032daa
addressing changes
sklppy88 Apr 15, 2024
600ac9a
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 15, 2024
cbda439
feat: add shared mutable access from external contract #5689 (#5758)
sklppy88 Apr 15, 2024
ae19d83
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 15, 2024
c75dc4d
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 15, 2024
8270e04
fix
sklppy88 Apr 15, 2024
a84c9bd
fix
sklppy88 Apr 15, 2024
ed2466d
fix all
sklppy88 Apr 16, 2024
ac9adc3
Update cli_docs_sandbox.test.ts
sklppy88 Apr 16, 2024
9d3c831
Update cli_docs_sandbox.test.ts
sklppy88 Apr 16, 2024
9e184de
expand comments
sklppy88 Apr 16, 2024
192d870
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 16, 2024
bf4529a
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 16, 2024
d39ac15
address comments
sklppy88 Apr 16, 2024
442d745
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 16, 2024
634c15b
yarn format
sklppy88 Apr 17, 2024
d663fa8
test
sklppy88 Apr 17, 2024
9ab61ba
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
2f7e492
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
d9e61c7
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
51180e3
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
4918f41
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
8867e5e
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
78093cd
Update yarn-project/end-to-end/src/e2e_key_registry.test.ts
sklppy88 Apr 17, 2024
2b1b5cb
address comments
sklppy88 Apr 17, 2024
b655e76
yarn format
sklppy88 Apr 17, 2024
bb4b7cb
fix
sklppy88 Apr 17, 2024
8666545
Merge branch 'master' into ek/feat/implement-key-registry
sklppy88 Apr 17, 2024
96ed013
yarn fmt
sklppy88 Apr 17, 2024
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
1 change: 1 addition & 0 deletions noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"contracts/escrow_contract",
"contracts/gas_token_contract",
"contracts/import_test_contract",
"contracts/key_registry_contract",
"contracts/inclusion_proofs_contract",
"contracts/lending_contract",
"contracts/parent_contract",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "key_registry_contract"
authors = [""]
compiler_version = ">=0.25.0"
type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
contract KeyRegistry {
use dep::std::hash::poseidon2::Poseidon2::hash as poseidon2_hash;
use dep::aztec::{
context::gas::GasOpts,
state_vars::{
SharedMutable,
Map
},
protocol_types::{
abis::function_selector::FunctionSelector,
contract_class_id::ContractClassId,
address::{
AztecAddress,
EthAddress,
PublicKeysHash,
PartialAddress,
},
constants::{
GENERATOR_INDEX__CONTRACT_ADDRESS_V1,
GENERATOR_INDEX__PUBLIC_KEYS_HASH
},
traits::{
Serialize,
Deserialize,
}
},
};

global KEY_ROTATION_DELAY = 5;

struct PublicKeys {
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
nullifier_public_key: Field,
incoming_public_key: Field,
outgoing_public_key: Field,
tagging_public_key: Field,
}

impl Serialize<4> for PublicKeys {
fn serialize(self: Self) -> [Field; 4] {
[self.nullifier_public_key, self.incoming_public_key, self.outgoing_public_key, self.tagging_public_key]
}
}

impl Deserialize<4> for PublicKeys {
fn deserialize(fields: [Field; 4]) -> Self {
PublicKeys {
nullifier_public_key: fields[0],
incoming_public_key: fields[1],
outgoing_public_key: fields[2],
tagging_public_key: fields[3],
}
}
}

#[aztec(storage)]
struct Storage {
nullifier_public_key_registry: Map<AztecAddress, SharedMutable<Field, KEY_ROTATION_DELAY>>,
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
incoming_public_key_registry: Map<AztecAddress, SharedMutable<Field, KEY_ROTATION_DELAY>>,
outgoing_public_key_registry: Map<AztecAddress, SharedMutable<Field, KEY_ROTATION_DELAY>>,
tagging_public_key_registry: Map<AztecAddress, SharedMutable<Field, KEY_ROTATION_DELAY>>,
}

#[aztec(public)]
fn register(
address: AztecAddress,
partial_address: PartialAddress,
public_keys: PublicKeys,
) {
let PublicKeys {
nullifier_public_key,
incoming_public_key,
outgoing_public_key,
tagging_public_key
} = public_keys;

assert((nullifier_public_key != 0) & (incoming_public_key != 0) & (outgoing_public_key != 0) & (tagging_public_key != 0));

// TODO (ek): Do it below after refactoring all public_keys_hash_elemtns
// let public_keys_hash = PublicKeysHash::compute(nullifier_public_key, tagging_public_key, incoming_public_key, outgoing_public_key);
// let address = AztecAddress::compute(public_keys_hash, partial_address);
let public_keys_hash = poseidon2_hash([
nullifier_public_key,
tagging_public_key,
incoming_public_key,
outgoing_public_key,
GENERATOR_INDEX__PUBLIC_KEYS_HASH,
],
5
);

let computed_address = AztecAddress::from_field(
poseidon2_hash([
public_keys_hash.to_field(),
partial_address.to_field(),
GENERATOR_INDEX__CONTRACT_ADDRESS_V1 as Field,
],
3
)
);

assert(computed_address.eq(address));

let nullifier_entry = storage.nullifier_public_key_registry.at(address);
let incoming_entry = storage.nullifier_public_key_registry.at(address);
let outgoing_entry = storage.nullifier_public_key_registry.at(address);
let tagging_entry = storage.nullifier_public_key_registry.at(address);
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved

nullifier_entry.schedule_value_change(nullifier_public_key);
incoming_entry.schedule_value_change(incoming_public_key);
outgoing_entry.schedule_value_change(outgoing_public_key);
tagging_entry.schedule_value_change(tagging_public_key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
eth_address::EthAddress, salted_initialization_hash::SaltedInitializationHash,
aztec_address::AztecAddress
},
constants::GENERATOR_INDEX__PARTIAL_ADDRESS, contract_class_id::ContractClassId,
hash::pedersen_hash, traits::ToField
constants::{GENERATOR_INDEX__PARTIAL_ADDRESS, AZTEC_ADDRESS_LENGTH}, contract_class_id::ContractClassId,
hash::pedersen_hash, traits::{ToField, FromField, Serialize, Deserialize}
};

// Partial address
Expand All @@ -18,6 +18,18 @@ impl ToField for PartialAddress {
}
}

impl Serialize<AZTEC_ADDRESS_LENGTH> for PartialAddress {
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
fn serialize(self: Self) -> [Field; AZTEC_ADDRESS_LENGTH] {
[self.to_field()]
}
}

impl Deserialize<AZTEC_ADDRESS_LENGTH> for PartialAddress {
fn deserialize(fields: [Field; AZTEC_ADDRESS_LENGTH]) -> Self {
PartialAddress { inner: fields[0] }
}
}

impl PartialAddress {
pub fn from_field(field: Field) -> Self {
Self { inner: field }
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/src/cli_docs_sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ FPCContractArtifact
GasTokenContractArtifact
ImportTestContractArtifact
InclusionProofsContractArtifact
KeyRegistryContractArtifact
LendingContractArtifact
MultiCallEntrypointContractArtifact
ParentContractArtifact
Expand Down
Loading