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 6 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,144 @@
contract KeyRegistry {
use dep::aztec::{
avm::hash::poseidon,
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,
GENERATOR_INDEX__PARTIAL_ADDRESS
},
},
};

global KEY_ROTATION_DELAY = 5;

#[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(
nullifier_public_key: Field,
incoming_public_key: Field,
outgoing_public_key: Field,
tagging_public_key: Field,
) {
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
assert((nullifier_public_key != 0) & (incoming_public_key != 0) & (outgoing_public_key != 0) & (tagging_public_key != 0));
let nullifier_entry = storage.nullifier_public_key_registry.at(context.msg_sender());
let incoming_entry = storage.nullifier_public_key_registry.at(context.msg_sender());
let outgoing_entry = storage.nullifier_public_key_registry.at(context.msg_sender());
let tagging_entry = storage.nullifier_public_key_registry.at(context.msg_sender());

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);
}

#[aztec(public)]
fn register_from_preimage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call this register and the other function rotate_nullifier_public_key. The preimage check is an implementation detail so I don't think it makes sense to have it in func name and I think we'll always want to rotate the keys only 1 by 1 so it doesn't make sense to have generic rotate_keys function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, addressed in 2b1b5c, along with all the other feedback. Thank you 🙏

address: AztecAddress,
contract_class_id: ContractClassId,
initialization_hash: Field,
salt: Field,
deployer: AztecAddress,
portal_contract_address: EthAddress,
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,
) {
assert((nullifier_public_key != 0) & (incoming_public_key != 0) & (outgoing_public_key != 0) & (tagging_public_key != 0));
context.call_public_function(
context.this_address(),
FunctionSelector::from_signature("assert_non_membership_public((Field))"),
[address.to_field()],
GasOpts::default()
).assert_empty();

let partial_address = PartialAddress::compute(
contract_class_id,
salt,
initialization_hash,
portal_contract_address,
deployer
);

// 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 = poseidon([
nullifier_public_key,
tagging_public_key,
incoming_public_key,
outgoing_public_key,
GENERATOR_INDEX__PARTIAL_ADDRESS as Field,
],
);

let computed_address = AztecAddress::from_field(
poseidon([
public_keys_hash.to_field(),
partial_address.to_field(),
GENERATOR_INDEX__CONTRACT_ADDRESS as Field,
],
)
);

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);
}

#[aztec(public)]
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
fn assert_non_membership_public(
address: AztecAddress
) {
let registry_entry = storage.nullifier_public_key_registry.at(address);
let nullifier_key = registry_entry.get_current_value_in_public();

assert(nullifier_key == 0);
}

#[aztec(private)]
fn assert_non_membership_private(
address: AztecAddress
) {
let registry_entry = storage.nullifier_public_key_registry.at(address);
let nullifier_key = registry_entry.get_current_value_in_private();

assert(nullifier_key == 0);
}

#[aztec(public)]
fn get_nullifying_public_key(
address: AztecAddress
) {
let registry_entry = storage.nullifier_public_key_registry.at(address);
registry_entry.get_current_value_in_public()
}
}
Loading