Skip to content

GasFees.mul() throws BigInt error when scalar is a float #22294

@awprojs

Description

@awprojs

Description

GasFees.mul(scalar) throws a TypeError when scalar is a non-integer (e.g. 1.5), because the result of Number(this.feePerDaGas) * scalar produces a float that cannot be converted to BigInt.

Reproduction

This is hit in normal CLI usage. Both cli-wallet/utils/options/fees.js and wallet-sdk/base-wallet/base_wallet.js call:

const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);

Where MIN_FEE_PADDING is 0.5, so scalar = 1.5. When the node returns fees like feePerL2Gas = 2910685593001n, the multiplication produces:

Number(2910685593001n) * 1.5 = 4366028389501.5

Which then fails:

TypeError: The number 4366028389501.5 cannot be converted to a BigInt because it is not an integer

Location

@aztec/stdlib/dest/gas/gas_fees.js, line 40:

mul(scalar) {
    if (scalar === 1 || scalar === 1n) {
        return this.clone();
    } else if (typeof scalar === 'bigint') {
        return new GasFees(this.feePerDaGas * scalar, this.feePerL2Gas * scalar);
    } else {
        // BUG: this can produce non-integer results
        return new GasFees(Number(this.feePerDaGas) * scalar, Number(this.feePerL2Gas) * scalar);
    }
}

Suggested Fix

Wrap in Math.ceil() (or Math.round()):

return new GasFees(
    Math.ceil(Number(this.feePerDaGas) * scalar),
    Math.ceil(Number(this.feePerL2Gas) * scalar)
);

Math.ceil makes sense here since this is used for fee estimation — rounding up is safer than rounding down.

Environment

  • @aztec/stdlib versions: 4.1.2, 4.1.3 (both affected)
  • Hit on Aztec Alpha mainnet where real gas prices produce large values

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions