Skip to content

Commit

Permalink
consensus: Ban empty v2 transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Oct 28, 2024
1 parent bbe823b commit 1fcd548
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ func (s State) V2TransactionWeight(txn types.V2Transaction) uint64 {
for _, a := range txn.Attestations {
a.EncodeTo(e)
}
e.WriteBytes(txn.ArbitraryData)
e.Write(txn.ArbitraryData)
e.Flush()
return uint64(wc.n)
}

Expand Down
4 changes: 3 additions & 1 deletion consensus/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,9 @@ func ValidateV2Transaction(ms *MidState, txn types.V2Transaction) error {
return errors.New("v2 transactions are not allowed until v2 hardfork begins")
} else if err := validateV2CurrencyOverflow(ms, txn); err != nil {
return err
} else if weight := ms.base.V2TransactionWeight(txn); weight > ms.base.MaxBlockWeight() {
} else if weight := ms.base.V2TransactionWeight(txn); weight == 0 {
return errors.New("transactions cannot be empty")
} else if weight > ms.base.MaxBlockWeight() {
return fmt.Errorf("transaction exceeds maximum block weight (%v > %v)", weight, ms.base.MaxBlockWeight())
} else if err := validateV2Siacoins(ms, txn); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,12 @@ func TestValidateV2Block(t *testing.T) {
})
},
},
{
"empty v2 transaction",
func(b *types.Block) {
b.V2.Transactions = append(b.V2.Transactions, types.V2Transaction{})
},
},
{
"wrong parent ID",
func(b *types.Block) {
Expand Down

0 comments on commit 1fcd548

Please sign in to comment.