diff --git a/core/services/workflows/metering/metering.go b/core/services/workflows/metering/metering.go index c94fb9c537d..387c371c028 100644 --- a/core/services/workflows/metering/metering.go +++ b/core/services/workflows/metering/metering.go @@ -806,6 +806,9 @@ func (r *Report) creditToSpendingLimits( // accepts fractional decimals ("0.001158"), scientific notation ("1e18"), // and negatives ("-5") func parseNativeGasUnits(s string) (decimal.Decimal, error) { + if strings.ContainsAny(s, "eE") { + return decimal.Zero, fmt.Errorf("spend value in gas units %q is not a non-negative integer", s) + } value, err := decimal.NewFromString(s) if err != nil { return decimal.Zero, err diff --git a/core/services/workflows/metering/metering_test.go b/core/services/workflows/metering/metering_test.go index d770edd5df2..b7b665a4cc5 100644 --- a/core/services/workflows/metering/metering_test.go +++ b/core/services/workflows/metering/metering_test.go @@ -1601,7 +1601,9 @@ func Test_parseNativeGasUnits(t *testing.T) { {name: "integer", input: "115800", want: "115800"}, {name: "large integer", input: "34440000000000", want: "34440000000000"}, {name: "zero", input: "0", want: "0"}, - {name: "exponent with integer value is accepted", input: "1e18", want: "1000000000000000000"}, + {name: "exponent with integer value rejected", input: "1e18", wantErr: true}, + {name: "max exponent rejected", input: "1e2147483647", wantErr: true}, + {name: "min exponent rejected", input: "1e-2147483648", wantErr: true}, {name: "fractional rejected", input: "0.001158", wantErr: true}, {name: "fractional wei rejected", input: "0.5", wantErr: true}, {name: "negative rejected", input: "-5", wantErr: true},