Skip to content

Commit

Permalink
even more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 16, 2025
1 parent 16c0840 commit 24cb94b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type FunctionCall } from '@aztec/circuit-types';
import { type AztecAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
import { FunctionType } from '@aztec/foundation/abi';
import { FunctionType, U128 } from '@aztec/foundation/abi';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';

Expand Down Expand Up @@ -35,7 +35,7 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
isStatic: false,
args: [
this.sender.toField(),
new Fr(this.claim.claimAmount),
...new U128(this.claim.claimAmount).toFields(),
this.claim.claimSecret,
new Fr(this.claim.messageLeafIndex),
],
Expand Down
25 changes: 22 additions & 3 deletions yarn-project/sequencer-client/src/tx_validator/gas_validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Tx, TxExecutionPhase, type TxValidationResult, type TxValidator } from '@aztec/circuit-types';
import { type AztecAddress, type Fr, FunctionSelector, type GasFees } from '@aztec/circuits.js';
import { type AztecAddress, Fr, FunctionSelector, type GasFees } from '@aztec/circuits.js';
import { U128 } from '@aztec/foundation/abi';
import { createLogger } from '@aztec/foundation/log';
import { computeFeePayerBalanceStorageSlot, getExecutionRequestsByPhase } from '@aztec/simulator/server';

Expand Down Expand Up @@ -65,10 +66,26 @@ export class GasTxValidator implements TxValidator<Tx> {
const feeLimit = tx.data.constants.txContext.gasSettings.getFeeLimit();

// Read current balance of the feePayer
const initialBalance = await this.#publicDataSource.storageRead(
// TODO(#11285): Remove the 2 reads below with the commented out code.
// Uncomment below ######################
// const initialBalance = await this.#publicDataSource.storageRead(
// this.#feeJuiceAddress,
// computeFeePayerBalanceStorageSlot(feePayer),
// );
// Uncomment above ######################
// Remove the following ######################
const initialBalanceLowLimb = await this.#publicDataSource.storageRead(
this.#feeJuiceAddress,
computeFeePayerBalanceStorageSlot(feePayer),
);
const initialBalanceHighLimb = await this.#publicDataSource.storageRead(
this.#feeJuiceAddress,
new Fr(computeFeePayerBalanceStorageSlot(feePayer).toBigInt() + 1n),
);
const initialBalance = new Fr(
U128.fromU64sLE(initialBalanceLowLimb.toBigInt(), initialBalanceHighLimb.toBigInt()).toInteger(),
);
// Remove the above ######################

// If there is a claim in this tx that increases the fee payer balance in Fee Juice, add it to balance
const setupFns = getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP);
Expand All @@ -85,7 +102,9 @@ export class GasTxValidator implements TxValidator<Tx> {
!fn.callContext.isStaticCall,
);

const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[2]) : initialBalance;
const balance = claimFunctionCall
? initialBalance.add(new Fr(U128.fromFields(claimFunctionCall.args.slice(2, 4)).toInteger()))
: initialBalance;
if (balance.lt(feeLimit)) {
this.#log.warn(`Rejecting transaction due to not enough fee payer balance`, {
feePayer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ClientExecutionContext extends ViewDataOracle {
const args = this.executionCache.getPreimage(this.argsHash);

if (args.length !== argumentsSize) {
throw new Error('Invalid arguments size');
throw new Error(`Invalid arguments size: expected ${argumentsSize}, got ${args.length}`);
}

const privateContextInputs = new PrivateContextInputs(
Expand Down

0 comments on commit 24cb94b

Please sign in to comment.