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: constant addresses as addresses #8056

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_
*/
pub fn assert_inner_hash_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, inner_hash: Field) {
let result: Field = context.call_public_function(
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS),
CANONICAL_AUTH_REGISTRY_ADDRESS,
FunctionSelector::from_signature("consume((Field),Field)"),
[on_behalf_of.to_field(), inner_hash].as_slice(),
GasOpts::default()
Expand Down Expand Up @@ -356,7 +356,7 @@ pub fn compute_authwit_message_hash(consumer: AztecAddress, chain_id: Field, ver
*/
pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authorize: bool) {
context.call_public_function(
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS),
CANONICAL_AUTH_REGISTRY_ADDRESS,
FunctionSelector::from_signature("set_authorized(Field,bool)"),
[message_hash, authorize as Field].as_slice(),
GasOpts::default()
Expand All @@ -372,7 +372,7 @@ pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authoriz
*/
pub fn set_reject_all(context: &mut PublicContext, reject: bool) {
context.call_public_function(
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS),
CANONICAL_AUTH_REGISTRY_ADDRESS,
FunctionSelector::from_signature("set_reject_all(bool)"),
[context.this_address().to_field(), reject as Field].as_slice(),
GasOpts::default()
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/deploy.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) {
serialized_args[4] = universal_deploy as Field;

let _call_result = context.call_private_function(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
DEPLOYER_CONTRACT_ADDRESS,
FunctionSelector::from_field(0x7ebd3690),
serialized_args
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl ProveContractDeployment for Header {
fn prove_contract_deployment(self, contract_address: AztecAddress) {
// Compute deployment nullifier
let nullifier = compute_siloed_nullifier(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
DEPLOYER_CONTRACT_ADDRESS,
contract_address.to_field()
);

Expand All @@ -27,7 +27,7 @@ impl ProveContractNonDeployment for Header {
fn prove_contract_non_deployment(self, contract_address: AztecAddress) {
// Compute deployment nullifier
let nullifier = compute_siloed_nullifier(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
DEPLOYER_CONTRACT_ADDRESS,
contract_address.to_field()
);

Expand Down
10 changes: 2 additions & 8 deletions noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ fn key_registry_hash_public_historical_read(historical_header: Header, account:
// (prior to siloing!), we simply add the length to the base slot to get the last element.
let hash_storage_slot = keys_storage_slot + PUBLIC_KEYS_LENGTH as Field;

historical_header.public_storage_historical_read(
hash_storage_slot,
AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS)
)
historical_header.public_storage_historical_read(hash_storage_slot, CANONICAL_KEY_REGISTRY_ADDRESS)
}

unconstrained fn key_registry_get_stored_keys_hint(account: AztecAddress, block_number: u32) -> PublicKeys {
Expand All @@ -105,10 +102,7 @@ unconstrained fn key_registry_get_stored_keys_hint(account: AztecAddress, block_

// TODO (#7524): call the unconstrained KeyRegistry.get_current_keys() function instead

let context = UnconstrainedContext::at_historical(
AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS),
block_number
);
let context = UnconstrainedContext::at_historical(CANONICAL_KEY_REGISTRY_ADDRESS, block_number);
let keys_storage = Map::new(
context,
KEY_REGISTRY_STORAGE_SLOT,
Expand Down
14 changes: 10 additions & 4 deletions noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ pub fn store_master_key(key_index: Field, address: AztecAddress, key: Point) {
let x_coordinate_derived_slot = derive_storage_slot_in_map(x_coordinate_map_slot, address);
let y_coordinate_derived_slot = derive_storage_slot_in_map(y_coordinate_map_slot, address);

let canonical_registry_address = AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS);

cheatcodes::direct_storage_write(canonical_registry_address, x_coordinate_derived_slot, [key.x]);
cheatcodes::direct_storage_write(canonical_registry_address, y_coordinate_derived_slot, [key.y]);
cheatcodes::direct_storage_write(
CANONICAL_KEY_REGISTRY_ADDRESS,
x_coordinate_derived_slot,
[key.x]
);
cheatcodes::direct_storage_write(
CANONICAL_KEY_REGISTRY_ADDRESS,
y_coordinate_derived_slot,
[key.y]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ contract FeeJuice {
context.end_setup();

// Register class and publicly deploy contract
let _register = ContractClassRegisterer::at(AztecAddress::from_field(REGISTERER_CONTRACT_ADDRESS)).register(
let _register = ContractClassRegisterer::at(REGISTERER_CONTRACT_ADDRESS).register(
artifact_hash,
private_functions_root,
public_bytecode_commitment
).call(&mut context);
let _deploy = ContractInstanceDeployer::at(AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS)).deploy(
let _deploy = ContractInstanceDeployer::at(DEPLOYER_CONTRACT_ADDRESS).deploy(
instance.salt,
instance.contract_class_id,
instance.initialization_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,11 @@ fn insert_public_data_update_requests(

fn compute_fee_payer_fee_juice_balance_leaf_slot(fee_payer: AztecAddress) -> Field {
let balances_slot_in_fee_juice_contract = 1;
let fee_juice = AztecAddress::from_field(FEE_JUICE_ADDRESS);
let fee_payer_balance_slot_in_fee_juice_contract = derive_storage_slot_in_map(balances_slot_in_fee_juice_contract, fee_payer);
compute_public_data_tree_index(fee_juice, fee_payer_balance_slot_in_fee_juice_contract)
compute_public_data_tree_index(
FEE_JUICE_ADDRESS,
fee_payer_balance_slot_in_fee_juice_contract
)
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::address::AztecAddress;

global MAX_FIELD_VALUE: Field = 21888242871839275222246405745257275088548364400416034343698204186575808495616;
global ARGS_LENGTH: u32 = 16;

Expand Down Expand Up @@ -178,11 +180,11 @@ global L2_GAS_PER_NOTE_HASH: u32 = 32;
global L2_GAS_PER_NULLIFIER: u32 = 64;

// CANONICAL CONTRACT ADDRESSES
global CANONICAL_KEY_REGISTRY_ADDRESS = 0x2ee3f8c67efa88f9e6fb44242f1e9dcc0f9a6752ded07af0d9fac3875a61d421;
global CANONICAL_AUTH_REGISTRY_ADDRESS = 0x24877c50868f86712240eb535d90d1c97403d074805dd3758c3aecb02958f8d4;
global DEPLOYER_CONTRACT_ADDRESS = 0x2ab1a2bd6d07d8d61ea56d85861446349e52c6b7c0612b702cb1e6db6ad0b089;
global REGISTERER_CONTRACT_ADDRESS = 0x05d15342d76e46e5be07d3cda0d753158431cdc5e39d29ce4e8fe1f5c070564a;
global FEE_JUICE_ADDRESS = 0x16a83e3395bc921a2441db55dce24f0e0932636901a2e676fa68b9b2b9a644c1;
global CANONICAL_KEY_REGISTRY_ADDRESS = AztecAddress::from_field(0x2ee3f8c67efa88f9e6fb44242f1e9dcc0f9a6752ded07af0d9fac3875a61d421);
global CANONICAL_AUTH_REGISTRY_ADDRESS = AztecAddress::from_field(0x24877c50868f86712240eb535d90d1c97403d074805dd3758c3aecb02958f8d4);
global DEPLOYER_CONTRACT_ADDRESS = AztecAddress::from_field(0x2ab1a2bd6d07d8d61ea56d85861446349e52c6b7c0612b702cb1e6db6ad0b089);
global REGISTERER_CONTRACT_ADDRESS = AztecAddress::from_field(0x05d15342d76e46e5be07d3cda0d753158431cdc5e39d29ce4e8fe1f5c070564a);
global FEE_JUICE_ADDRESS = AztecAddress::from_field(0x16a83e3395bc921a2441db55dce24f0e0932636901a2e676fa68b9b2b9a644c1);

// LENGTH OF STRUCTS SERIALIZED TO FIELDS
global AZTEC_ADDRESS_LENGTH = 1;
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/circuits.js/src/scripts/constants.in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ function parseNoirFile(fileContent: string): ParsedContent {

if (!name || !value) {
// eslint-disable-next-line no-console
console.warn(`Unknown content: ${line}`);
if (!line.includes('use crate')) {
console.warn(`Unknown content: ${line}`);
}
return;
}

Expand Down Expand Up @@ -327,6 +329,8 @@ function evaluateExpressions(expressions: [string, string][]): { [key: string]:
// Remove 'as u8' and 'as u32' castings
.replaceAll(' as u8', '')
.replaceAll(' as u32', '')
// Remove the 'AztecAddress::from_field(...)' pattern
.replace(/AztecAddress::from_field\((0x[a-fA-F0-9]+)\)/g, '$1')
// We make some space around the parentheses, so that constant numbers are still split.
.replace(/\(/g, '( ')
.replace(/\)/g, ' )')
Expand Down
Loading