Tuesday, June 30, 2026
HomeEthereumSolidity Storage Array Bugs | Ethereum Basis Weblog

Solidity Storage Array Bugs | Ethereum Basis Weblog

Solidity Storage Array Bug Announcement

This weblog publish is about two bugs related to storage arrays that are in any other case unrelated. Each have been current within the compiler for a very long time and have solely been found now despite the fact that a contract containing them ought to very probably present malfunctions in checks.

Daenam Kim with assist from Nguyen Pham, each from Curvegrid found a problem the place invalid knowledge is saved in reference to arrays of signed integers.

This bug has been current since Solidity 0.4.7 and we think about it the extra critical of the 2. If these arrays use detrimental integers in a sure scenario, it’s going to trigger knowledge corruption and thus the bug ought to be simple to detect.

By way of the Ethereum bug bounty program, we acquired a report a couple of flaw throughout the new experimental ABI encoder (known as ABIEncoderV2). The brand new ABI encoder continues to be marked as experimental, however we nonetheless assume that this deserves a distinguished announcement since it’s already used on mainnet.
Credit to Ming Chuan Lin (of https://www.secondstate.io) for each discovering and fixing the bug!

The 0.5.10 launch incorporates the fixes to the bugs.
In the meanwhile, we don’t plan to publish a repair to the legacy 0.4.x collection of Solidity, however we would if there’s common demand.

Each bugs ought to be simply seen in checks that contact the related code paths.

Particulars concerning the two bugs might be discovered under.

Signed Integer Array Bug

Who ought to be involved

You probably have deployed contracts which use signed integer arrays in storage and both immediately assign

  • a literal array with not less than one detrimental worth in it (x = [-1, -2, -3];) or
  • an present array of a completely different signed integer kind

to it, this may result in knowledge corruption within the storage array.

Contracts that solely assign particular person array components (i.e. with x[2] = -1;) usually are not affected.

Learn how to examine if contract is weak

In case you use signed integer arrays in storage, attempt to run checks the place you utilize detrimental values. The impact ought to be that the precise worth saved is constructive as a substitute of detrimental.

You probably have a contract that meets these situations, and wish to confirm whether or not the contract is certainly weak, you’ll be able to attain out to us by way of safety@ethereum.org.

Technical particulars

Storage arrays might be assigned from arrays of various kind. Throughout this copy and project operation, a kind conversion is carried out on every of the weather. Along with the conversion, particularly if the signed integer kind is shorter than 256 bits, sure bits of the worth must be zeroed out in preparation for storing a number of values in the identical storage slot.

Which bits to zero out was incorrectly decided from the supply and never the goal kind. This results in too many bits being zeroed out. Specifically, the signal bit can be zero which makes the worth constructive.

ABIEncoderV2 Array Bug

Who ought to be involved

You probably have deployed contracts which use the experimental ABI encoder V2, then these may be affected. Which means solely contracts which use the next directive throughout the supply code might be affected:

pragma experimental ABIEncoderV2;

Moreover, there are a variety of necessities for the bug to set off. See technical particulars additional under for extra data.

Learn how to examine if contract is weak

The bug solely manifests itself when the entire following situations are met:

  • Storage knowledge involving arrays or structs is distributed on to an exterior operate name, to abi.encode or to occasion knowledge with out prior project to a neighborhood (reminiscence) variable AND
  • this knowledge both incorporates an array of structs or an array of statically-sized arrays (i.e. not less than two-dimensional).

Along with that, within the following scenario, your code is NOT affected:

  • when you solely return such knowledge and don’t use it in abi.encode, exterior calls or occasion knowledge.

Attainable penalties

Naturally, any bug can have wildly various penalties relying on this system management circulate, however we anticipate that that is extra prone to result in malfunction than exploitability.

The bug, when triggered, will beneath sure circumstances ship corrupt parameters on technique invocations to different contracts.

Technical particulars

Throughout the encoding course of, the experimental ABI encoder doesn’t correctly advance to the following component in an array in case the weather occupy greater than a single slot in storage.

That is solely the case for components which might be structs or statically-sized arrays. Arrays of dynamically-sized arrays or of elementary datatypes usually are not affected.

The particular impact you will note is that knowledge is “shifted” within the encoded array: You probably have an array of kind uint[2][] and it incorporates the info
[[1, 2], [3, 4], [5, 6]], then it will likely be encoded as [[1, 2], [2, 3], [3, 4]] as a result of the encoder solely advances by a single slot between components as a substitute of two.

This publish was collectively composed by @axic, @chriseth, @holiman

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments