High severity

Storage array modified by value

Updated 2026-11-10

In Solidity an array variable can live in storage, where it persists between calls, or in memory, a scratch space that vanishes when the call returns. When you pass an array to a function, the parameter’s declared data location decides which you get. Declare the parameter storage and the function receives a reference to the caller’s array: writes go straight to the chain. Declare it memory and the function receives a fresh copy: writes land on the copy and are thrown away when the function returns. A helper written to update a storage array, but whose parameter says memory, compiles and runs without reverting, but changes nothing. The caller’s balances, queue, or allowlist stay exactly as they were, and nothing on-chain signals that the update was lost.

Vulnerable pattern

_bump takes the array by value, so the credit never persists
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Ledger {
    uint256[] public balances; // storage

    function credit(uint256 i, uint256 amount) external {
        _bump(balances, i, amount); // intends to update balances[i]
    }

    // Parameter is `memory`, so `arr` is a throwaway copy of the storage array.
    function _bump(uint256[] memory arr, uint256 i, uint256 amount) internal {
        arr[i] += amount; // writes to the copy; balances is untouched
    }
}

A caller invokes credit expecting balances[i] to grow by amount. The transaction succeeds, no event or revert hints at trouble, and balances[i] is unchanged. The write inside _bump updated the memory copy that the EVM discards at the end of the internal call. If credit records deposits, rewards or vote tallies, each one is lost while the surrounding accounting treats it as booked. A test suite that only checks that the call succeeded will not catch it.

The fix

Change one word: declare the parameter storage so the function works on the caller’s array by reference. The write then reaches the chain. If the helper needs a scratch copy and the caller needs the result, return the modified array and have the caller reassign it; to change state in place, use storage. Make every array, struct and mapping parameter’s location explicit, and never use memory on a parameter you mean to persist.

The parameter is storage: the write updates balances on-chain
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Ledger {
    uint256[] public balances;

    function credit(uint256 i, uint256 amount) external {
        _bump(balances, i, amount);
    }

    // `storage`: `arr` references the caller's array, so the write persists.
    function _bump(uint256[] storage arr, uint256 i, uint256 amount) internal {
        arr[i] += amount;
    }
}

A note on scope

Modern Solidity narrowed this mistake but did not rule it out. Before version 0.5.0 the data location on a parameter was optional and defaulted to memory, so a developer could leave it off, assume the array was passed by reference, and lose every write without ever typing the word memory. Since 0.5.0 the location is mandatory on array, struct, and mapping parameters, which replaces the silent default with an explicit keyword, but a developer who writes memory out of habit, or copies a signature, still hits the same lost write. The detector flags the call site whenever a storage array is passed to a function whose matching parameter is not storage and that function writes to it. It reasons about the write, so a helper that takes a memory array and only reads it is not flagged; the finding means a write you probably expected to persist will not. It is rated high impact at high confidence because the mistake changes nothing visibly while breaking the contract’s core bookkeeping.

Scan your contract for this

pactlint flags array-by-reference and other recurring DeFi bug classes in Solidity source or a verified contract on Ethereum or Base. Pay per call in USDC on Base, Polygon, Solana, BNB Chain or Arbitrum with x402, or on Tempo with MPP, no signup; the first few scans each day are free.

How to scan →

A storage array passed by value is detected by Slither’s stock array-by-reference detector, rated high impact at high confidence. Because high impact only ever drops a notch when confidence is low, pactlint surfaces this one at high severity, and it runs no worker-side triage on it: it is neither suppressed as noise nor downgraded, so a reported finding stays High as the analyser rates it. Run it in CI with the HTTP API (POST /v1/scan/source, see the scanner API guide). Heuristic and educational, not an audit.