Skip to content

Commit

Permalink
chore: Add visibility modifiers (#2728)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Oct 9, 2023
1 parent 4881414 commit d9ae189
Show file tree
Hide file tree
Showing 84 changed files with 409 additions and 409 deletions.
14 changes: 7 additions & 7 deletions yarn-project/aztec-nr/authwit/src/account.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct AccountActions {
}

impl AccountActions {
fn init(context: Context, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
pub fn init(context: Context, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
AccountActions {
context: context,
is_valid_impl: is_valid_impl,
Expand All @@ -27,16 +27,16 @@ impl AccountActions {
}
}

fn private(context: &mut PrivateContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
pub fn private(context: &mut PrivateContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
AccountActions::init(Context::private(context), approved_action_storage_slot, is_valid_impl)
}

fn public(context: &mut PublicContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
pub fn public(context: &mut PublicContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self {
AccountActions::init(Context::public(context), approved_action_storage_slot, is_valid_impl)
}

// docs:start:entrypoint
fn entrypoint(self, payload: EntrypointPayload) {
pub fn entrypoint(self, payload: EntrypointPayload) {
let message_hash = payload.hash();
let valid_fn = self.is_valid_impl;
let private_context = self.context.private.unwrap();
Expand All @@ -45,7 +45,7 @@ impl AccountActions {
}
// docs:end:entrypoint

fn is_valid(self, message_hash: Field) -> Field {
pub fn is_valid(self, message_hash: Field) -> Field {
let valid_fn = self.is_valid_impl;
if (valid_fn(self.context.private.unwrap(), message_hash)) {
IS_VALID_SELECTOR
Expand All @@ -54,7 +54,7 @@ impl AccountActions {
}
}

fn is_valid_public(self, message_hash: Field) -> Field {
pub fn is_valid_public(self, message_hash: Field) -> Field {
let value = self.approved_action.at(message_hash).read();
if (value){
IS_VALID_SELECTOR
Expand All @@ -63,7 +63,7 @@ impl AccountActions {
}
}

fn internal_set_is_valid_storage(self, message_hash: Field, value: bool) {
pub fn internal_set_is_valid_storage(self, message_hash: Field, value: bool) {
self.approved_action.at(message_hash).write(value);
}
}
10 changes: 5 additions & 5 deletions yarn-project/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153;
// @todo #2676 Should use different generator than the payload to limit probability of collisions.

// Assert that `whom` have authorized `message_hash` with a valid authentication witness
fn assert_valid_authwit(context: &mut PrivateContext, whom: AztecAddress, message_hash: Field) {
pub fn assert_valid_authwit(context: &mut PrivateContext, whom: AztecAddress, message_hash: Field) {
let result = context.call_private_function(whom.address, IS_VALID_SELECTOR, [message_hash])[0];
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
}

// Assert that `whom` have authorized the current call with a valid authentication witness
fn assert_current_call_valid_authwit(context: &mut PrivateContext, whom: AztecAddress) {
pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, whom: AztecAddress) {
let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash];
let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];
assert_valid_authwit(context, whom, message_hash);
}

// Assert that `whom` have authorized `message_hash` in a public context
fn assert_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress, message_hash: Field) {
pub fn assert_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress, message_hash: Field) {
let result = context.call_public_function(whom.address, IS_VALID_PUBLIC_SELECTOR, [message_hash])[0];
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
}

// Assert that `whom` have authorized the current call in a public context
fn assert_current_call_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress) {
pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress) {
let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash];
let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];
assert_valid_authwit_public(context, whom, message_hash);
}

// Compute the message hash to be used by an authentication witness
fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field {
pub fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field {
let args_hash = hash_args(args);
pedersen_with_separator([caller.address, target.address, selector, args_hash], GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0]
}
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/authwit/src/auth_witness.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[oracle(getAuthWitness)]
fn get_auth_witness_oracle<N>(_message_hash: Field) -> [Field; N] {}

unconstrained fn get_auth_witness<N>(message_hash: Field) -> [Field; N] {
unconstrained pub fn get_auth_witness<N>(message_hash: Field) -> [Field; N] {
get_auth_witness_oracle(message_hash)
}
30 changes: 15 additions & 15 deletions yarn-project/aztec-nr/aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct HistoricBlockData {

impl HistoricBlockData {
// NOTE: this order must match the order in `private_circuit_public_inputs.hpp`
fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {
pub fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {
[
self.private_data_tree_root,
self.nullifier_tree_root,
Expand All @@ -165,7 +165,7 @@ impl HistoricBlockData {
]
}

fn empty() -> Self {
pub fn empty() -> Self {
Self { private_data_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 }
}
}
Expand Down Expand Up @@ -265,15 +265,15 @@ struct ContractStorageRead {
}

impl ContractStorageRead {
fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] {
pub fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] {
[self.storage_slot, self.value]
}

fn hash(self) -> Field {
pub fn hash(self) -> Field {
dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ)[0]
}

fn empty() -> Self {
pub fn empty() -> Self {
Self { storage_slot: 0, value: 0 }
}
}
Expand All @@ -285,15 +285,15 @@ struct ContractStorageUpdateRequest {
}

impl ContractStorageUpdateRequest {
fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] {
pub fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] {
[self.storage_slot, self.old_value, self.new_value]
}

fn hash(self) -> Field {
pub fn hash(self) -> Field {
dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST)[0]
}

fn empty() -> Self {
pub fn empty() -> Self {
Self { storage_slot: 0, old_value: 0, new_value: 0 }
}
}
Expand All @@ -320,7 +320,7 @@ struct PublicCircuitPublicInputs {

impl PublicCircuitPublicInputs {

fn hash(self) -> Field {
pub fn hash(self) -> Field {
let mut inputs: BoundedVec<Field, PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH> = BoundedVec::new(0);
inputs.push(self.call_context.hash());
inputs.push(self.args_hash);
Expand All @@ -346,7 +346,7 @@ impl PublicCircuitPublicInputs {
dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0]
}

fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
pub fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH> = BoundedVec::new(0);
fields.push_array(self.call_context.serialize());
fields.push(self.args_hash);
Expand Down Expand Up @@ -374,29 +374,29 @@ struct Hasher {
}

impl Hasher {
fn new()-> Self {
pub fn new()-> Self {
Self { fields: [] }
}

fn add(&mut self, field: Field) {
pub fn add(&mut self, field: Field) {
self.fields = self.fields.push_back(field);
}

fn add_multiple<N>(&mut self, fields: [Field; N]) {
pub fn add_multiple<N>(&mut self, fields: [Field; N]) {
for i in 0..N {
self.fields = self.fields.push_back(fields[i]);
}
}

fn hash(self) -> Field {
pub fn hash(self) -> Field {
hash_args(self.fields)
}
}

global ARGS_HASH_CHUNK_LENGTH: u32 = 32;
global ARGS_HASH_CHUNK_COUNT: u32 = 16;

fn hash_args<N>(args: [Field; N]) -> Field {
pub fn hash_args<N>(args: [Field; N]) -> Field {
if args.len() == 0 {
0
} else {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/address.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::std::hash;
use crate::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;

fn compute_address(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> Field {
pub fn compute_address(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> Field {
hash::pedersen_with_separator([pub_key_x, pub_key_y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0]
}
Loading

0 comments on commit d9ae189

Please sign in to comment.