Skip to content

Commit

Permalink
fix: use context rather than inputs more often
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Aug 11, 2023
1 parent d6b4437 commit 9b95458
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/abis/ecdsa_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ contract EcdsaAccount {
for byte in signing_pub_key_y { args.push(byte as Field); }
let mut context = PrivateContext::new(inputs, abi::hash_args(args.storage));

let this = inputs.call_context.storage_contract_address;
let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, inputs.call_context.storage_contract_address);
let this = context.this_address();
let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this);
storage.public_key.initialise(&mut context, &mut pub_key_note);

emit_encrypted_log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract Escrow {
owner: pub Field
) -> distinct pub abi::PrivateCircuitPublicInputs {
let mut context = PrivateContext::new(inputs, abi::hash_args([owner]));
let this = inputs.call_context.storage_contract_address;
let this = context.this_address();

let storage = Storage::init();
let mut note = AddressNote::new(owner, this);
Expand All @@ -56,8 +56,8 @@ contract Escrow {
recipient: pub Field,
) -> distinct pub abi::PrivateCircuitPublicInputs {
let mut context = PrivateContext::new(inputs, abi::hash_args([token, amount, recipient]));
let this = inputs.call_context.storage_contract_address;
let sender = inputs.call_context.msg_sender;
let this = context.this_address();
let sender = context.msg_sender();
let storage = Storage::init();

// TODO: Do we need to manually nullify and recreate this note for access control? Or does Set handle it for us? Or since we have no methods for updating it, we're good?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ contract Lending {
inputs: PublicContextInputs,
amount: Field
) -> pub abi::PublicCircuitPublicInputs {
// TODO(MADDIAA): GET ALL OF THE STUFF FROM CONTEXT IN THIS FILE!!!!! -> ADD TO THE PUBLIC CONTEXT
let mut context = PublicContext::new(inputs, abi::hash_args([amount]));
// @todo @LHerskind Transfer tokens into this contract. We can't do it now because too few writes.

let return_values = call_public_function(context.this_address(), 1065861440, [inputs.call_context.msg_sender, amount]);
let return_values = call_public_function(context.this_address(), 1065861440, [context.msg_sender(), amount]);

context.return_values.push(return_values[0]);
context.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ contract NonNativeToken {
let storage = Storage::init();
let public_balances = storage.public_balances;

let sender = inputs.call_context.msg_sender;
let sender = context.msg_sender();
let sender_balance = public_balances.at(sender);

let current_sender_balance: Field = sender_balance.read();
Expand Down Expand Up @@ -254,8 +254,7 @@ contract NonNativeToken {
let pending_shields = storage.pending_shields;

// Decrease user's balance.
// TODO: USE THE PUBLIC CONTEXT IN THIS RATEHR THAN THE INPUTS
let sender = inputs.call_context.msg_sender;
let sender = context.msg_sender();
let sender_balance = public_balances.at(sender);
let current_sender_balance: Field = sender_balance.read();

Expand All @@ -268,7 +267,7 @@ contract NonNativeToken {
// and insert it into the set of "pending_shields" and therefore
// (eventually) the private data tree.
let mut note = TransparentNote::new(amount, secretHash);
pending_shields.insert_from_public(inputs, &mut note);
pending_shields.insert_from_public(context, &mut note);

context.finish()
}
Expand Down Expand Up @@ -322,7 +321,7 @@ contract NonNativeToken {
spend_notes(&mut context, sender_balance, amount, owner);

// enqueue a public function to perform the public state update.
let thisAddress = inputs.call_context.storage_contract_address;
let thisAddress = context.this_address();

// addUnshieldedBalance selector (in decimal)
// recompute by: `cast keccak addUnshieldedBalance(field,field)` -> convert to decimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ contract Parent {
]));

let pubEntryPointSelector = 3221316504;
let thisAddress = inputs.call_context.storage_contract_address;
let thisAddress = context.this_address();
let _return_values = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]);

// Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.
Expand All @@ -144,7 +144,7 @@ contract Parent {
]));

let pubEntryPointSelector = 3221316504;
let thisAddress = inputs.call_context.storage_contract_address;
let thisAddress = context.this_address();

let _return_values1 = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ contract PendingCommitments {
args[0] = amount;
args[1] = owner;

let this = context.this_address();
// nested call to create/insert note
let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args);
let _callStackItem1 = context.call_private_function(this, insert_fn_selector, args);
// nested call to read that note / pending commitment
let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args);
let _callStackItem2 = context.call_private_function(this, get_then_nullify_fn_selector, args);
// nested call to confirm that balance is zero
let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner]);
let _callStackItem3 = context.call_private_function(this, get_note_zero_fn_selector, [owner]);

context.finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract PublicToken {
let mut context = PublicContext::new(inputs, abi::hash_args([amount, recipient]));

let storage = Storage::init();
let sender = inputs.call_context.msg_sender;
let sender = context.msg_sender();

let sender_balance = storage.balances.at(sender);
let recipient_balance = storage.balances.at(recipient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract SchnorrAccount {

let mut context = PrivateContext::new(inputs, abi::hash_args([signing_pub_key_x, signing_pub_key_y]));

let this = inputs.call_context.storage_contract_address;
let this = context.this_address();
let mut pub_key_note = PublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this);
storage.signing_public_key.initialise(&mut context, &mut pub_key_note);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract SchnorrSingleKeyAccount {

// Verify public key against address
let reproduced_address = dep::std::hash::pedersen_with_separator([x, y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0];
assert(reproduced_address == inputs.call_context.storage_contract_address);
assert(reproduced_address == context.this_address());

// Execute calls
payload.execute_calls(&mut context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl EasyPrivateUint {
let owner_key = get_public_key(owner);
emit_encrypted_log(
context,
context.inputs.call_context.storage_contract_address,
(*context).this_address(),
self.set.storage_slot,
owner,
owner_key,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl EasyPrivateUint {

emit_encrypted_log(
context,
context.inputs.call_context.storage_contract_address,
(*context).this_address(),
self.set.storage_slot,
owner,
owner_key,
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/noir-libs/noir-aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ impl PublicContext {
// assert(item.public_inputs.call_context.is_delegate_call == false);
// assert(item.public_inputs.call_context.is_static_call == false);
// assert(item.public_inputs.call_context.is_contract_deployment == false);
// assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);
// assert(item.public_inputs.call_context.storage_contract_address == contract_address);
// assert(item.public_context.msg_sender() == self.inputs.call_context.storage_contract_address);
// assert(item.public_context.this_address() == contract_address);


// item.public_inputs.return_values
Expand Down Expand Up @@ -704,8 +704,8 @@ impl PublicContext {
// assert(item.public_inputs.call_context.is_delegate_call == false);
// assert(item.public_inputs.call_context.is_static_call == false);
// assert(item.public_inputs.call_context.is_contract_deployment == false);
// assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);
// assert(item.public_inputs.call_context.storage_contract_address == contract_address);
// assert(item.public_context.msg_sender() == self.inputs.call_context.storage_contract_address);
// assert(item.public_context.this_address() == contract_address);

// self.public_call_stack.push(item.hash());

Expand Down
11 changes: 7 additions & 4 deletions yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::abi::PublicContextInputs;
use crate::context::PrivateContext;
use crate::context::{
PrivateContext,
PublicContext,
};
use crate::note::{
note_header::NoteHeader,
note_interface::NoteInterface,
Expand All @@ -16,7 +19,7 @@ fn create_note<Note, N>(
note: &mut Note,
note_interface: NoteInterface<Note, N>,
) {
let contract_address = context.inputs.call_context.storage_contract_address;
let contract_address = (*context).this_address();

let header = NoteHeader { contract_address, storage_slot, nonce: 0 };
let set_header = note_interface.set_header;
Expand All @@ -31,12 +34,12 @@ fn create_note<Note, N>(
}

fn create_note_hash_from_public<Note, N>(
inputs: PublicContextInputs,
context: PublicContext,
storage_slot: Field,
note: &mut Note,
note_interface: NoteInterface<Note, N>,
) {
let contract_address = inputs.call_context.storage_contract_address;
let contract_address = context.this_address();

let header = NoteHeader { contract_address, storage_slot, nonce: 0 };
let set_header = note_interface.set_header;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-libs/noir-aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn check_note_header<Note, N>(
) {
let get_header = note_interface.get_header;
let header = get_header(note);
let contract_address = context.inputs.call_context.storage_contract_address;
let contract_address = context.this_address();
assert(header.contract_address == contract_address);
assert(header.storage_slot == storage_slot);
}
Expand Down Expand Up @@ -67,7 +67,7 @@ fn ensure_note_hash_exists<Note, N>(
// - and the nonce (used in the unique siloed note hash)
let set_header = note_interface.set_header;
let note_header = NoteHeader {
contract_address: context.inputs.call_context.storage_contract_address,
contract_address: (*context).this_address(),
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be
// real nonce (once public kernel applies nonces).
nonce: 0,
Expand Down
9 changes: 6 additions & 3 deletions yarn-project/noir-libs/noir-aztec/src/state_vars/set.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::abi::PublicContextInputs;
use crate::context::PrivateContext;
use crate::context::{
PrivateContext,
PublicContext,
};
use crate::note::lifecycle::{create_note, create_note_hash_from_public, destroy_note};
use crate::note::{
note_getter::{get_notes, ensure_note_exists, ensure_note_hash_exists},
Expand All @@ -24,8 +27,8 @@ impl<Note, N> Set<Note, N> {
create_note(context, self.storage_slot, note, self.note_interface);
}

fn insert_from_public(self, inputs: PublicContextInputs, note: &mut Note) {
create_note_hash_from_public(inputs, self.storage_slot, note, self.note_interface);
fn insert_from_public(self, context: PublicContext, note: &mut Note) {
create_note_hash_from_public(context, self.storage_slot, note, self.note_interface);
}

fn assert_contains(self, context: &mut PrivateContext, note: &mut Note) {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-libs/value-note/src/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn spend_notes(
let encryption_pub_key = get_public_key(owner);
emit_encrypted_log(
context,
context.inputs.call_context.storage_contract_address,
(*context).this_address(),
balance.storage_slot,
owner,
encryption_pub_key,
Expand All @@ -74,7 +74,7 @@ fn send_note(
let encryption_pub_key = get_public_key(recipient);
emit_encrypted_log(
context,
context.inputs.call_context.storage_contract_address,
(*context).this_address(),
balance.storage_slot,
recipient,
encryption_pub_key,
Expand Down

0 comments on commit 9b95458

Please sign in to comment.