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

Account Existence check #1798

Closed
wolflo opened this issue Aug 22, 2020 · 0 comments · Fixed by #1801
Closed

Account Existence check #1798

wolflo opened this issue Aug 22, 2020 · 0 comments · Fixed by #1801
Labels
Projects

Comments

@wolflo
Copy link
Contributor

wolflo commented Aug 22, 2020

Summary of the problem

Account existence is inconsistent with EIP-161. Accounts can remain existent-but-empty, which should not be the case.

Manticore version

0.3.4

Python version

3.8.5

Step to reproduce the behavior

The following test shows the issue as it relates to calculation of the gas cost for a self-destruct instruction. Account 0xffffffffffffffffffffffffffffffffffffffff is touched in the first transaction, but should remain non-existent because it has no code, zero balance, and zero nonce. The self-destruct in the second transaction should charge 21000 + 3 + 5000 + 25000 - 24000, but instead charges 21000 + 3 + 5000 - min(gas_used / 2, 24000) = 13002 because the recipient account is considered as already existing.

def test_acct_existence(self):
    with disposable_mevm() as m:
        asm_acc = """   PUSH20 0xffffffffffffffffffffffffffffffffffffffff
                        SELFDESTRUCT
                  """

        # 21000 base tx + 3 push op + 5000 base selfdestruct + 25000 new acct cost - 24000 refund
        expected_gas = 27003

        m.create_account(
            address=0x111111111111111111111111111111111111111,
            code=EVMAsm.assemble(asm_acc),
            balance=1
        )
        m.create_account(
            address=0x222222222222222222222222222222222222222,
            balance=1000000000000000000
        )

        # this should not result in creation of the acct, but does
        m.transaction(
            caller=0x222222222222222222222222222222222222222,
            address=0xffffffffffffffffffffffffffffffffffffffff,
            data=b'',
            value=0
        )
        # this should result in creation of the acct, but it's already created
        m.transaction(
            caller=0x222222222222222222222222222222222222222,
            address=0x111111111111111111111111111111111111111,
            data=b'',
            value=0
        )
        self.assertEqual(m.count_ready_states(), 1)
        state = next(m.ready_states)
        txs = state.platform.transactions

        # AssertionError: 13002 != 27003
        self.assertEqual(txs[-1].used_gas, expected_gas)

Expected behavior

An account that is touched but remains empty should be considered non-existent.

Actual behavior

Touched accounts are considered existing regardless of code, nonce, and balance.

@wolflo wolflo added the bug label Aug 22, 2020
@ehennenfent ehennenfent added this to To do in Manticore Aug 25, 2020
Manticore automation moved this from To do to Done Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Manticore
  
Done
Development

Successfully merging a pull request may close this issue.

1 participant