Skip to content

Commit

Permalink
chore: swap pub and unconstrained in function signatures (#9237)
Browse files Browse the repository at this point in the history
This PR allows `pub unconstrained fn` which is preferred over
`unconstrained pub fn`
  • Loading branch information
TomAFrench authored Oct 14, 2024
1 parent 8e66ef9 commit 1c7e627
Show file tree
Hide file tree
Showing 89 changed files with 188 additions and 166 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/auth_witness.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ unconstrained fn get_auth_witness_oracle<let N: u32>(_message_hash: Field) -> [F
* @param message_hash The hash of the message for which the `auth_witness` is to be fetched.
* @return The `auth_witness` for the given `message_hash` as Field array.
*/
unconstrained pub fn get_auth_witness<let N: u32>(message_hash: Field) -> [Field; N] {
pub unconstrained fn get_auth_witness<let N: u32>(message_hash: Field) -> [Field; N] {
get_auth_witness_oracle(message_hash)
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ unconstrained fn call_static<let RET_SIZE: u32>(
call_static_opcode(gas, address, args, function_selector)
}

unconstrained pub fn calldata_copy<let N: u32>(cdoffset: u32, copy_size: u32) -> [Field; N] {
pub unconstrained fn calldata_copy<let N: u32>(cdoffset: u32, copy_size: u32) -> [Field; N] {
calldata_copy_opcode(cdoffset, copy_size)
}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use crate::{

mod test;

unconstrained pub fn get_nsk_app(npk_m_hash: Field) -> Field {
pub unconstrained fn get_nsk_app(npk_m_hash: Field) -> Field {
get_key_validation_request(npk_m_hash, NULLIFIER_INDEX).sk_app
}

// A helper function that gets app-siloed outgoing viewing key for a given `ovpk_m_hash`. This function is used
// in unconstrained contexts only - when computing unconstrained note logs. The safe alternative is `request_ovsk_app`
// function defined on `PrivateContext`.
unconstrained pub fn get_ovsk_app(ovpk_m_hash: Field) -> Field {
pub unconstrained fn get_ovsk_app(ovpk_m_hash: Field) -> Field {
get_key_validation_request(ovpk_m_hash, OUTGOING_INDEX).sk_app
}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/macros/dispatch/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub comptime fn generate_public_dispatch(m: Module) -> Quoted {
// functions having this attribute. However, the public MACRO will
// handle the public_dispatch function specially and do nothing.
#[public]
unconstrained pub fn public_dispatch(selector: Field) {
pub unconstrained fn public_dispatch(selector: Field) {
$dispatch
}
};
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ unconstrained fn get_notes_internal<Note, let N: u32, PREPROCESSOR_ARGS, FILTER_
apply_preprocessor(opt_notes, options.preprocessor, options.preprocessor_args)
}

unconstrained pub fn view_notes<Note, let N: u32>(
pub unconstrained fn view_notes<Note, let N: u32>(
storage_slot: Field,
options: NoteViewerOptions<Note, N>
) -> BoundedVec<Note, MAX_NOTES_PER_PAGE> where Note: NoteInterface<N> {
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn compute_note_hash_for_nullify<Note, let N: u32>(note: Note) -> Field wher
compute_note_hash_for_nullify_internal(note, note_hash_for_read_request)
}

unconstrained pub fn compute_note_hash_and_optionally_a_nullifier<T, let N: u32, let S: u32>(
pub unconstrained fn compute_note_hash_and_optionally_a_nullifier<T, let N: u32, let S: u32>(
deserialize_content: fn([Field; N]) -> T,
note_header: NoteHeader,
compute_nullifier: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unconstrained fn call_private_function_oracle(
_is_delegate_call: bool
) -> [Field; 2] {}

unconstrained pub fn call_private_function_internal(
pub unconstrained fn call_private_function_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unconstrained fn enqueue_public_function_call_oracle(
_is_delegate_call: bool
) -> Field {}

unconstrained pub fn enqueue_public_function_call_internal(
pub unconstrained fn enqueue_public_function_call_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
Expand Down Expand Up @@ -38,7 +38,7 @@ unconstrained fn set_public_teardown_function_call_oracle(
_is_delegate_call: bool
) -> Field {}

unconstrained pub fn set_public_teardown_function_call_internal(
pub unconstrained fn set_public_teardown_function_call_internal(
contract_address: AztecAddress,
function_selector: FunctionSelector,
args_hash: Field,
Expand All @@ -62,7 +62,7 @@ pub fn notify_set_min_revertible_side_effect_counter(counter: u32) {
};
}

unconstrained pub fn notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter: u32) {
pub unconstrained fn notify_set_min_revertible_side_effect_counter_oracle_wrapper(counter: u32) {
notify_set_min_revertible_side_effect_counter_oracle(counter);
}

Expand Down
8 changes: 4 additions & 4 deletions noir-projects/aztec-nr/aztec/src/oracle/execution.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ unconstrained fn get_chain_id_oracle() -> Field {}
#[oracle(getVersion)]
unconstrained fn get_version_oracle() -> Field {}

unconstrained pub fn get_contract_address() -> AztecAddress {
pub unconstrained fn get_contract_address() -> AztecAddress {
get_contract_address_oracle()
}

unconstrained pub fn get_block_number() -> u32 {
pub unconstrained fn get_block_number() -> u32 {
get_block_number_oracle()
}

unconstrained pub fn get_chain_id() -> Field {
pub unconstrained fn get_chain_id() -> Field {
get_chain_id_oracle()
}

unconstrained pub fn get_version() -> Field {
pub unconstrained fn get_version() -> Field {
get_version_oracle()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ unconstrained fn get_contract_instance_internal(address: AztecAddress) -> [Field
get_contract_instance_oracle(address)
}

unconstrained pub fn get_contract_instance_internal_avm(address: AztecAddress) -> [Field; CONTRACT_INSTANCE_LENGTH + 1] {
pub unconstrained fn get_contract_instance_internal_avm(address: AztecAddress) -> [Field; CONTRACT_INSTANCE_LENGTH + 1] {
get_contract_instance_oracle_avm(address)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::protocol_types::{address::AztecAddress, constants::L1_TO_L2_MSG_TREE_HE

/// Returns the leaf index and sibling path of an entry in the L1 to L2 messaging tree, which can then be used to prove
/// its existence.
unconstrained pub fn get_l1_to_l2_membership_witness(
pub unconstrained fn get_l1_to_l2_membership_witness(
contract_address: AztecAddress,
message_hash: Field,
secret: Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unconstrained fn get_membership_witness_oracle<let M: u32>(
_leaf_value: Field
) -> [Field; M] {}

unconstrained pub fn get_membership_witness<let N: u32, let M: u32>(
pub unconstrained fn get_membership_witness<let N: u32, let M: u32>(
block_number: u32,
tree_id: Field,
leaf_value: Field
Expand All @@ -33,7 +33,7 @@ unconstrained pub fn get_membership_witness<let N: u32, let M: u32>(

// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr

unconstrained pub fn get_note_hash_membership_witness(
pub unconstrained fn get_note_hash_membership_witness(
block_number: u32,
leaf_value: Field
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
Expand All @@ -43,7 +43,7 @@ unconstrained pub fn get_note_hash_membership_witness(
// There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership
// witness for a value in the public data tree.

unconstrained pub fn get_archive_membership_witness(
pub unconstrained fn get_archive_membership_witness(
block_number: u32,
leaf_value: Field
) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ unconstrained fn get_low_nullifier_membership_witness_oracle(

// Nullifier here refers to the nullifier we are looking to get non-inclusion proof for (by proving that a lower
// nullifier's next_value is bigger than the nullifier)
unconstrained pub fn get_low_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness {
pub unconstrained fn get_low_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness {
let fields = get_low_nullifier_membership_witness_oracle(block_number, nullifier);
NullifierMembershipWitness::deserialize(fields)
}
Expand All @@ -48,7 +48,7 @@ unconstrained fn get_nullifier_membership_witness_oracle(

// Nullifier here refers to the nullifier we are looking to get non-inclusion proof for (by proving that a lower
// nullifier's next_value is bigger than the nullifier)
unconstrained pub fn get_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness {
pub unconstrained fn get_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness {
let fields = get_nullifier_membership_witness_oracle(block_number, nullifier);
NullifierMembershipWitness::deserialize(fields)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ unconstrained fn get_public_data_witness_oracle(
_public_data_tree_index: Field
) -> [Field; PUBLIC_DATA_WITNESS] {}

unconstrained pub fn get_public_data_witness(
pub unconstrained fn get_public_data_witness(
block_number: u32,
public_data_tree_index: Field
) -> PublicDataWitness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ unconstrained fn get_sibling_path_oracle<let N: u32>(
_leaf_index: Field
) -> [Field; N] {}

unconstrained pub fn get_sibling_path<let N: u32>(block_number: u32, tree_id: Field, leaf_index: Field) -> [Field; N] {
pub unconstrained fn get_sibling_path<let N: u32>(block_number: u32, tree_id: Field, leaf_index: Field) -> [Field; N] {
let value: [Field; N] = get_sibling_path_oracle(block_number, tree_id, leaf_index);
value
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::test::helpers::test_environment::TestEnvironment;
#[oracle(getHeader)]
unconstrained fn get_header_at_oracle(_block_number: u32) -> [Field; HEADER_LENGTH] {}

unconstrained pub fn get_header_at_internal(block_number: u32) -> Header {
pub unconstrained fn get_header_at_internal(block_number: u32) -> Header {
let header = get_header_at_oracle(block_number);
Header::deserialize(header)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ unconstrained fn get_key_validation_request_internal(
KeyValidationRequest::deserialize(result)
}

unconstrained pub fn get_key_validation_request(
pub unconstrained fn get_key_validation_request(
pk_m_hash: Field,
key_index: Field
) -> KeyValidationRequest {
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::protocol_types::{
#[oracle(getPublicKeysAndPartialAddress)]
unconstrained fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> [Field; 13] {}

unconstrained pub fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, PartialAddress) {
pub unconstrained fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, PartialAddress) {
let result = get_public_keys_and_partial_address_oracle(address);

let keys = PublicKeys {
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ unconstrained fn emit_unencrypted_log_private_oracle_wrapper<T>(contract_address

/// Temporary substitute for `emit_unencrypted_log_private` that is used for handling contract class registration. This
/// variant returns the log hash, which would be too large to compute inside a circuit.
unconstrained pub fn emit_contract_class_unencrypted_log_private<let N: u32>(
pub unconstrained fn emit_contract_class_unencrypted_log_private<let N: u32>(
contract_address: AztecAddress,
message: [Field; N],
counter: u32
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ unconstrained fn get_notes_oracle_wrapper<let N: u32, let S: u32>(
)
}

unconstrained pub fn get_notes<Note, let N: u32, let M: u32, let S: u32, let NS: u32>(
pub unconstrained fn get_notes<Note, let N: u32, let M: u32, let S: u32, let NS: u32>(
storage_slot: Field,
num_selects: u8,
select_by_indexes: [u8; M],
Expand Down Expand Up @@ -175,7 +175,7 @@ unconstrained pub fn get_notes<Note, let N: u32, let M: u32, let S: u32, let NS:
/// nullifier, but a `false` value should not be relied upon since other transactions may emit this nullifier before the
/// current transaction is included in a block. While this might seem of little use at first, certain design patterns
/// benefit from this abstraction (see e.g. `PrivateMutable`).
unconstrained pub fn check_nullifier_exists(inner_nullifier: Field) -> bool {
pub unconstrained fn check_nullifier_exists(inner_nullifier: Field) -> bool {
check_nullifier_exists_oracle(inner_nullifier) == 1
}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/random.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// truly random: we assume that the oracle is cooperating and returning random values.
/// In some applications this behavior might not be acceptable and other techniques might be more suitable, such as
/// producing pseudo-random values by hashing values outside of user control (like block hashes) or secrets.
unconstrained pub fn random() -> Field {
pub unconstrained fn random() -> Field {
rand_oracle()
}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/returns.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub fn pack_returns(returns: [Field]) {
};
}

unconstrained pub fn pack_returns_oracle_wrapper(returns: [Field]) {
pub unconstrained fn pack_returns_oracle_wrapper(returns: [Field]) {
let _ = pack_returns_oracle(returns);
}

unconstrained pub fn unpack_returns<let N: u32>(return_hash: Field) -> [Field; N] {
pub unconstrained fn unpack_returns<let N: u32>(return_hash: Field) -> [Field; N] {
unpack_returns_oracle(return_hash)
}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/storage.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::protocol_types::{address::AztecAddress, traits::Deserialize};
#[oracle(storageRead)]
unconstrained fn storage_read_oracle<let N: u32>(address: Field, storage_slot: Field, block_number: Field, length: Field) -> [Field; N] {}

unconstrained pub fn raw_storage_read<let N: u32>(
pub unconstrained fn raw_storage_read<let N: u32>(
address: AztecAddress,
storage_slot: Field,
block_number: u32
Expand All @@ -16,7 +16,7 @@ unconstrained pub fn raw_storage_read<let N: u32>(
)
}

unconstrained pub fn storage_read<T, let N: u32>(
pub unconstrained fn storage_read<T, let N: u32>(
address: AztecAddress,
storage_slot: Field,
block_number: u32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ impl<Note> PrivateImmutable<Note, &mut PrivateContext> {

impl<Note> PrivateImmutable<Note, UnconstrainedContext> {
// docs:start:is_initialized
unconstrained pub fn is_initialized(self) -> bool {
pub unconstrained fn is_initialized(self) -> bool {
let nullifier = self.compute_initialization_nullifier();
check_nullifier_exists(nullifier)
}
// docs:end:is_initialized

// view_note does not actually use the context, but it calls oracles that are only available in private
// docs:start:view_note
unconstrained pub fn view_note<let N: u32>(self) -> Note where Note: NoteInterface<N> + NullifiableNote {
pub unconstrained fn view_note<let N: u32>(self) -> Note where Note: NoteInterface<N> + NullifiableNote {
let mut options = NoteViewerOptions::new();
view_notes(self.storage_slot, options.set_limit(1)).get(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ impl<Note, let N: u32> PrivateMutable<Note, &mut PrivateContext> where Note: Not
}

impl<Note, let N: u32> PrivateMutable<Note, UnconstrainedContext> where Note: NoteInterface<N> + NullifiableNote {
unconstrained pub fn is_initialized(self) -> bool {
pub unconstrained fn is_initialized(self) -> bool {
let nullifier = self.compute_initialization_nullifier();
check_nullifier_exists(nullifier)
}

// docs:start:view_note
unconstrained pub fn view_note(self) -> Note {
pub unconstrained fn view_note(self) -> Note {
let mut options = NoteViewerOptions::new();
view_notes(self.storage_slot, options.set_limit(1)).get(0)
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<Note, let N: u32> PrivateSet<Note, &mut PrivateContext> where Note: NoteInt

impl<Note, let N: u32> PrivateSet<Note, UnconstrainedContext> where Note: NoteInterface<N> + NullifiableNote {
// docs:start:view_notes
unconstrained pub fn view_notes(
pub unconstrained fn view_notes(
self,
options: NoteViewerOptions<Note, N>
) -> BoundedVec<Note, MAX_NOTES_PER_PAGE> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl <T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, &mut PublicContext> where
}

impl<T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, UnconstrainedContext>where T: Deserialize<T_SERIALIZED_LEN> {
unconstrained pub fn read(self) -> T {
pub unconstrained fn read(self) -> T {
self.context.storage_read(self.storage_slot)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T, let T_SERIALIZED_LEN: u32> PublicMutable<T, &mut PublicContext> where T:
}

impl<T, let T_SERIALIZED_LEN: u32> PublicMutable<T, UnconstrainedContext> where T: Deserialize<T_SERIALIZED_LEN> {
unconstrained pub fn read(self) -> T {
pub unconstrained fn read(self) -> T {
self.context.storage_read(self.storage_slot)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T, let T_SERIALIZED_LEN: u32> SharedImmutable<T, &mut PublicContext> where
}

impl<T, let T_SERIALIZED_LEN: u32> SharedImmutable<T, UnconstrainedContext> where T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN> {
unconstrained pub fn read_public(self) -> T {
pub unconstrained fn read_public(self) -> T {
self.context.storage_read(self.storage_slot)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<T, let INITIAL_DELAY: u32> SharedMutable<T, INITIAL_DELAY, &mut PrivateCont
}

impl<T, let INITIAL_DELAY: u32> SharedMutable<T, INITIAL_DELAY, UnconstrainedContext> where T: ToField + FromField + Eq {
unconstrained pub fn get_current_value_in_unconstrained(self) -> T {
pub unconstrained fn get_current_value_in_unconstrained(self) -> T {
let block_number = self.context.block_number() as u32;
self.read_value_change().get_current_at(block_number)
}
Expand Down
Loading

0 comments on commit 1c7e627

Please sign in to comment.