Submitted by Bube, also found by maxim371 and Rhaydden
The LibBytes::readProposalData function uses inline assembly for efficient data extraction from a byte array. The colRedeemed variable, which represents an 11-byte value within the ProposalData structure, is intended to be extracted by applying a mask to isolate the relevant bytes. However, the current implementation incorrectly uses the add operation. That leads to retrieve incorrect value of colRedeemed variable:
The add operation would incorrectly add the mask to the shifted value, potentially resulting in an incorrect value for colRedeemed. The correct operation should use and to apply the mask and isolate the 11-byte colRedeemed value.
The RedemptionFacet contract calls the LibBytes::readProposalData function and uses colRedeemed variable in claimRedemption function.
Link to the code here.
The following contract Assembly is a simple contract that contains two functions: incorrectColRedeemed with the logic from the LibBytes contract and the correctColRedeemed with the correct logic:
The following test file contains test function test_assembly that compares the returned value from the both functions and shows the differences between the results:
Foundry
Replace the add operation with an and operation to correctly apply the mask:
colRedeemed := and(0xffffffffffffffffffffff, shr(80, fullWord)).
ditto-eth (DittoETH) confirmed
