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

EIP-150 tests with wrong stateRoot? #714

Closed
jochem-brouwer opened this issue Jul 13, 2020 · 2 comments
Closed

EIP-150 tests with wrong stateRoot? #714

jochem-brouwer opened this issue Jul 13, 2020 · 2 comments

Comments

@jochem-brouwer
Copy link
Member

jochem-brouwer commented Jul 13, 2020

Hey there - we are implementing Tangerine Whistle (EIP-150) and I cannot get this specific test to work. I do not understand why.

I'm assuming here that the hash field should be the expected stateRoot .

In the test, note that the transaction has a gasPrice of 0 -> hence gas pricing will not change the stateRoot whatsoever, so we do not care about this pricing.

Here's my reasoning:

The test has a contract (0x095e7baea6a6c7c4c2dfeb977efac326af552d87) which calls itself. The first call selfdestructs to 0x02 and then it selfdestructs to 0x01.

The touched accounts are thus 0x01 and 0x02. In EIP-158 (Spurious Dragon) will remove account 0x01 from the trie, since it is DEAD (it does exist in the trie, but has zero balance, zero code and zero nonce). However, in Tangerine Whistle, it will stay. This should be the sole difference between Tangerine Whistle and Spurious Dragon.

Why then does Frontier/Homestead have a different state root? Well, this is because the CALL itself goes Out-Of-Gas in this hard fork. If you inspect the deployed code at the contract, you see that GAS gets forwarded to the CALL. Pre-TF this semantic was GAS - 20, since CALL used 20 gas. TF changed this; if you forward more than the available gas, instead of going OOG, you forward all the remaining gas. Hence, in Frontier/Homestead, the entire transaction goes OOG and thus no selfdestruct happened.

I want to note that in my tests, the EIP-158 test passes, but the EIP-150 tests does not pass. I think either the test is wrong somehow or my analysis is wrong and I'd love to get some help here.

For completeness, this is the EIP-150 state dump I'd expect:

0000000000000000000000000000000000000001 exists in trie? true
nonce
balance
stateRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
codeHash c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
0000000000000000000000000000000000000002 exists in trie? true
nonce
balance 0de0b6b3a76586a0
stateRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
codeHash c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
a94f5374fce5edbc8e2a8697c15331677e6ebf0b exists in trie? true
nonce 01
balance 0de0b6b3a7627960
stateRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
codeHash c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
095e7baea6a6c7c4c2dfeb977efac326af552d87 exists in trie? true
nonce
balance
stateRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
codeHash c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

Here non-defined values are empty buffers, i.e. they are 0.

This is the state root I'm getting: cf78ad0da35b6779d038ce6cd5d32e8eac81090b1f6a1d4430d6047dc2ce7e5c, while c5ac5551ef0c7f49c4a25c02c117046045adf7ba7cc672f91d5a1d2ea3a5837d is expected.

Linked issue: Issue 431.

As a final note, I find it weird that in these LegacyTests the gasPrice is set to 0; you'd like to reflect the gas cost changes of these forks in the stateRoot I'd imagine.

@jochem-brouwer
Copy link
Member Author

The issue is resolved; the problem was that our VM did not put an empty coinbase account in the Trie. After Tangerine Whistle, this is not a problem, as it would be cleaned up when removing empty "touched" accounts. An empty coinbase account in this case should exist, because the test suite expects that the miner account gets touched and all gas fee get put into this account - in this case, these fees are 0, and thus by Spurious Dragon this account is removed.

@holgerd77
Copy link
Contributor

Will just state the name of the test here in case someone with similar problems does a repo-wide search:
doubleSelfdestructTest

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

2 participants