cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

[Bug]: `SDKGasMeter.GasConsumedToLimit` returns incorrect values

Open chipshort opened this issue 1 year ago • 2 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

What happened?

SDKGasMeter's GasConsumedToLimit function returns remaining gas instead of consumed gas.

I also don't see this type used anywhere in the SDK. What is it for?

Cosmos SDK Version

main

How to reproduce?

No response

chipshort avatar Aug 28 '24 10:08 chipshort

Hey! This is used in runTx, and it's run on every tx.

The implementation is the following:

// GasConsumedToLimit returns the gas limit if gas consumed is past the limit,
// otherwise it returns the consumed gas.
//
// NOTE: This behavior is only called when recovering from panic when
// BlockGasMeter consumes gas past the limit.
func (g *basicGasMeter) GasConsumedToLimit() Gas {
	if g.IsPastLimit() {
		return g.limit
	}
	return g.consumed
}

It looks correct to me, why do you think it is returning the remaining gas? Do you have an example?

We also have the function GasRemaining() btw

facundomedica avatar Aug 28 '24 11:08 facundomedica

I am not talking about basicGasMeter. I am talking about SDKGasMeter. I linked to the exact line in the code in my first post: https://github.com/cosmos/cosmos-sdk/blob/01abf4fbf92c72ab4d13a983e730dc006db19b27/runtime/gas.go#L65

chipshort avatar Aug 28 '24 12:08 chipshort