From fd9130d7df9957880579be6ed44f99ee05b4f17a Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Tue, 6 Oct 2020 10:52:23 +0200 Subject: [PATCH 1/2] Prevent integer overflow --- x/wasm/internal/keeper/keeper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index e52a148b111..51e9da1fbaa 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -566,6 +566,10 @@ func (k Keeper) dispatchMessages(ctx sdk.Context, contractAddr sdk.AccAddress, m func gasForContract(ctx sdk.Context) uint64 { meter := ctx.GasMeter() + // avoid integer overflow + if meter.IsOutOfGas() { + return 0 + } remaining := (meter.Limit() - meter.GasConsumed()) * GasMultiplier if remaining > MaxGas { return MaxGas From 5fbf4ae7c7dfde5e37378dadc10e706e8268d45f Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 7 Oct 2020 11:59:57 +0200 Subject: [PATCH 2/2] Review feedback --- x/wasm/internal/keeper/keeper.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 51e9da1fbaa..c85be35900f 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -566,11 +566,10 @@ func (k Keeper) dispatchMessages(ctx sdk.Context, contractAddr sdk.AccAddress, m func gasForContract(ctx sdk.Context) uint64 { meter := ctx.GasMeter() - // avoid integer overflow if meter.IsOutOfGas() { return 0 } - remaining := (meter.Limit() - meter.GasConsumed()) * GasMultiplier + remaining := (meter.Limit() - meter.GasConsumedToLimit()) * GasMultiplier if remaining > MaxGas { return MaxGas }