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

extcodesize returns wrong value on contracts being constructed #453

Closed
elopez opened this issue Apr 30, 2020 · 4 comments
Closed

extcodesize returns wrong value on contracts being constructed #453

elopez opened this issue Apr 30, 2020 · 4 comments

Comments

@elopez
Copy link
Member

elopez commented Apr 30, 2020

extcodesize on a contract being constructed should return 0, but on echidna it returns non-0. Here's a testcase:

pragma solidity ^0.5.0;

contract C {

  uint sz;

  constructor() public {
    uint x;
    address t = address(this);
    assembly { x := extcodesize(t) }
    sz = x;
  }

  function echidna_test_zero() public returns (bool) {
    return sz == 0;
  }
}
@incertia
Copy link
Contributor

i believe this is more of an hevm regression than an echidna issue

in particular, we have to run constructors as a RuntimeCode "bytecode here" rather than an InitCode "bytecode here" and hevm likely implements extcodesize for RuntimeCode as a non-constructor.

@incertia
Copy link
Contributor

jk

i think we can get around this by manually setting state . code. in particular,

vm & env . contracts . at addr ?= initialContract (InitCode bc)
loadContract addr
vm & state . code .= bc

@incertia
Copy link
Contributor

check out the PR, i am almost certain it is the right thing to do

extcodesize

@ggrieco-tob
Copy link
Member

Fixed in #454 and #465

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

3 participants