From d0f6abd2bf2d31cd1ff02abad59fc56337f1d333 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Thu, 23 Nov 2023 17:08:00 +0000 Subject: [PATCH 1/2] remove return value of 1 --- .../lending_contract/src/interfaces.nr | 8 +-- .../contracts/lending_contract/src/main.nr | 70 +++++-------------- .../contracts/price_feed_contract/src/main.nr | 4 +- .../contracts/test_contract/src/interface.nr | 9 ++- .../src/interfaces.nr | 4 +- .../token_blacklist_contract/src/main.nr | 54 +++++--------- .../token_bridge_contract/src/main.nr | 19 ++--- .../src/contracts/token_contract/src/main.nr | 32 +++------ .../uniswap_contract/src/interfaces.nr | 6 +- .../contracts/uniswap_contract/src/main.nr | 8 +-- 10 files changed, 71 insertions(+), 143 deletions(-) diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr index e2377ef2f6e..53385ed3e99 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr @@ -37,7 +37,7 @@ 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] @@ -45,15 +45,15 @@ impl Token { } 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] diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr index adca6f6adc5..8a24bd2e2b9 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr @@ -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(); @@ -118,8 +118,6 @@ contract Lending { storage.collateral_asset.write(collateral_asset); storage.stable_coin.write(stable_coin); - - 1 } // Create a position. @@ -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(); @@ -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); @@ -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); @@ -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); @@ -271,8 +245,6 @@ 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)] @@ -280,18 +252,14 @@ contract Lending { 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)] @@ -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 { diff --git a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr index b4a2e6461bc..3573778e708 100644 --- a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr @@ -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)] diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr index 65cf52e96b5..1bb62e9f3f6 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr @@ -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; @@ -26,6 +26,7 @@ struct ManyNotesADeepStructTestCodeGenStruct { secret_hash: Field, } + // Interface for calling Test functions from a private context struct TestPrivateContextInterface { address: Field, @@ -241,6 +242,9 @@ impl TestPrivateContextInterface { } } + + + // Interface for calling Test functions from a public context struct TestPublicContextInterface { @@ -326,4 +330,5 @@ impl TestPublicContextInterface { } } - + + diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr index a05dc34874b..9fb08061031 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr @@ -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()") ); @@ -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] diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr index 8e51623b854..95e9a33d65f 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr @@ -134,6 +134,13 @@ contract TokenBlacklist { } /////// + #[aztec(public)] + internal fn _initialize(new_admin: AztecAddress, slow_updates_contract: AztecAddress) { + assert(new_admin.address != 0, "invalid admin"); + storage.admin.write(new_admin); + storage.public_slow_update.write(slow_updates_contract); + SlowMap::at(slow_updates_contract).initialize(context); + } #[aztec(private)] fn update_roles(user: AztecAddress, roles: Field) { @@ -145,7 +152,7 @@ contract TokenBlacklist { } #[aztec(public)] - fn mint_public(to: AztecAddress, amount: Field) -> Field { + fn mint_public(to: AztecAddress, amount: Field) { let slow = SlowMap::at(storage.public_slow_update.read()); let to_roles = UserFlags::new(slow.read_at_pub(context, to.address) as u120); assert(!to_roles.is_blacklisted, "Blacklisted: Recipient"); @@ -159,11 +166,10 @@ contract TokenBlacklist { storage.public_balances.at(to.address).write(new_balance); storage.total_supply.write(supply); - 1 } #[aztec(public)] - fn mint_private(amount: Field, secret_hash: Field) -> Field { + fn mint_private(amount: Field, secret_hash: Field) { let slow = SlowMap::at(storage.public_slow_update.read()); let caller_roles = UserFlags::new(slow.read_at_pub(context, context.msg_sender()) as u120); assert(caller_roles.is_minter, "caller is not minter"); @@ -174,11 +180,10 @@ contract TokenBlacklist { storage.total_supply.write(supply); pending_shields.insert_from_public(&mut note); - 1 } #[aztec(public)] - fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) -> Field { + fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) { let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -198,11 +203,10 @@ contract TokenBlacklist { storage.public_balances.at(from.address).write(from_balance); pending_shields.insert_from_public(&mut note); - 1 } #[aztec(public)] - fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -221,12 +225,10 @@ contract TokenBlacklist { let to_balance = storage.public_balances.at(to.address).read().add(amount); storage.public_balances.at(to.address).write(to_balance); - - 1 } #[aztec(public)] - fn burn_public(from: AztecAddress, amount: Field, nonce: Field) -> Field { + fn burn_public(from: AztecAddress, amount: Field, nonce: Field) { let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -243,12 +245,10 @@ contract TokenBlacklist { let new_supply = storage.total_supply.read().sub(amount); storage.total_supply.write(new_supply); - - 1 } #[aztec(private)] - fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) -> Field { + fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let to_roles = UserFlags::new(slow.read_at(&mut context, to.address) as u120); assert(!to_roles.is_blacklisted, "Blacklisted: Recipient"); @@ -260,17 +260,15 @@ contract TokenBlacklist { let options = NoteGetterOptions::new().select(0, amount).select(1, secret_hash).set_limit(1); let notes = pending_shields.get_notes(options); let note = notes[0].unwrap_unchecked(); - // Remove the note from the pending shields set + // Remove the note from the pending shields set pending_shields.remove(note); // Add the token note to user's balances set storage.balances.at(to).add(SafeU120::new(amount)); - - 1 } #[aztec(private)] - fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -286,13 +284,11 @@ contract TokenBlacklist { storage.balances.at(from).sub(SafeU120::new(amount)); let selector = compute_selector("_increase_public_balance((Field),Field)"); - let _void = context.call_public_function(context.this_address(), selector, [to.address, amount]); - - 1 + context.call_public_function(context.this_address(), selector, [to.address, amount]); } #[aztec(private)] - fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -308,12 +304,10 @@ contract TokenBlacklist { let amount = SafeU120::new(amount); storage.balances.at(from).sub(amount); storage.balances.at(to).add(amount); - - 1 } #[aztec(private)] - fn burn(from: AztecAddress, amount: Field, nonce: Field) -> Field { + fn burn(from: AztecAddress, amount: Field, nonce: Field) { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -327,17 +321,7 @@ contract TokenBlacklist { storage.balances.at(from).sub(SafeU120::new(amount)); let selector = compute_selector("_reduce_total_supply(Field)"); - let _void = context.call_public_function(context.this_address(), selector, [amount]); - - 1 - } - - #[aztec(public)] - internal fn _initialize(new_admin: AztecAddress, slow_updates_contract: AztecAddress) { - assert(new_admin.address != 0, "invalid admin"); - storage.admin.write(new_admin); - storage.public_slow_update.write(slow_updates_contract); - SlowMap::at(slow_updates_contract).initialize(context); + context.call_public_function(context.this_address(), selector, [amount]); } /// Internal /// diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr index 4fb1553eefe..04be48b7e88 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr @@ -52,15 +52,14 @@ contract TokenBridge { // docs:start:claim_public // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[aztec(public)] - fn claim_public(to: AztecAddress, amount: Field, canceller: EthereumAddress, msg_key: Field, secret: Field) -> Field { + fn claim_public(to: AztecAddress, amount: Field, canceller: EthereumAddress, msg_key: Field, secret: Field) { let content_hash = get_mint_public_content_hash(to.address, amount, canceller.address); + // Consume message and emit nullifier context.consume_l1_to_l2_message(msg_key, content_hash, secret); // Mint tokens Token::at(storage.token.read()).mint_public(context, to.address, amount); - - 1 } // docs:end:claim_public @@ -73,15 +72,13 @@ contract TokenBridge { amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) nonce: Field // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 - ) -> Field { + ) { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); context.message_portal(content); // Burn tokens Token::at(storage.token.read()).burn_public(context, context.msg_sender(), amount, nonce); - - 1 } // docs:end:exit_to_l1_public // docs:start:claim_private @@ -94,7 +91,7 @@ contract TokenBridge { canceller: EthereumAddress, msg_key: Field, // L1 to L2 message key as derived from the inbox contract secret_for_L1_to_L2_message_consumption: Field // secret used to consume the L1 to L2 message - ) -> Field { + ) { // Consume L1 to L2 message and emit nullifier let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, @@ -108,8 +105,6 @@ contract TokenBridge { context.call_public_function(context.this_address(), compute_selector("_call_mint_on_token(Field,Field)"), [amount, secret_hash_for_redeeming_minted_notes]); - - 1 } // docs:end:claim_private @@ -123,7 +118,7 @@ contract TokenBridge { amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) nonce: Field // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 - ) -> Field { + ) { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); context.message_portal(content); @@ -135,8 +130,6 @@ contract TokenBridge { // Burn tokens Token::at(token.address).burn(&mut context, context.msg_sender(), amount, nonce); - - 1 } /// docs:end:exit_to_l1_private @@ -180,5 +173,5 @@ contract TokenBridge { unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> [Field; 4] { [0, 0, 0, 0] } - // docs:end:compute_note_hash_and_nullifier_placeholder +// docs:end:compute_note_hash_and_nullifier_placeholder } diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr index 6eb7c6cd906..2a52ab0607b 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr @@ -152,7 +152,7 @@ contract Token { // docs:start:mint_public #[aztec(public)] - fn mint_public(to: AztecAddress, amount: Field) -> Field { + fn mint_public(to: AztecAddress, amount: Field) { // docs:start:read_minter assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter"); // docs:end:read_minter @@ -162,13 +162,12 @@ contract Token { storage.public_balances.at(to.address).write(new_balance); storage.total_supply.write(supply); - 1 } // docs:end:mint_public // docs:start:mint_private #[aztec(public)] - fn mint_private(amount: Field, secret_hash: Field) -> Field { + fn mint_private(amount: Field, secret_hash: Field) { assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter"); let pending_shields = storage.pending_shields; let mut note = TransparentNote::new(amount, secret_hash); @@ -178,13 +177,12 @@ contract Token { // docs:start:insert_from_public pending_shields.insert_from_public(&mut note); // docs:end:insert_from_public - 1 } // docs:end:mint_private // docs:start:shield #[aztec(public)] - fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) -> Field { + fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) { if (from.address != context.msg_sender()) { // The redeem is only spendable once, so we need to ensure that you cannot insert multiple shields from the same message. assert_current_call_valid_authwit_public(&mut context, from); @@ -200,13 +198,12 @@ contract Token { storage.public_balances.at(from.address).write(from_balance); pending_shields.insert_from_public(&mut note); - 1 } // docs:end:shield // docs:start:transfer_public #[aztec(public)] - fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, from); } else { @@ -220,13 +217,12 @@ contract Token { let to_balance = storage.public_balances.at(to.address).read().add(amount); storage.public_balances.at(to.address).write(to_balance); - 1 } // docs:end:transfer_public // docs:start:burn_public #[aztec(public)] - fn burn_public(from: AztecAddress, amount: Field, nonce: Field) -> Field { + fn burn_public(from: AztecAddress, amount: Field, nonce: Field) { // docs:start:assert_current_call_valid_authwit_public if (from.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, from); @@ -241,14 +237,12 @@ contract Token { let new_supply = storage.total_supply.read().sub(amount); storage.total_supply.write(new_supply); - - 1 } // docs:end:burn_public // docs:start:redeem_shield #[aztec(private)] - fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) -> Field { + fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) { let pending_shields = storage.pending_shields; let secret_hash = compute_secret_hash(secret); // Get 1 note (set_limit(1)) which has amount stored in field with index 0 (select(0, amount)) and secret_hash @@ -261,14 +255,12 @@ contract Token { // Add the token note to user's balances set storage.balances.at(to).add(SafeU120::new(amount)); - - 1 } // docs:end:redeem_shield // docs:start:unshield #[aztec(private)] - fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); } else { @@ -279,14 +271,12 @@ contract Token { let selector = compute_selector("_increase_public_balance((Field),Field)"); let _void = context.call_public_function(context.this_address(), selector, [to.address, amount]); - - 1 } // docs:end:unshield // docs:start:transfer #[aztec(private)] - fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { // docs:start:assert_current_call_valid_authwit if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); @@ -300,14 +290,12 @@ contract Token { // docs:start:increase_private_balance storage.balances.at(to).add(amount); // docs:end:increase_private_balance - - 1 } // docs:end:transfer // docs:start:burn #[aztec(private)] - fn burn(from: AztecAddress, amount: Field, nonce: Field) -> Field { + fn burn(from: AztecAddress, amount: Field, nonce: Field) { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); } else { @@ -318,8 +306,6 @@ contract Token { let selector = compute_selector("_reduce_total_supply(Field)"); let _void = context.call_public_function(context.this_address(), selector, [amount]); - - 1 } // docs:end:burn diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr index aabf2735702..a319d7135ba 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr @@ -15,7 +15,7 @@ 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] @@ -23,7 +23,7 @@ impl Token { } pub fn unshield(self: Self, context: &mut PrivateContext, from: Field, to: Field, amount: Field, nonce: Field) { - let _return_values = context.call_private_function( + context.call_private_function( self.address, compute_selector("unshield((Field),(Field),Field,Field)"), [from, to, amount, nonce] @@ -46,7 +46,7 @@ impl TokenBridge { } pub fn exit_to_l1_public(self: Self, context: PublicContext, recipient: Field, amount: Field, callerOnL1: Field, nonce: Field) { - let _return_values = context.call_public_function( + context.call_public_function( self.address, compute_selector("exit_to_l1_public((Field),Field,(Field),Field)"), [recipient, amount, callerOnL1, nonce] diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr index 1e332adcd70..97d8a5f10e0 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr @@ -72,7 +72,7 @@ contract Uniswap { caller_on_L1: EthereumAddress, // nonce for someone to call swap on sender's behalf nonce_for_swap_approval: Field - ) -> Field { + ) { if (sender.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, sender); } @@ -110,8 +110,6 @@ contract Uniswap { canceller_for_L1_to_L2_message.address, caller_on_L1.address); context.message_portal(content_hash); - - 1 } // docs:end:swap_public @@ -133,7 +131,7 @@ contract Uniswap { deadline_for_L1_to_l2_message: Field, // for when l1 uniswap portal inserts the message to consume output assets on L2 canceller_for_L1_to_L2_message: EthereumAddress, // L1 address of who can cancel the message to consume assets on L2. caller_on_L1: EthereumAddress // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) - ) -> Field { + ) { // Assert that user provided token address is same as expected by token bridge. // we can't directly use `input_asset_bridge.token` because that is a public method and public can't return data to private context.call_public_function(context.this_address(), @@ -171,8 +169,6 @@ contract Uniswap { canceller_for_L1_to_L2_message.address, caller_on_L1.address); context.message_portal(content_hash); - - 1 } // docs:end:swap_private From e58a3d6d26aec403c2cb88230c62eb389a773dd4 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Fri, 24 Nov 2023 10:55:30 +0000 Subject: [PATCH 2/2] fix tests --- yarn-project/acir-simulator/src/public/index.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 38ef76b8190..74abeab2e0b 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -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); @@ -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,