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

Execution ordering in tuples and assignments is off #52

Open
plotchy opened this issue May 18, 2023 · 0 comments
Open

Execution ordering in tuples and assignments is off #52

plotchy opened this issue May 18, 2023 · 0 comments

Comments

@plotchy
Copy link
Collaborator

plotchy commented May 18, 2023

pragma solidity >=0.8.0;
contract struct_push {

    mapping(uint => uint) map;
    uint public index;
    uint public a;

    function foo() public payable returns (uint, uint, uint, uint, uint) {
        require(index == 0);
        (a, map[++index]) = (index, bar(++index));
        
        return (a, index, map[0], map[1], map[2]);
    }

    function bar(uint i) internal pure returns (uint) {
        return i;
    }
}

Foundry output of foo():

Running 1 test for test/any.t.sol:CounterTest
[PASS] testPush() (gas: 54875)
Traces:
  [172906] CounterTest::setUp() 
    ├─ [118365] → new struct_push@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   └─ ← 591 bytes of code
    └─ ← ()

  [54875] CounterTest::testPush() 
    ├─ [49591] struct_push::foo() 
    │   └─ ← 0, 2, 0, 0, 1
    └─ ← ()

Test result: ok. 1 passed; 0 failed; finished in 248.38µs

Pyrometer output of foo():
image

a == 1, though is expected to be 0.
map[2] == [0, 2^256-1] and is expected to be 1. Though all the mapping slots are pessimistic so this seems currently unsupported.

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

No branches or pull requests

1 participant