Skip to content
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
Closed

Storage corruption when addition on storage element overflows #1306

catageek opened this issue Oct 30, 2016 · 5 comments
Assignees
Labels

Comments

@catageek
Copy link

@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
Copy link
Contributor

@ethernomad ethernomad commented Oct 31, 2016

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

@chriseth
Copy link
Contributor

@chriseth 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
Copy link

@ghost ghost commented Nov 3, 2016

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

@axic
Copy link
Member

@axic 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
Copy link

@VIP21 VIP21 commented Nov 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
@axic @ethernomad @catageek @chriseth @VIP21 and others