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

chore(noir-contracts): remove redundant return value of 1 #3415

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions yarn-project/acir-simulator/src/public/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ describe('ACIR public execution simulator', () => {
const execution: PublicExecution = { contractAddress, functionData, args, callContext };
const result = await executor.simulate(execution, GlobalVariables.empty());

expect(result.returnValues[0]).toEqual(new Fr(1n));

const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField());
const totalSupplyStorageSlot = new Fr(4n);

Expand Down Expand Up @@ -182,8 +180,6 @@ describe('ACIR public execution simulator', () => {
const expectedRecipientBalance = new Fr(160n);
const expectedSenderBalance = new Fr(60n);

expect(result.returnValues[0]).toEqual(new Fr(1n));

expect(result.contractStorageUpdateRequests).toEqual([
{
storageSlot: senderStorageSlot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ impl Token {
}

pub fn transfer_public(self: Self, context: PublicContext, from: Field, to: Field, amount: Field, nonce: Field) {
let _transfer_return_values = context.call_public_function(
context.call_public_function(
self.address,
compute_selector("transfer_public((Field),(Field),Field,Field)"),
[from, to, amount, nonce]
);
}

pub fn mint_public(self: Self, context: PublicContext, to: Field, amount: Field) {
let _return_values = context.call_public_function(
context.call_public_function(
self.address,
compute_selector("mint_public((Field),Field)"),
[to, amount]
);
}

pub fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field){
let _return_values = context.call_public_function(
pub fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field) {
context.call_public_function(
self.address,
compute_selector("burn_public((Field),Field,Field)"),
[from, amount, nonce]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ contract Lending {
) {}

#[aztec(public)]
fn init(oracle_address: Field, loan_to_value: Field, collateral_asset: Field, stable_coin: Field) -> Field {
fn init(oracle_address: Field, loan_to_value: Field, collateral_asset: Field, stable_coin: Field) {
let asset_loc = storage.assets.at(0);
let asset = asset_loc.read();

Expand All @@ -118,8 +118,6 @@ contract Lending {

storage.collateral_asset.write(collateral_asset);
storage.stable_coin.write(stable_coin);

1
}

// Create a position.
Expand Down Expand Up @@ -153,28 +151,20 @@ contract Lending {
let _res = Token::at(collateral_asset).unshield(&mut context, from, context.this_address(), amount, nonce);
// _deposit(on_behalf_of, amount, collateral_asset)
let selector = compute_selector("_deposit(Field,Field,Field)");
let _callStackItem2 = context.call_public_function(context.this_address(),
context.call_public_function(context.this_address(),
selector,
[on_behalf_of, amount, collateral_asset]);
}

#[aztec(public)]
fn deposit_public(amount: Field, nonce: Field, on_behalf_of: Field, collateral_asset: Field) -> Field {
Token::at(collateral_asset).transfer_public(context,
context.msg_sender(),
context.this_address(),
amount,
nonce);
fn deposit_public(amount: Field, nonce: Field, on_behalf_of: Field, collateral_asset: Field) {
Token::at(collateral_asset).transfer_public(context, context.msg_sender(), context.this_address(), amount, nonce);
let selector = compute_selector("_deposit(Field,Field,Field)");
let return_values = context.call_public_function(context.this_address(),
selector,
[on_behalf_of, amount, collateral_asset]);

return_values[0]
context.call_public_function(context.this_address(), selector, [on_behalf_of, amount, collateral_asset]);
}

#[aztec(public)]
internal fn _deposit(owner: Field, amount: Field, collateral_asset: Field) -> Field {
internal fn _deposit(owner: Field, amount: Field, collateral_asset: Field) {
let _asset = Lending::at(context.this_address()).update_accumulator(context);

let coll_asset = storage.collateral_asset.read();
Expand All @@ -183,29 +173,23 @@ contract Lending {
let coll_loc = storage.collateral.at(owner);
let collateral = coll_loc.read();
coll_loc.write(collateral + amount);

1
}

#[aztec(private)]
fn withdraw_private(secret: Field, to: Field, amount: Field) {
let on_behalf_of = compute_identifier(secret, 0, context.msg_sender());
let selector = compute_selector("_withdraw(Field,Field,Field)");
let _callStackItem = context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]);
context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]);
}

#[aztec(public)]
fn withdraw_public(to: Field, amount: Field) -> Field {
fn withdraw_public(to: Field, amount: Field) {
let selector = compute_selector("_withdraw(Field,Field,Field)");
let return_values = context.call_public_function(context.this_address(),
selector,
[context.msg_sender(), to, amount]);

return_values[0]
context.call_public_function(context.this_address(), selector, [context.msg_sender(), to, amount]);
}

#[aztec(public)]
internal fn _withdraw(owner: Field, recipient: Field, amount: Field) -> Field {
internal fn _withdraw(owner: Field, recipient: Field, amount: Field) {
let asset = Lending::at(context.this_address()).update_accumulator(context);
let price = PriceFeed::at(asset.oracle_address).get_price(context);

Expand All @@ -217,11 +201,7 @@ contract Lending {

// debt_covered will revert if decrease would leave insufficient collateral to cover debt.
// or trying to remove more collateral than available
let debt_covered = covered_by_collateral(price,
asset.loan_to_value,
collateral as u120,
0,
amount as u120);
let debt_covered = covered_by_collateral(price, asset.loan_to_value, collateral as u120, 0, amount as u120);
let debt_returns = debt_updates(asset.interest_accumulator, static_debt as u120, 0, 0);

assert(debt_returns.debt_value < debt_covered);
Expand All @@ -231,29 +211,23 @@ contract Lending {
// @todo @LHerskind Support both shielding and transfers (for now just transfer)
let collateral_asset = storage.collateral_asset.read();
Token::at(collateral_asset).transfer_public(context, context.this_address(), recipient, amount, 0);

1
}

#[aztec(private)]
fn borrow_private(secret: Field, to: Field, amount: Field) {
let on_behalf_of = compute_identifier(secret, 0, context.msg_sender());
let selector = compute_selector("_borrow(Field,Field,Field)");
let _callStackItem = context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]);
context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]);
}

#[aztec(public)]
fn borrow_public(to: Field, amount: Field) -> Field {
fn borrow_public(to: Field, amount: Field) {
let selector = compute_selector("_borrow(Field,Field,Field)");
let return_values = context.call_public_function(context.this_address(),
selector,
[context.msg_sender(), to, amount]);

return_values[0]
context.call_public_function(context.this_address(), selector, [context.msg_sender(), to, amount]);
}

#[aztec(public)]
internal fn _borrow(owner: Field, to: Field, amount: Field) -> Field {
internal fn _borrow(owner: Field, to: Field, amount: Field) {
let asset = Lending::at(context.this_address()).update_accumulator(context);
let price = PriceFeed::at(asset.oracle_address).get_price(context);

Expand All @@ -271,27 +245,21 @@ contract Lending {
// @todo @LHerskind Need to support both private and public minting.
let stable_coin = storage.stable_coin.read();
Token::at(stable_coin).mint_public(context, to, amount);

1
}

#[aztec(private)]
fn repay_private(from: Field, amount: Field, nonce: Field, secret: Field, on_behalf_of: Field, stable_coin: Field) {
let on_behalf_of = compute_identifier(secret, on_behalf_of, context.msg_sender());
let _res = Token::at(stable_coin).burn(&mut context, from, amount, nonce);
let selector = compute_selector("_repay(Field,Field,Field)");
let _callStackItem = context.call_public_function(context.this_address(),
selector,
[on_behalf_of, amount, stable_coin]);
context.call_public_function(context.this_address(), selector, [on_behalf_of, amount, stable_coin]);
}

#[aztec(public)]
fn repay_public(amount: Field, nonce: Field, owner: Field, stable_coin: Field) -> Field {
fn repay_public(amount: Field, nonce: Field, owner: Field, stable_coin: Field) {
Token::at(stable_coin).burn_public(context, context.msg_sender(), amount, nonce);
let selector = compute_selector("_repay(Field,Field,Field)");
let return_values = context.call_public_function(context.this_address(), selector, [owner, amount, stable_coin]);

return_values[0]
context.call_public_function(context.this_address(), selector, [owner, amount, stable_coin]);
}

#[aztec(public)]
Expand All @@ -305,8 +273,6 @@ contract Lending {
let debt_returns = debt_updates(asset.interest_accumulator, static_debt, 0, amount as u120);

storage.static_debt.at(owner).write(debt_returns.static_debt as Field);

1
}

unconstrained fn get_asset(assetId: Field) -> Asset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ contract PriceFeed {
fn constructor() {}

#[aztec(public)]
fn set_price(asset_id: Field, price: u120) -> Field {
fn set_price(asset_id: Field, price: u120) {
let asset = storage.assets.at(asset_id);
asset.write(Asset { price });

1
}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Autogenerated file, do not edit! */

use dep::std;
use dep::aztec::context::{ PrivateContext, PublicContext };
use dep::aztec::constants_gen::RETURN_VALUES_LENGTH;
Expand All @@ -26,6 +26,7 @@ struct ManyNotesADeepStructTestCodeGenStruct {
secret_hash: Field,
}


// Interface for calling Test functions from a private context
struct TestPrivateContextInterface {
address: Field,
Expand Down Expand Up @@ -241,6 +242,9 @@ impl TestPrivateContextInterface {
}

}




// Interface for calling Test functions from a public context
struct TestPublicContextInterface {
Expand Down Expand Up @@ -326,4 +330,5 @@ impl TestPublicContextInterface {
}

}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl SlowMap {
}

pub fn initialize(self: Self, context: PublicContext) {
let _return_values = context.call_public_function_no_args(
context.call_public_function_no_args(
self.address,
compute_selector("initialize()")
);
Expand All @@ -39,7 +39,7 @@ impl SlowMap {
}

pub fn update_at_private(self: Self, context: &mut PrivateContext, index: Field, new_value: Field) {
let _return_values = context.call_private_function(
context.call_private_function(
self.address,
compute_selector("update_at_private(Field,Field)"),
[index, new_value]
Expand Down
Loading