Skip to content

Commit

Permalink
reverting incorrect changes + adding safety comments for get_contract…
Browse files Browse the repository at this point in the history
…_instance*
  • Loading branch information
benesjan committed Jan 8, 2025
1 parent 0686c36 commit d9308ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/aztec/src/initializer.nr
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ fn compute_unsiloed_contract_initialization_nullifier(address: AztecAddress) ->
address.to_field()
}

// Used in macros by `create_assert_correct_initializer_args` func.
pub fn assert_initialization_matches_address_preimage_public(context: PublicContext) {
let address = context.this_address();
let deployer = unsafe { get_contract_instance_deployer_avm(address).unwrap() };
let initialization_hash =
unsafe { get_contract_instance_initialization_hash_avm(address).unwrap() };
let deployer = get_contract_instance_deployer_avm(address).unwrap();
let initialization_hash = get_contract_instance_initialization_hash_avm(address).unwrap();
let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash());
assert(initialization_hash == expected_init, "Initialization hash does not match");
assert(
Expand All @@ -50,6 +50,7 @@ pub fn assert_initialization_matches_address_preimage_public(context: PublicCont
);
}

// Used in macros by `create_assert_correct_initializer_args` func.
pub fn assert_initialization_matches_address_preimage_private(context: PrivateContext) {
let address = context.this_address();
let instance = get_contract_instance(address);
Expand Down
33 changes: 17 additions & 16 deletions noir-projects/aztec-nr/aztec/src/oracle/get_contract_instance.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ unconstrained fn get_contract_instance_internal(

// NOTE: this is for use in private only
pub fn get_contract_instance(address: AztecAddress) -> ContractInstance {
let instance = unsafe {
//@safety The instance is verified against the contract address below.
ContractInstance::deserialize(get_contract_instance_internal(address))
};
let instance =
unsafe { ContractInstance::deserialize(get_contract_instance_internal(address)) };
// The to_address function combines all values in the instance object to produce an address, so by checking that we
// get the expected address we validate the entire struct.
assert_eq(instance.to_address(), address);
Expand Down Expand Up @@ -60,30 +58,33 @@ pub unconstrained fn get_contract_instance_initialization_hash_internal_avm(
get_contract_instance_initialization_hash_oracle_avm(address)
}

pub unconstrained fn get_contract_instance_deployer_avm(
address: AztecAddress,
) -> Option<AztecAddress> {
let (member, exists) = get_contract_instance_deployer_internal_avm(address);
pub fn get_contract_instance_deployer_avm(address: AztecAddress) -> Option<AztecAddress> {
let (member, exists) = unsafe {
//@safety AVM opcodes are constrained by the AVM itself
get_contract_instance_deployer_internal_avm(address)
};
if exists {
Option::some(AztecAddress::from_field(member))
} else {
Option::none()
}
}
pub unconstrained fn get_contract_instance_class_id_avm(
address: AztecAddress,
) -> Option<ContractClassId> {
let (member, exists) = get_contract_instance_class_id_internal_avm(address);
pub fn get_contract_instance_class_id_avm(address: AztecAddress) -> Option<ContractClassId> {
let (member, exists) = unsafe {
//@safety AVM opcodes are constrained by the AVM itself
get_contract_instance_class_id_internal_avm(address)
};
if exists {
Option::some(ContractClassId::from_field(member))
} else {
Option::none()
}
}
pub unconstrained fn get_contract_instance_initialization_hash_avm(
address: AztecAddress,
) -> Option<Field> {
let (member, exists) = get_contract_instance_initialization_hash_internal_avm(address);
pub fn get_contract_instance_initialization_hash_avm(address: AztecAddress) -> Option<Field> {
let (member, exists) = unsafe {
//@safety AVM opcodes are constrained by the AVM itself
get_contract_instance_initialization_hash_internal_avm(address)
};
if exists {
Option::some(member)
} else {
Expand Down

0 comments on commit d9308ca

Please sign in to comment.