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

Optimizer causes code that overwrites contract fields, with an if(false) nearby #1416

Closed
pdobacz opened this Issue Nov 22, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@pdobacz

pdobacz commented Nov 22, 2016

Which version of Solidity you are using

solc is 0.4.5+commit.b318366e.Linux.g++

What was the source code (if applicable)

pragma solidity ^0.4.5;

contract Test {
    uint256 public totalSupply;
    function Test() {
        totalSupply = 1000;
    }
    function f() {
        if (false) // comment the if out to fix
            var other_name = totalSupply;
        totalSupply -= 456;
    }
}

Which platform are you running on

populus (TestRPC), online solidity compiler as well

How to reproduce the issue

compile with optimization, deploy Test, call f, totalSupply is 2^256 - 456 afterwards

populus:

def test_test(chain):
    contract_factory = chain.get_contract_factory("Test")
    deploy_txn_hash = contract_factory.deploy()
    deploy_address = chain.wait.for_contract_address(deploy_txn_hash)
    asset = contract_factory(address=deploy_address)

    assert asset.call().totalSupply() == 1000
    txn_hash = asset.transact().f()
    chain.wait.for_receipt(txn_hash)
    assert asset.call().totalSupply() == 544

What was the result of the issue

with the if(false) condition in the contract, the totalSupply variable gets overwritten with 0 somewhere.

What the expected behaviour is

totalSupply == 544

@ethernomad

This comment has been minimized.

Show comment
Hide comment
@ethernomad

ethernomad Nov 23, 2016

Contributor

When was this bug introduced?

Contributor

ethernomad commented Nov 23, 2016

When was this bug introduced?

@pirapira

This comment has been minimized.

Show comment
Hide comment
@pirapira

pirapira Nov 23, 2016

Member

I'm doing git bisect now. I already know it's quite recent.

Member

pirapira commented Nov 23, 2016

I'm doing git bisect now. I already know it's quite recent.

@pirapira

This comment has been minimized.

Show comment
Hide comment
@pirapira

pirapira Nov 23, 2016

Member

From 0.4.5, at e543bd3

Member

pirapira commented Nov 23, 2016

From 0.4.5, at e543bd3

@ethernomad

This comment has been minimized.

Show comment
Hide comment
@ethernomad

ethernomad Nov 23, 2016

Contributor

Great!

#1424

Contributor

ethernomad commented Nov 23, 2016

Great!

#1424

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