# Bitmask and shift isolation bug

Bit checks that shift or mask the whole word, letting neighbouring set bits corrupt the result

_Area: Smart contract access control and control flow. Seen in 2 disclosed reports; latest 2025-08-21. Updated 2026-11-17._

## How it works
A bitmap stores many independent flags in one word. To test or set one flag you must first isolate that bit, then compare. The bug is skipping the isolation: shifting the whole storage word by the bit index leaves every lower set bit in the result, so the comparison sees neighbours, not just the target bit. A check that should pass then reverts, or a check that should fail passes. The broken assumption is "shifting by N gives me bit N"; it only does if the word is masked first. The same class appears wherever a user-supplied value is tested for truthiness instead of for the exact shape the code needs [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)[E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md).

## Where it shows up
- Assembly or Solidity doing `shr`/`shl`/`xor`/`and` on a packed bitmap, especially claim, incentive, or nonce bitmaps [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)
- Bit tests written as `(word >> i) == 1` or `xor(1, word >> i)` with no mask or shift-back [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)
- Logic that assumes IDs are claimed in increasing order, so lower bits are never set when a higher one is checked [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)
- User-controlled arguments checked only with `if x` / truthiness, where a non-empty list with an empty head is truthy but yields an empty operation [E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md)
- Per-message gas or accounting resets inside a loop over messages in one transaction [E2](https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md)

## How to review
State the invariant: a test of bit N must depend only on bit N. Trace the expression: is the word masked (`and(word, 1 << i)`) or shifted left then right before comparison? If not, construct a state where a lower bit is set and a higher bit is checked, and confirm the result. For truthiness checks, ask what values are truthy versus what values are valid, and whether an attacker can supply a truthy-but-wrong value [E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md). For per-item resets, check whether accounting uses accumulated or last-item values [E2](https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md).

## How finders spotted it
- Read the assembly bit manipulation in `setOrThrow`, noticed the shift acted on the full storage word rather than an isolated bit, then hand-traced two out-of-order incentive IDs to confirm the revert [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)
- Read the `GasPriceVoter` handler, noticed the gas meter was reset per message unlike a reference implementation that accumulates, and confirmed with a multi-message transaction [E2](https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md)
- Read the mutation deconstruction in `statutes.clsp`, noticed only truthiness was checked and that a list with `()` as its head is truthy while yielding an empty operation, then confirmed with minimal simulations [E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md)

## Variants seen
- Bitmap isolation failure causing spurious revert and denial of claims [E1](https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md)
- Truthiness check on a user-supplied list steering control flow into the wrong branch [E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md)
- Per-message accounting reset letting many items share one charge [E2](https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md)

## Impact and severity
E1 blocks claims for a hash, a denial of service on the validator. E3 breaks spend aggregation and can DoS the statutes singleton; combined with a price drop it could block liquidations and governance, pushing vaults toward undercollateralization and depeg, which raises severity well above the base bug [E3](https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md). E2 lets one observer grief block space at low cost [E2](https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md).

## Evidence
- E1: https://bugbountylibrary.com/r/sherlock%3A2024-06-boost-aa-wallet%3AH-2.md
- E2: https://bugbountylibrary.com/r/c4%3A2023-11-zetachain%3AM-18.md
- E3: https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.8.md
