Skip to content

Commit

Permalink
verification key issue workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 25, 2024
1 parent 93d28f2 commit c0261fb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AztecAddress, PublicMutable<U128>>,
// TODO(#7604): uncomment the following
// balances: Map<AztecAddress, PublicMutable<U128>>,
portal_address: SharedImmutable<EthAddress>,
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
});
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/simulator/src/public/fee_payment.ts
Original file line number Diff line number Diff line change
@@ -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();
}

/**
Expand Down

0 comments on commit c0261fb

Please sign in to comment.