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

extcodehash behave as a symbolic value #324

Closed
simon-something opened this issue Jul 5, 2024 · 3 comments
Closed

extcodehash behave as a symbolic value #324

simon-something opened this issue Jul 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@simon-something
Copy link

simon-something commented Jul 5, 2024

Describe the bug
While calling the extcodehash on a concrete address (either eoa or contract), a concrete hash image would be expected. Instead, the returned value behave as a symbolic one.

To Reproduce
While running this code snippet as context, in a Counter example repo:

function check_extcodehash() public {
    address firstImplementation = address(new Counter());
    address secondImplementation = address(new Counter());

    bytes32 firstHash;
    bytes32 secondHash;

    assembly {
        firstHash := extcodehash(firstImplementation)
        secondHash := extcodehash(secondImplementation)
    }

the following assertions produce these results:
assert(firstHash == secondHash); fails
assert(firstHash != secondHash); fails
assert(firstHash == secondHash || firstHash != secondHash); passes

This same example can be reproduced with 2 EOA as well.

Environment:

  • OS: macOS
  • Python version: 3.10.4
  • Halmos and other dependency versions: 0.1.13

Additional context
This is relevant as extcodehash was used by OpenZeppelin isContract(address) in the Address lib (now removed, but some older repo still rely on it for, for instance, proxy implementation migration)

@simon-something simon-something added the bug Something isn't working label Jul 5, 2024
@simon-something
Copy link
Author

Tagging @karmacoma-eth as we discussed it over telegram

@karmacoma-eth karmacoma-eth self-assigned this Jul 22, 2024
@karmacoma-eth
Copy link
Collaborator

ok this is unfortunate behavior, but it seems expected atm because extcodehash is modeled as a bare uninterpreted function.

If we log firstHash and secondHash, we get:

[console.log] f_extcodehash(0x00000000000000000000000000000000aaaa0002)
[console.log] f_extcodehash(0x00000000000000000000000000000000aaaa0003)

so as far as the solver is involved, they could be the same, and they could be different.

To fix this, we need to implement the full behavior of extcodehash

@daejunpark
Copy link
Collaborator

this should be fixed by #328. please feel free to reopen if the issue persists. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants