Skip to content
Smart contracts Audit finding Intermediate

Bug in AccountEncoder causes wrong Solana account permissions

A parsing bug in the AccountEncoder library causes the isWritable flag for Solana accounts to always be set to true, even when users intend them to be read-only. This affects all Solana bridge transactions with multiple accounts, potentially allowing unauthorised token transfers or account state changes.

1337 Follow with EgisSecurity, Goran and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/633

Found by

1337, EgisSecurity, Goran, HeckerTrieuTien, JuggerNaut, coin2own, dhank

Summary

When users bridge assets to Solana, they specify a list of accounts and if accounts should be read-only (protected) versus writable (modifiable). This is a critical security feature that prevents unauthorized access to user funds. However, a data parsing bug in AccountEncoder systematically corrupts these permission settings, marking user accounts as writable when they should be protected as read-only. This affects 100% of Solana bridge transactions. As a consequence, potential unauthorized token transfers or account state changes can occur.

Root Cause

Library AccountEncoder implements decompressAccounts function which takes bytes array as input and parses account info out of it:

Solidity
    function decompressAccounts(bytes memory input) internal pure returns (Account[] memory accounts) {
        assembly {
              let ptr := add(input, 32)
  
              // Read accounts length (uint16)
              let len := add(shl(8, byte(0, mload(ptr))), byte(1, mload(ptr)))
              ptr := add(ptr, 2)
  
              // Allocate memory for Account[] array
              accounts := mload(0x40)
              mstore(accounts, len)
              let arrData := add(accounts, 32)

            // Prepare memory for Account structs
            let freePtr := add(arrData, mul(len, 32))

            for { let i := 0 } lt(i, len) { i := add(i, 1) } {
                let acc := freePtr
                freePtr := add(freePtr, 64)

                // Load publicKey
                mstore(acc, mload(ptr))
                ptr := add(ptr, 32)

                // Load isWritable (as bool)
                 // @audit Reads 32 bytes for 1-byte boolean
                mstore(add(acc, 32), iszero(iszero(mload(ptr))))
                ptr := add(ptr, 1)

                // Store pointer to struct in the array
                mstore(add(arrData, mul(i, 32)), acc)
            }

            mstore(0x40, freePtr)
        }
    }

In the assembly loop, the code reads 32 bytes with mload(ptr) when parsing boolean values that should only be 1 byte. This causes the boolean logic iszero(iszero(...)) to evaluate the intended 1-byte boolean plus the first 31 bytes of the next account's public key. Since public keys contain non-zero bytes, the boolean always becomes true regardless of the user's intention.

Internal Pre-conditions

  1. User initiates Solana bridge transaction (decoded.dstChainId == SOLANA_EDDY)
  2. Transaction contains multiple accounts in compressed format
  3. Function decompressAccounts() is called to parse account metadata before Solana execution

External Pre-conditions

None

Attack Path

This is not an attack but systematic corruption affecting every multi-account Solana transaction:

  1. User provides correctly formatted compressed account data: [count][pubkey1][bool1][pubkey2][bool2]
  2. User intends Account 1 as read-only (bool1 = false) to protect their token balance
  3. decompressAccounts() parses Account 1's boolean by reading [bool1 + first_31_bytes_of_pubkey2]
  4. Since pubkey2 contains non-zero bytes, iszero(iszero(non-zero)) returns true
  5. Account 1 gets marked as isWritable: true instead of user's intended false
  6. Transaction executes on Solana with corrupted permissions
  7. Solana programs can now modify Account 1 when user expected it to remain untouched
  8. Potential unauthorized token transfers or account state changes occur

Impact

High severity - user accounts intended as read-only systematically get marked as writeable. This affects 100% of Solana bridge transactions with multiple accounts and occurs silently without any indication to users that their security assumptions are violated, potentially resulting in unexpected fund drains or account modifications.

PoC

This test case showcases the problem:

Solidity
    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);
    }

Run it:

Bash
❯ forge test --mt test_accounts -vvv

Logs:
  ----User provided values:
  0xb335f44a2f5f0b13a7007be5f03a32df2fe6c27804d6e6ea21294eb0705e09b4
  false
  0x2186009e2f515bf15a0990ff378c583734095fd9ed9c46c3d15e33a8daf0a619
  true


  ----Parsed values
  0xb335f44a2f5f0b13a7007be5f03a32df2fe6c27804d6e6ea21294eb0705e09b4
  true
  0x2186009e2f515bf15a0990ff378c583734095fd9ed9c46c3d15e33a8daf0a619
  true

We can see that the "isWriteable" flag for the first account got parsed as true when it is actually false

Mitigation

Extract only the first byte:

Solidity
mstore(add(acc, 32), shr(248, mload(ptr)))  

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Skyewwww/omni-chain-contracts/pull/31

The original report as published on Sherlock, by 1337. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The assembly code reads 32 bytes for a boolean value that is only 1 byte, so the boolean check includes bytes from the next account's public key, which are non-zero and make the boolean always true.

Impact

User accounts intended as read-only are systematically marked writable, potentially leading to unauthorised token transfers or account state changes in all Solana bridge transactions with multiple accounts.

What the attacker needed

Solana bridge transaction; multiple accounts in compressed format

The fix

The issue was fixed by extracting only the first byte of the boolean value using a shift operation.

How it was found

  1. User provides correctly formatted compressed account data with a read-only flag for the first account.
  2. The decompressAccounts function parses the boolean by reading 32 bytes instead of 1.
  3. The extra bytes come from the next account's public key, which are non-zero.
  4. The boolean check returns true, marking the account as writable.
  5. The transaction executes on Solana with the account marked writable instead of read-only.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you send assets to another blockchain, you specify which accounts the destination program can modify. A bug in the code that reads this list mistakenly marks every account as modifiable, even if you said it should be read-only. This means a program could change balances or data you expected to be protected.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 1337

View all

1 more disclosed report, best first.

More from DODO Cross-Chain DEX

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.