Skip to content

Commit ea7037c

Browse files
committed
core/rawdb: put back bit length assertions
1 parent 6124e29 commit ea7037c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/rawdb/accessors_indexes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ func ReadCanonicalRawReceipt(db ethdb.Reader, blockHash common.Hash, blockNumber
318318
// https://eips.ethereum.org/EIPS/eip-7745#hash-tree-structure
319319
func ReadFilterMapExtRow(db ethdb.KeyValueReader, mapRowIndex uint64, bitLength uint) ([]uint32, error) {
320320
byteLength := int(bitLength) / 8
321+
if int(bitLength) != byteLength*8 {
322+
panic("invalid bit length")
323+
}
321324
key := filterMapRowKey(mapRowIndex, false)
322325
has, err := db.Has(key)
323326
if err != nil {
@@ -344,6 +347,9 @@ func ReadFilterMapExtRow(db ethdb.KeyValueReader, mapRowIndex uint64, bitLength
344347

345348
func ReadFilterMapBaseRows(db ethdb.KeyValueReader, mapRowIndex uint64, rowCount uint32, bitLength uint) ([][]uint32, error) {
346349
byteLength := int(bitLength) / 8
350+
if int(bitLength) != byteLength*8 {
351+
panic("invalid bit length")
352+
}
347353
key := filterMapRowKey(mapRowIndex, true)
348354
has, err := db.Has(key)
349355
if err != nil {
@@ -403,6 +409,9 @@ func ReadFilterMapBaseRows(db ethdb.KeyValueReader, mapRowIndex uint64, rowCount
403409
// or deletes any existing entry if the row is empty.
404410
func WriteFilterMapExtRow(db ethdb.KeyValueWriter, mapRowIndex uint64, row []uint32, bitLength uint) {
405411
byteLength := int(bitLength) / 8
412+
if int(bitLength) != byteLength*8 {
413+
panic("invalid bit length")
414+
}
406415
var err error
407416
if len(row) > 0 {
408417
encRow := make([]byte, len(row)*byteLength)
@@ -422,6 +431,9 @@ func WriteFilterMapExtRow(db ethdb.KeyValueWriter, mapRowIndex uint64, row []uin
422431

423432
func WriteFilterMapBaseRows(db ethdb.KeyValueWriter, mapRowIndex uint64, rows [][]uint32, bitLength uint) {
424433
byteLength := int(bitLength) / 8
434+
if int(bitLength) != byteLength*8 {
435+
panic("invalid bit length")
436+
}
425437
var entryCount, zeroBits int
426438
for i, row := range rows {
427439
if len(row) > 0 {

0 commit comments

Comments
 (0)