# The colRedeemed variable is wrongly retrieved in LibBytes::readProposalData function

Inline assembly in LibBytes::readProposalData used `add` instead of `and` to mask colRedeemed, corrupting the 11-byte field read during redemption claims.

- Payout: Audit contest
- Severity: medium
- Program: DittoETH
- Found by: Bube
- Disclosed: 2024-06-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-03-dittoeth-findings/issues/221
- Library page: https://bugbountylibrary.com/r/c4%3A2024-03-dittoeth%3AM-03
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** DittoETH LibBytes::readProposalData / RedemptionFacet.claimRedemption
**Root cause:** Assembly mask applied with `add(0xffffffffffffffffffffff, shr(80, fullWord))` instead of `and(...)`, so the mask constant is added to the shifted word rather than isolating the low 11 bytes.
**Steps:**
1. Read LibBytes.sol line 42: `colRedeemed := add(0xffffffffffffffffffffff, shr(80, fullWord))`
2. Note the mask should be applied with `and`, not `add`
3. Reproduce in Foundry: deploy Assembly contract with incorrectColRedeemed and correctColRedeemed
4. Call both with `testFullWord = 0x1234599990abcdef...` and observe incorrect < correct
5. Confirm RedemptionFacet.claimRedemption consumes the corrupted colRedeemed
**How found:** Code review of inline assembly in LibBytes, spotting the `add` where a bitmask `and` was intended.
**Exploitation:** Not described; impact is incorrect colRedeemed value flowing into claimRedemption, corrupting redemption accounting.
**Insight:** When auditing hand-written assembly bit-packing, verify each field uses `and` for masking and `shr` for shifting; a stray `add` silently corrupts packed struct reads that unit tests with round numbers may miss.

## Proof of concept (copied exactly from the original report)

**Buggy add vs correct and assembly contract**

```
contract Assembly {
    function incorrectColRedeemed(uint256 fullWord) public pure returns (uint88) {
        uint88 col;
        assembly {
            col := add(0xffffffffffffffffffffff, shr(80, fullWord))
        }
        return col;
    }

    function correctColRedeemed(uint256 fullWord) public pure returns (uint256) {
        uint88 col;
        assembly {
            col := and(0xffffffffffffffffffffff, shr(80, fullWord))
        }
        return col;
    }
}
```

**Test comparing incorrect and correct results**

```
contract TestAssembly is Test {

    Assembly asm = new Assembly();

    uint256 testFullWord = 0x1234599990abcdef1234567890abcdef1234567890abcdef1234567890abcdef;

    function test_assembly() external view {
        assert(asm.incorrectColRedeemed(testFullWord) < asm.correctColRedeemed(testFullWord));
        console.log('Incorrect:', asm.incorrectColRedeemed(testFullWord));
        console.log('Correct: ', asm.correctColRedeemed(testFullWord));
    }
```

