New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage corruption when addition on storage element overflows #1306

Closed
catageek opened this Issue Oct 30, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@catageek

catageek commented Oct 30, 2016

The following code returns 1 instead of 0 because the addition overflows. The assembly code shows that the AND mask is applied before the addition and not after, resulting in the corruption of b.

contract Test {
    uint32 a = 0xFFFFFFFF;
    uint32 b;

    function run() returns (uint32) {
        var x = 1;
        a = uint32(a + x);
        return b;
    }
}

I suppose that writing in a should not corrupt b in any case.

Solidity version: 0.4.3+commit.2353da71.Emscripten.clang

@ethernomad

This comment has been minimized.

Contributor

ethernomad commented Oct 31, 2016

Confirmed. I can reproduce this bug with and without optimization all the way back to 0.1.6.

@chriseth

This comment has been minimized.

Contributor

chriseth commented Oct 31, 2016

Simpler example:

contract Test {
    uint32 a;
    uint32 b;

    function run() returns (uint32) {
        a--;
        return b;
    }
}

@chriseth chriseth self-assigned this Oct 31, 2016

@chriseth chriseth added in progress and removed nextrelease labels Oct 31, 2016

@chriseth chriseth removed the in progress label Oct 31, 2016

paulperegud added a commit to golemfactory/golem-crowdfunding that referenced this issue Nov 2, 2016

@ghost

This comment has been minimized.

ghost commented Nov 3, 2016

Has this issue been fixed if we do pragma solidity ^0.4.4?

@axic

This comment has been minimized.

Member

axic commented Nov 5, 2016

@Physes yes, it is fixed in the 0.4.4 version and the pragma will ensure it cannot be compiled with earlier versions.

@VIP21

This comment has been minimized.

VIP21 commented Nov 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment