-
Notifications
You must be signed in to change notification settings - Fork 592
GasFees.mul() throws BigInt error when scalar is a float #22294
Copy link
Copy link
Open
Description
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/stdlibversions: 4.1.2, 4.1.3 (both affected)- Hit on Aztec Alpha mainnet where real gas prices produce large values
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels