diff --git a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr index 96b25801626..5b028a66791 100644 --- a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr @@ -20,7 +20,8 @@ contract GasToken { struct Storage { // This map is accessed directly by protocol circuits to check balances for fee payment. // Do not change this storage layout unless you also update the base rollup circuits. - balances: Map>, + // TODO(#7604): uncomment the following + // balances: Map>, portal_address: SharedImmutable, } @@ -96,8 +97,12 @@ contract GasToken { #[aztec(public)] #[aztec(internal)] fn _increase_public_balance(to: AztecAddress, amount: Field) { - let new_balance = storage.balances.at(to).read().add(U128::from_integer(amount)); - storage.balances.at(to).write(new_balance); + // let new_balance = storage.balances.at(to).read().add(U128::from_integer(amount)); + // storage.balances.at(to).write(new_balance); + + // TODO(#7604): nuke the following and uncomment above + let new_balance: U128 = context.storage_read(to.to_field()) + U128::from_integer(amount); + context.storage_write(to.to_field(), new_balance); } // TODO(palla/gas) Remove this function and use the private claim flow only @@ -110,8 +115,12 @@ contract GasToken { // Consume message and emit nullifier context.consume_l1_to_l2_message(content_hash, secret, portal_address, leaf_index); - let new_balance = storage.balances.at(to).read() + U128::from_integer(amount); - storage.balances.at(to).write(new_balance); + // let new_balance = storage.balances.at(to).read() + U128::from_integer(amount); + // storage.balances.at(to).write(new_balance); + + // TODO(#7604): nuke the following and uncomment above + let new_balance: U128 = context.storage_read(to.to_field()) + U128::from_integer(amount); + context.storage_write(to.to_field(), new_balance); } // TODO(@just-mitch): remove this function before mainnet deployment @@ -120,22 +129,32 @@ contract GasToken { #[aztec(public)] fn mint_public(to: AztecAddress, amount: Field) { let amount = U128::from_integer(amount); - let new_balance = storage.balances.at(to).read().add(amount); + // let new_balance = storage.balances.at(to).read().add(amount); - storage.balances.at(to).write(new_balance); + // storage.balances.at(to).write(new_balance); + + // TODO(#7604): nuke the following and uncomment above + let new_balance: U128 = context.storage_read(to.to_field()) + amount; + context.storage_write(to.to_field(), new_balance); } #[aztec(public)] #[aztec(view)] fn check_balance(fee_limit: Field) { let fee_limit = U128::from_integer(fee_limit); - assert(storage.balances.at(context.msg_sender()).read() >= fee_limit, "Balance too low"); + // assert(storage.balances.at(context.msg_sender()).read() >= fee_limit, "Balance too low"); + + // TODO(#7604): nuke the following and uncomment above + let balance: U128 = context.storage_read(context.msg_sender().to_field()); + assert(balance >= fee_limit, "Balance too low"); } // utility function for testing #[aztec(public)] #[aztec(view)] fn balance_of_public(owner: AztecAddress) -> pub Field { - storage.balances.at(owner).read().to_field() + // storage.balances.at(owner).read().to_field() + // TODO(#7604): nuke the following and uncomment above + context.storage_read(owner.to_field()) } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 46a6065adaf..71062700b1b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -417,12 +417,13 @@ fn insert_public_data_update_requests( // TODO(#7551): rename `leaf_slot` to `storage_index` everywhere and slot in PublicDataTreeLeaf // and PublicDataTreeLeafPreimage etc. as storage_index as well fn compute_fee_payer_gas_token_balance_leaf_slot(fee_payer: AztecAddress) -> Field { - // TODO(benesjan): re-enable this - // let gas_token = AztecAddress::from_field(GAS_TOKEN_ADDRESS); + let gas_token = AztecAddress::from_field(GAS_TOKEN_ADDRESS); // let fee_payer_balance_slot_in_gas_token_contract = derive_storage_slot_in_map(balances_slot_in_gas_token_contract, fee_payer); // let fee_payer_balance_contract_storage_index = fee_payer_balance_slot_in_gas_token_contract.x; // compute_public_data_tree_index(gas_token, fee_payer_balance_contract_storage_index) - 0 + + // TODO(#7604): nuke the following and uncomment above + compute_public_data_tree_index(gas_token, fee_payer.to_field()) } #[test] 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 5cc1219637c..c5d308ec0cf 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 @@ -1,7 +1,5 @@ import { type Tx, mockTx } from '@aztec/circuit-types'; import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js'; -import { pedersenHash } from '@aztec/foundation/crypto'; -import { GasTokenContract } from '@aztec/noir-contracts.js'; import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token'; import { type MockProxy, mock, mockFn } from 'jest-mock-extended'; @@ -37,7 +35,9 @@ describe('GasTxValidator', () => { inclusionFee: new Fr(TX_FEE), }); payer = tx.data.feePayer; - expectedBalanceSlot = pedersenHash([GasTokenContract.storage.balances.slot, payer]); + // expectedBalanceSlot = pedersenHash([GasTokenContract.storage.balances.slot, payer]); + // TODO(#7604): nuke the following and uncomment above + expectedBalanceSlot = payer.toField(); expect(tx.data.constants.txContext.gasSettings.getFeeLimit()).toEqual(new Fr(TX_FEE)); }); diff --git a/yarn-project/simulator/src/public/fee_payment.ts b/yarn-project/simulator/src/public/fee_payment.ts index 6a0923182c0..2190100930e 100644 --- a/yarn-project/simulator/src/public/fee_payment.ts +++ b/yarn-project/simulator/src/public/fee_payment.ts @@ -1,14 +1,15 @@ -import { GAS_TOKEN_ADDRESS, deriveStorageSlotInMap } from '@aztec/circuits.js'; +import { GAS_TOKEN_ADDRESS } from '@aztec/circuits.js'; import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; -import { GasTokenArtifact } from '@aztec/protocol-contracts/gas-token'; /** * Computes the storage slot within the gas token contract for the balance of the fee payer. */ export function computeFeePayerBalanceContractStorageIndex(feePayer: AztecAddress): Fr { - return deriveStorageSlotInMap(GasTokenArtifact.storageLayout.balances.slot, feePayer).x; + // return deriveStorageSlotInMap(GasTokenArtifact.storageLayout.balances.slot, feePayer).x; + // TODO(#7604): nuke the following and uncomment above + return feePayer.toField(); } /**