Skip to content

Commit 9817941

Browse files
authored
Merge pull request #6548 from oasisprotocol/peternose/trivial/limit-tx-size
go/consensus/cometbft/abci/transaction: Limit tx size in gas estimation
2 parents 420d110 + 5a932ad commit 9817941

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

.changelog/6548.trivial.md

Whitespace-only changes.

go/consensus/cometbft/abci/transaction.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ func (mux *abciMux) EstimateGas(caller signature.PublicKey, tx *transaction.Tran
154154
return 0, consensus.ErrInvalidArgument
155155
}
156156

157+
// Check transaction size against maximum allowed size. This is necessary
158+
// to prevent DoS attacks by sending large transactions that consume
159+
// a lot of resources during simulation.
160+
params := mux.state.ConsensusParameters()
161+
if params == nil {
162+
return 0, consensus.ErrNoCommittedBlocks
163+
}
164+
165+
if params.MaxTxSize > 0 {
166+
rawTx := cbor.Marshal(tx)
167+
if uint64(len(rawTx)) > params.MaxTxSize {
168+
return 0, consensus.ErrOversizedTx
169+
}
170+
}
171+
157172
// Certain modules, in particular the beacon require InitChain or BeginBlock
158173
// to have completed before initialization is complete.
159174
if mux.state.LastHeight() == 0 {

0 commit comments

Comments
 (0)