# Bug in AccountEncoder causes wrong Solana account permissions

AccountEncoder.decompressAccounts reads 32 bytes for a 1-byte isWritable flag, so Solana accounts meant read-only are parsed writable in every multi-account bridge tx.

- Payout: Audit contest
- Severity: medium
- Program: Dodo Cross Chain Dex
- Found by: 1337
- Disclosed: 2025-05-29
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/633
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-dodo-cross-chain-dex%3AM-4
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solana tech:solidity technique:source-review vuln:access-control

**Target:** Solidity AccountEncoder library (decompressAccounts) used in Solana bridge path
**Root cause:** Assembly loop uses `mload(ptr)` (32 bytes) to read a 1-byte boolean, so `iszero(iszero(...))` incorporates the next account's pubkey bytes and always yields true.
**Steps:**
1. Encode compressed accounts `[uint16 count][pubkey32][bool1][pubkey32][bool1]...` with first account isWritable=false
2. Call `AccountEncoder.decompressAccounts(compressed)`
3. Observe parsed `accounts[0].isWritable == true` despite input false, because mload reads bool1 plus 31 bytes of pubkey2
4. Fix: `mstore(add(acc,32), shr(248, mload(ptr)))`
**How found:** Code review of the assembly parser: noticed `mload(ptr)` reads 32 bytes for a 1-byte boolean and reasoned the following pubkey bytes would force the flag true; confirmed with a Foundry PoC.
**Insight:** In hand-written assembly parsers, audit every `mload` against the declared field width in the packed format — a 32-byte read of a 1-byte field silently absorbs adjacent data and can flip booleans or corrupt offsets.

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

**Test showing read-only account parsed as writable**

```
function test_accounts() public {
        bytes32[] memory publicKeys = new bytes32[](2);
        publicKeys[0] = keccak256(abi.encodePacked(block.timestamp));
        publicKeys[1] = keccak256(abi.encodePacked(block.timestamp + 1));
        bool[] memory isWritables = new bool[](2);
        isWritables[0] = false;
        isWritables[1] = true;

        console.log("----User provided values:");

        console.logBytes32(publicKeys[0]);
        console.log(isWritables[0]);

        console.logBytes32(publicKeys[1]);
        console.log(isWritables[1]);

        bytes memory compressed = compressAccounts(publicKeys, isWritables);

        console.log("\n");
        console.log("(----Parsed values");

        console.logBytes32(AccountEncoder.decompressAccounts(compressed)[0].publicKey);
        console.log(AccountEncoder.decompressAccounts(compressed)[0].isWritable);

        console.logBytes32(AccountEncoder.decompressAccounts(compressed)[1].publicKey);
        console.log(AccountEncoder.decompressAccounts(compressed)[1].isWritable);
    }
```

