Submitted by Trust, also found by kutugu
https://github.com/code-423n4/2023-07-basin/blob/c1b72d4e372a6246e0efbd57b47fb4cbb5d77062/src/libraries/LibBytes16.sol#L45 https://github.com/code-423n4/2023-07-basin/blob/c1b72d4e372a6246e0efbd57b47fb4cbb5d77062/src/libraries/LibLastReserveBytes.sol#L58
The MultiFlowPump contract stores reserve counts on every update, using the libraries LibBytes16 and LibLastReserveBytes. Those libs pack bytes16 values efficiently with the storeBytes16() and storeLastReserves functions.
In case of an odd number of items, the last storage slot will be half full. Care must be taken to not step over the previous value in that slot. This is done correctly in LibBytes:
As can be seen, it overwrites the slot with the previous 128 bits in the upper half of the slot, only setting the lower 128 bytes.
However, the wrong slot is read in the other two libraries. For example, in storeLastReserves():
The error is not multiplying maxI before adding it to slot. This means that the reserves count encoded in lower 16 bytes in add(slot, mul(maxI, 32)) will have the value of a reserve in a much lower index.
Slots are used in 32 byte increments, i.e. S, S+32, S+64
When maxI==0, the intended slot and the actual slot overlap. When maxI is 1..31, the read slot happens to be zero (unused), so the first actual corruption occurs on maxI==32. By substitution, we get:
SLOT[32*32] = correct reserve | SLOT[32]
In other words, the 4rd reserve (stored in lower 128 bits of  SLOT[32]) will be written to the 64th reserve.
The Basin pump is intended to support an arbitrary number of reserves safely, therefore the described storage corruption impact is in scope.
Reserve amounts in the pump will be corrupted, resulting in wrong oracle values.
Change the sload() operation in both affected functions to sload(add(slot, mul(maxI, 32)
publiuss (Basin) confirmed, but disagreed with severity and commented:
alcueca (Judge) decreased severity to Medium and commented:
