From 2fa612c45e0263887833e2491a92ce179a0ec639 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 16 Jan 2025 18:07:40 +0000 Subject: [PATCH] more fixes --- .../contracts/fee_juice_contract/src/lib.nr | 4 ++-- .../contracts/fee_juice_contract/src/main.nr | 15 +++++++-------- .../contracts/price_feed_contract/src/main.nr | 4 ++-- .../sequencer-client/src/sequencer/allowed.ts | 4 ++-- .../src/tx_validator/gas_validator.test.ts | 4 ++-- .../src/tx_validator/gas_validator.ts | 4 +++- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr index 35179d962e15..2fa51c33c05f 100644 --- a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr @@ -6,10 +6,10 @@ pub fn calculate_fee(context: PublicContext) -> Field { context.transaction_fee() } -pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field { +pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: U128) -> Field { let mut hash_bytes = [0; 68]; let recipient_bytes: [u8; 32] = owner.to_field().to_be_bytes(); - let amount_bytes: [u8; 32] = amount.to_be_bytes(); + let amount_bytes: [u8; 32] = amount.to_field().to_be_bytes(); // The purpose of including the following selector is to make the message unique to that specific call. Note that // it has nothing to do with calling the function. diff --git a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr index c47dccdd9985..0465b55239af 100644 --- a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr @@ -23,7 +23,7 @@ contract FeeJuice { // Not flagged as initializer to reduce cost of checking init nullifier in all functions. // This function should be called as entrypoint to initialize the contract by minting itself funds. #[private] - fn initialize(portal_address: EthAddress, initial_mint: Field) { + fn initialize(portal_address: EthAddress, initial_mint: U128) { // Validate contract class parameters are correct let self = context.this_address(); @@ -46,7 +46,7 @@ contract FeeJuice { } #[private] - fn claim(to: AztecAddress, amount: Field, secret: Field, message_leaf_index: Field) { + fn claim(to: AztecAddress, amount: U128, secret: Field, message_leaf_index: Field) { let content_hash = get_bridge_gas_msg_hash(to, amount); let portal_address = storage.portal_address.read(); assert(!portal_address.is_zero()); @@ -63,22 +63,21 @@ contract FeeJuice { #[public] #[internal] - fn _increase_public_balance(to: AztecAddress, amount: Field) { - let new_balance = storage.balances.at(to).read().add(U128::from_integer(amount)); + fn _increase_public_balance(to: AztecAddress, amount: U128) { + let new_balance = storage.balances.at(to).read().add(amount); storage.balances.at(to).write(new_balance); } #[public] #[view] - fn check_balance(fee_limit: Field) { - let fee_limit = U128::from_integer(fee_limit); + fn check_balance(fee_limit: U128) { assert(storage.balances.at(context.msg_sender()).read() >= fee_limit, "Balance too low"); } // utility function for testing #[public] #[view] - fn balance_of_public(owner: AztecAddress) -> pub Field { - storage.balances.at(owner).read().to_field() + fn balance_of_public(owner: AztecAddress) -> pub U128 { + storage.balances.at(owner).read() } } diff --git a/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr b/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr index 92739ffb6aba..3659646a1ecd 100644 --- a/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr @@ -16,9 +16,9 @@ contract PriceFeed { } #[public] - fn set_price(asset_id: Field, price: Field) { + fn set_price(asset_id: Field, price: U128) { let asset = storage.assets.at(asset_id); - asset.write(Asset { price: U128::from_integer(price) }); + asset.write(Asset { price }); } #[public] diff --git a/yarn-project/sequencer-client/src/sequencer/allowed.ts b/yarn-project/sequencer-client/src/sequencer/allowed.ts index 164a2a948b7e..c78c900a8ea4 100644 --- a/yarn-project/sequencer-client/src/sequencer/allowed.ts +++ b/yarn-project/sequencer-client/src/sequencer/allowed.ts @@ -17,13 +17,13 @@ export function getDefaultAllowedSetupFunctions(): AllowedElement[] { { address: ProtocolContractAddress.FeeJuice, // We can't restrict the selector because public functions get routed via dispatch. - // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'), + // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'), }, // needed for private transfers via FPC { classId: getContractClassFromArtifact(TokenContractArtifact).id, // We can't restrict the selector because public functions get routed via dispatch. - // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'), + // selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'), }, { classId: getContractClassFromArtifact(FPCContract.artifact).id, diff --git a/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts b/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts index 07f67fdeb0bd..cdbf52460c49 100644 --- a/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts +++ b/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts @@ -68,7 +68,7 @@ describe('GasTxValidator', () => { it('allows fee paying txs if fee payer claims enough balance during setup', async () => { mockBalance(feeLimit - 1n); - const selector = FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'); + const selector = FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'); patchNonRevertibleFn(tx, 0, { address: ProtocolContractAddress.FeeJuice, selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)), @@ -90,7 +90,7 @@ describe('GasTxValidator', () => { it('rejects txs if fee payer claims balance outside setup', async () => { mockBalance(feeLimit - 1n); patchRevertibleFn(tx, 0, { - selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'), + selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'), args: [payer.toField(), new Fr(1n)], }); await expectInvalid(tx, 'Insufficient fee payer balance'); diff --git a/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts b/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts index 4f5bc03692b0..d02f4c0638f3 100644 --- a/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts +++ b/yarn-project/sequencer-client/src/tx_validator/gas_validator.ts @@ -78,7 +78,9 @@ export class GasTxValidator implements TxValidator { fn.callContext.msgSender.equals(this.#feeJuiceAddress) && fn.args.length > 2 && // Public functions get routed through the dispatch function, whose first argument is the target function selector. - fn.args[0].equals(FunctionSelector.fromSignature('_increase_public_balance((Field),Field)').toField()) && + fn.args[0].equals( + FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))').toField(), + ) && fn.args[1].equals(feePayer.toField()) && !fn.callContext.isStaticCall, );