From ff23639ab29891a0bcd404731779f9e04c069f60 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 8 Nov 2024 01:59:00 +0000 Subject: [PATCH] WIP --- .../noir-contracts/contracts/fpc_contract/src/main.nr | 4 ++-- .../noir-contracts/contracts/token_contract/src/main.nr | 1 + .../aztec.js/src/fee/private_fee_payment_method.ts | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index 2f922be71e7d..9a9376abfc9f 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -27,13 +27,13 @@ contract FPC { } #[private] - fn fee_entrypoint_private(amount: Field, asset: AztecAddress) { + fn fee_entrypoint_private(amount: Field, asset: AztecAddress, nonce: Field) { // TODO(PR #8022): Once SharedImmutable performs only 1 merkle proof here, we'll save ~4k gates let settings = storage.settings.read_private(); assert(asset == settings.other_asset); - Token::at(asset).setup_refund(settings.admin, context.msg_sender(), amount).call( + Token::at(asset).setup_refund(settings.admin, context.msg_sender(), amount, nonce).call( &mut context, ); context.set_as_fee_payer(); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 65968ff06228..2c9ee70ec48c 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -675,6 +675,7 @@ contract Token { fee_payer: AztecAddress, // Address of the entity which will receive the fee note. user: AztecAddress, // A user for which we are setting up the fee refund. funded_amount: Field, // The amount the user funded the fee payer with (represents fee limit). + nonce: Field // A nonce to make authwitness unique. ) { // 1. This function is called by fee paying contract (fee_payer) when setting up a refund so we need to support // the authwit flow here and check that the user really permitted fee_payer to set up a refund on their behalf. diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index 6da919efc5a3..0578179ef1c6 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -59,13 +59,14 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit // (maxFee) to be in token denomination. const maxFee = this.setMaxFeeToOne ? Fr.ONE : gasSettings.getFeeLimit(); + const nonce = Fr.random(); await this.wallet.createAuthWit({ caller: this.paymentContract, action: { name: 'setup_refund', - args: [this.feeRecipient, this.wallet.getAddress(), maxFee], - selector: FunctionSelector.fromSignature('setup_refund((Field),(Field),Field)'), + args: [this.feeRecipient, this.wallet.getAddress(), maxFee, nonce], + selector: FunctionSelector.fromSignature('setup_refund((Field),(Field),Field,Field)'), type: FunctionType.PRIVATE, isStatic: false, to: this.asset, @@ -77,10 +78,10 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { { name: 'fee_entrypoint_private', to: this.paymentContract, - selector: FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field))'), + selector: FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field),Field)'), type: FunctionType.PRIVATE, isStatic: false, - args: [maxFee, this.asset], + args: [maxFee, this.asset, nonce], returnTypes: [], }, ];