core/types/bal: fix off-by-one in balance change index bounds check

The balance change index validation used > blockTxCount+2 which
allowed index blockTxCount+2 (out of bounds). Changed to >=
to match the nonce, code, and storage change checks.

Valid BAL indices are 0..blockTxCount+1. Index blockTxCount+2
is beyond the system transaction index and must be rejected.

Found by test_bal_invalid_extraneous_entries[out_of_bounds-extra_balance]
in bal@v5.5.1 fixtures.
This commit is contained in:
spencer-tb 2026-03-27 12:05:08 +00:00
parent 0253db6ce5
commit 076a330416

View file

@ -367,7 +367,7 @@ func (e *AccountAccess) validate(blockTxCount int) error {
return errors.New("balance changes not in ascending order by tx index")
}
if len(e.BalanceChanges) > 0 && int(e.BalanceChanges[len(e.BalanceChanges)-1].TxIdx) > blockTxCount+2 {
if len(e.BalanceChanges) > 0 && int(e.BalanceChanges[len(e.BalanceChanges)-1].TxIdx) >= blockTxCount+2 {
return errors.New("highest balance change index beyond what is allowed")
}
// check that the balance values are set and there are no duplicate index entries