Skip to content

Commit

Permalink
Fix panic: runtime error: negative shift amount on eliasfano reverse …
Browse files Browse the repository at this point in the history
…iterator seek (#12520)

Fixes an edge case for the rpc-test
`ots_searchTransactionsBefore/test13`.

- It occurs on a specially crafted eliasfano sequence on mainnet.
- Reverse iterator seeks a value whose upper bit is set at the 63th bit
of the 64 bit word.
- The seek operation locates the target, but position the cursor at the
previous element; but because the way it is coded, the position of the
upper part of the value is already positioned at the next element
(previous value in this case because of the reverse iterator).

I also:

- reenabled the rpc-test which was breaking because of this case.
- added a similar test for the forward iterator for the sake of
completeness (it was NOT breaking, just increasing coverage).
  • Loading branch information
wmitsuda authored Oct 29, 2024
1 parent 6916ff6 commit b7b8509
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/qa-rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ jobs:
ots_getBlockTransactions/test_03.json,\
ots_getBlockTransactions/test_04.json,\
ots_getBlockTransactions/test_05.json,\
ots_searchTransactionsBefore/test_13.json,\
trace_call/test_05.json,\
trace_call/test_07.json,\
trace_call/test_12.json,\
Expand Down
6 changes: 5 additions & 1 deletion erigon-lib/recsplit/eliasfano32/elias_fano.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ func (efi *EliasFanoIter) Seek(n uint64) {

// fields of next value
efi.lowerIdx -= efi.itemsIterated * efi.l
efi.upperMask = 1 << (sel - 1)
if sel > 0 {
efi.upperMask = 1 << (sel - 1)
} else {
efi.upperMask = 0
}
} else {
efi.itemsIterated = nextI

Expand Down
Loading

0 comments on commit b7b8509

Please sign in to comment.