Skip to content

Commit

Permalink
Add max gas limit check in ante handler (#532)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
Context for this change is from an immunefi bug report:

> when process the proposal block, sei protocol will check the gas fee
is valid or not, if totalGasWanted is bigger than
ctx.ConsensusParams().Block.MaxGas will return false,
> 
> And then in the tendermint will reject the proposal in validblock, but
the bad thing is the sei protcol try to process this block in a loop and
will not produce the new block. so will lead to the
> 
> sei network not being able to confirm new transactions.

## Testing performed to validate your change
  • Loading branch information
yzang2019 authored Aug 28, 2024
1 parent 3395ce7 commit f364e37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
var DefaultConsensusParams = &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: 200000,
MaxGas: 2000000,
MaxGas: 100000000,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
Expand Down
7 changes: 7 additions & 0 deletions x/auth/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

newCtx = sud.gasMeterSetter(simulate, ctx, gasTx.GetGas(), tx)

if cp := ctx.ConsensusParams(); cp != nil && cp.Block != nil {
// If there exists a maximum block gas limit, we must ensure that the tx
// does not exceed it.
if cp.Block.MaxGas > 0 && gasTx.GetGas() > uint64(cp.Block.MaxGas) {
return newCtx, sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "tx gas wanted %d exceeds block max gas limit %d", gasTx.GetGas(), cp.Block.MaxGas)
}
}
// Decorator will catch an OutOfGasPanic caused in the next antehandler
// AnteHandlers must have their own defer/recover in order for the BaseApp
// to know how much gas was used! This is because the GasMeter is created in
Expand Down

0 comments on commit f364e37

Please sign in to comment.