Skip to content

Commit b92990e

Browse files
committed
fix edge cases
1 parent ab68cf1 commit b92990e

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

app/abci.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) (*abci.
8181

8282
res := &abci.ResponseCheckTxV2{
8383
ResponseCheckTx: &abci.ResponseCheckTx{
84-
GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints?
84+
GasWanted: int64(gInfo.GasWanted), //nolint:gosec
8585
Data: result.Data,
8686
Priority: txCtx.Priority(),
87-
GasEstimated: int64(gInfo.GasEstimate),
87+
GasEstimated: int64(gInfo.GasEstimate), //nolint:gosec
8888
},
8989
ExpireTxHandler: txCtx.ExpireTxHandler(),
9090
CheckTxCallback: txCtx.CheckTxCallback(),

app/ante/cosmos_checktx.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,25 @@ func CosmosCheckTxAnte(
8080
returnErr = HandleOutofGas(r, tx.(GasTx).GetGas(), ctx.GasMeter().GasConsumed())
8181
}
8282
}()
83-
gasMeter, err := GetGasMeter(ctx.WithGasMeter(storetypes.NewNoConsumptionInfiniteGasMeter()), tx, oraclek, ek, pk)
83+
gasMeter, isGasless, err := GetGasMeter(ctx.WithGasMeter(storetypes.NewNoConsumptionInfiniteGasMeter()), tx, oraclek, ek, pk)
8484
if err != nil {
8585
return ctx, err
8686
}
8787
ctx = ctx.WithGasMeter(gasMeter)
8888

89-
priority, err := CheckAndChargeFees(ctx, tx, accountKeeper, bankKeeper, feegrantKeeper, pk)
90-
if err != nil {
91-
return ctx, err
89+
if !isGasless {
90+
priority, err := CheckAndChargeFees(ctx, tx, accountKeeper, bankKeeper, feegrantKeeper, pk)
91+
if err != nil {
92+
return ctx, err
93+
}
94+
if priority > antedecorators.MaxPriority {
95+
ctx = ctx.WithPriority(antedecorators.MaxPriority)
96+
} else {
97+
ctx = ctx.WithPriority(priority)
98+
}
9299
}
93100
if oracleVote {
94101
ctx = ctx.WithPriority(antedecorators.OraclePriority)
95-
} else if priority > antedecorators.MaxPriority {
96-
ctx = ctx.WithPriority(antedecorators.MaxPriority)
97-
} else {
98-
ctx = ctx.WithPriority(priority)
99102
}
100103

101104
authParams := accountKeeper.GetParams(ctx)
@@ -144,7 +147,7 @@ func CosmosStatelessChecks(tx sdk.Tx, height int64, consensusParams *tmproto.Con
144147
if cp := consensusParams; cp != nil && cp.Block != nil {
145148
// If there exists a maximum block gas limit, we must ensure that the tx
146149
// does not exceed it.
147-
if cp.Block.MaxGas > 0 && gasTx.GetGas() > uint64(cp.Block.MaxGas) {
150+
if cp.Block.MaxGas > 0 && gasTx.GetGas() > uint64(cp.Block.MaxGas) { //nolint:gosec
148151
return false, sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "tx gas wanted %d exceeds block max gas limit %d", gasTx.GetGas(), cp.Block.MaxGas)
149152
}
150153
}
@@ -192,7 +195,7 @@ func CosmosStatelessChecks(tx sdk.Tx, height int64, consensusParams *tmproto.Con
192195
}
193196

194197
timeoutHeight := timeoutTx.GetTimeoutHeight()
195-
if timeoutHeight > 0 && uint64(height) > timeoutHeight {
198+
if timeoutHeight > 0 && uint64(height) > timeoutHeight { //nolint:gosec
196199
return oracleVote, sdkerrors.Wrapf(
197200
sdkerrors.ErrTxTimeoutHeight, "block height: %d, timeout height: %d", height, timeoutHeight,
198201
)
@@ -244,17 +247,17 @@ func GetGasMeter(
244247
ctx sdk.Context, tx sdk.Tx, oracleKeeper oraclekeeper.Keeper,
245248
evmKeeper *evmkeeper.Keeper,
246249
paramsKeeper paramskeeper.Keeper,
247-
) (sdk.GasMeter, error) {
250+
) (sdk.GasMeter, bool, error) {
248251
// TODO: may not be necessary for CheckTx
249252
isGasless, err := antedecorators.IsTxGasless(tx, ctx, oracleKeeper, evmKeeper)
250253
if err != nil {
251-
return nil, err
254+
return nil, false, err
252255
}
253256
if !isGasless {
254257
cosmosGasParams := paramsKeeper.GetCosmosGasParams(ctx)
255-
return storetypes.NewMultiplierGasMeter(tx.(GasTx).GetGas(), cosmosGasParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierDenominator), nil
258+
return storetypes.NewMultiplierGasMeter(tx.(GasTx).GetGas(), cosmosGasParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierDenominator), isGasless, nil
256259
}
257-
return ctx.GasMeter(), nil
260+
return ctx.GasMeter(), isGasless, nil
258261
}
259262

260263
func CheckAndChargeFees(ctx sdk.Context, tx sdk.Tx, accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, feegrantKeeper *feegrantkeeper.Keeper, paramsKeeper paramskeeper.Keeper) (priority int64, err error) {
@@ -280,7 +283,7 @@ func CheckAndChargeFees(ctx sdk.Context, tx sdk.Tx, accountKeeper authkeeper.Acc
280283
}
281284
}
282285
if gas > 0 {
283-
priority = authante.GetTxPriority(feeCoins, int64(gas))
286+
priority = authante.GetTxPriority(feeCoins, int64(gas)) //nolint:gosec
284287
}
285288
if addr := accountKeeper.GetModuleAddress(authtypes.FeeCollectorName); addr == nil {
286289
return priority, fmt.Errorf("fee collector module account (%s) has not been set", authtypes.FeeCollectorName)
@@ -362,7 +365,7 @@ func CheckPubKeys(ctx sdk.Context, tx sdk.Tx, accountKeeper authkeeper.AccountKe
362365
accountKeeper.SetAccount(ctx, acc)
363366

364367
sigCount += authante.CountSubKeys(pk)
365-
if uint64(sigCount) > authParams.TxSigLimit {
368+
if uint64(sigCount) > authParams.TxSigLimit { //nolint:gosec
366369
return sdkerrors.Wrapf(sdkerrors.ErrTooManySignatures,
367370
"signatures: %d, limit: %d", sigCount, authParams.TxSigLimit)
368371
}

app/ante/evm_checktx.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ func EvmCheckTxAnte(
4747
return ctx, err
4848
}
4949
msg := tx.GetMsgs()[0].(*evmtypes.MsgEVMTransaction)
50-
etx, txData := msg.AsTransaction() // cached and validated
5150

51+
txData, _ := evmtypes.UnpackTxData(msg.Data) // cached and validated
5252
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeterWithMultiplier(ctx))
5353
if atx, ok := txData.(*ethtx.AssociateTx); ok {
5454
return HandleAssociateTx(ctx, ek, atx)
5555
}
56+
etx := ethtypes.NewTx(txData.AsEthereumData())
5657
evmAddr, seiAddr, seiPubkey, version, err := CheckAndDecodeSignature(ctx, txData, chainID)
5758
if err != nil {
5859
return ctx, err
@@ -134,6 +135,9 @@ func EvmStatelessChecks(ctx sdk.Context, tx sdk.Tx, chainID *big.Int) error {
134135
if err != nil {
135136
return err
136137
}
138+
if _, ok := txData.(*ethtx.AssociateTx); ok {
139+
return nil
140+
}
137141
etx, _ := msg.AsTransaction()
138142
if etx.To() == nil && len(etx.Data()) > params.MaxInitCodeSize {
139143
return fmt.Errorf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(etx.Data()), params.MaxInitCodeSize)

0 commit comments

Comments
 (0)