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

State trie clearing implementation detail #26

Closed
soc1c opened this issue Aug 7, 2019 · 2 comments
Closed

State trie clearing implementation detail #26

soc1c opened this issue Aug 7, 2019 · 2 comments

Comments

@soc1c
Copy link
Contributor

soc1c commented Aug 7, 2019

When completing the revert opcode, there were two test cases, which performed very similar logic that did not error because of REVERT at all and had mentioned being a state trie clearing test in one the filler test files (FailedCreateRevertsDeletion).

The two test files are:
FailedCreateRevertsDeletion.json
RevertPrefoundEmptyOOG.json

The scenario that both encounter is the following:
transaction calls A -> A creates X -> A hits error (OOG or intentional invalid opcode)

and my assumption is that either the empty contract that is created, X, isn't deleted OR the transaction state isn't reverted to the proper state at the start of the transaction.

edit: almost certain it is state trie clearing since the pre-byzantium tests pass on ETC

So either it is a missed edge case of state trie clearing, or an invalid existing implementation of state rollback within the existing ETC code.

I will look into this later, but documenting for now.

Here is the evm logs for both transactions (from ETH because they are cleaner than manually printing variables on ETC and the values are the same as the only difference is the accounts in post):

 --- PASS: TestState/RevertPrefoundEmptyOOG.json/Byzantium/0 (0.00s)
            state_test.go:107: EVM operation log:
                {"pc":0,"op":96,"gas":"0x11940","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":2,"op":96,"gas":"0x1193d","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x20"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":4,"op":96,"gas":"0x1193a","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x20","0x0"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":6,"op":240,"gas":"0x11937","gasCost":"0x7d03","memory":"0x","memSize":32,"stack":["0x20","0x0","0x0"],"depth":1,"refund":0,"opName":"CREATE","error":""}
                {"pc":0,"op":0,"gas":"0x99c4","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":2,"refund":0,"opName":"STOP","error":""}
                {"pc":7,"op":96,"gas":"0x9c34","gasCost":"0x7d03","memory":"0x","memSize":32,"stack":["0x7db299e0885c85039f56fa504a13dd8ce8a56aa7"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":9,"op":85,"gas":"0x9c31","gasCost":"0x4e20","memory":"0x","memSize":32,"stack":["0x7db299e0885c85039f56fa504a13dd8ce8a56aa7","0x0"],"depth":1,"refund":0,"opName":"SSTORE","error":""}
                {"pc":10,"op":96,"gas":"0x4e11","gasCost":"0x4e20","memory":"0x","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":12,"op":96,"gas":"0x4e0e","gasCost":"0x4e20","memory":"0x","memSize":32,"stack":["0xc"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":14,"op":85,"gas":"0x4e0b","gasCost":"0x4e20","memory":"0x","memSize":32,"stack":["0xc","0x1"],"depth":1,"refund":0,"opName":"SSTORE","error":"out of gas"}
                {"output":"","gasUsed":"0x11940","time":1485275,"error":"out of gas"}

FailedCreateRevertsDeletion.json has a slightly different flow:
transaction calls A -> A creates X -> X reverts back to A -> A hits invalid opcode and errors out

--- FAIL: TestState/FailedCreateRevertsDeletion.json/Byzantium/0 (0.00s)
            state_test.go:90: post state root mismatch: got 15755176ef2d7beb091958c3328a07aa87ff5a911e8388c422f24b96dd34e1d7, want 4198bc14346b78f666445049893f68de17d21f892a1e2c2848b576ff0d80cb4a
            state_test.go:107: EVM operation log:
                {"pc":0,"op":48,"gas":"0xe2a40","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"ADDRESS","error":""}
                {"pc":1,"op":80,"gas":"0xe2a3e","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"],"depth":1,"refund":0,"opName":"POP","error":""}
                {"pc":2,"op":96,"gas":"0xe2a3c","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":4,"op":128,"gas":"0xe2a39","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0xc"],"depth":1,"refund":0,"opName":"DUP1","error":""}
                {"pc":5,"op":96,"gas":"0xe2a36","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0xc","0xc"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":7,"op":96,"gas":"0xe2a33","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0xc","0xc","0x12"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":9,"op":57,"gas":"0xe2a30","gasCost":"0x9","memory":"0x","memSize":32,"stack":["0xc","0xc","0x12","0x0"],"depth":1,"refund":0,"opName":"CODECOPY","error":""}
                {"pc":10,"op":96,"gas":"0xe2a27","gasCost":"0x9","memory":"0x","memSize":32,"stack":["0xc"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":12,"op":96,"gas":"0xe2a24","gasCost":"0x9","memory":"0x","memSize":32,"stack":["0xc","0x0"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
                {"pc":14,"op":240,"gas":"0xe2a21","gasCost":"0x7d00","memory":"0x","memSize":32,"stack":["0xc","0x0","0x0"],"depth":1,"refund":0,"opName":"CREATE","error":""}
                {"pc":0,"op":98,"gas":"0xd766d","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":2,"refund":0,"opName":"PUSH3","error":""}
                {"pc":4,"op":96,"gas":"0xd766a","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x112233"],"depth":2,"refund":0,"opName":"PUSH1","error":""}
                {"pc":6,"op":82,"gas":"0xd7667","gasCost":"0x6","memory":"0x","memSize":32,"stack":["0x112233","0x0"],"depth":2,"refund":0,"opName":"MSTORE","error":""}
                {"pc":7,"op":96,"gas":"0xd7661","gasCost":"0x6","memory":"0x","memSize":32,"stack":[],"depth":2,"refund":0,"opName":"PUSH1","error":""}
                {"pc":9,"op":96,"gas":"0xd765e","gasCost":"0x6","memory":"0x","memSize":32,"stack":["0x20"],"depth":2,"refund":0,"opName":"PUSH1","error":""}
                {"pc":11,"op":253,"gas":"0xd765b","gasCost":"0x0","memory":"0x","memSize":32,"stack":["0x20","0x0"],"depth":2,"refund":0,"opName":"REVERT","error":""}
                {"pc":15,"op":80,"gas":"0xdad0f","gasCost":"0x7d00","memory":"0x","memSize":32,"stack":["0x0"],"depth":1,"refund":0,"opName":"POP","error":""}
                {"pc":16,"op":254,"gas":"0xdad0d","gasCost":"0x7d00","memory":"0x","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"Missing opcode 0xfe","error":"invalid opcode 0xfe"}
                {"output":"","gasUsed":"0xe2a40","time":250217,"error":"invalid opcode 0xfe"}

Just posting here for resolution: both these test failures are most likely caused by an issue in how ETC handles dirty objects in the state. Geth was able to pass the failing tests after their overhaul of the statedb and journaling.

@soc1c
Copy link
Contributor Author

soc1c commented Aug 7, 2019

Imported from eth-classic/go-ethereum#35

@austinabell
Copy link
Contributor

Implemented already by #14

@soc1c soc1c added this to the 6.0 Atlantis milestone Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants