Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

State trie clearing implementation detail #35

Closed
austinabell opened this issue May 22, 2019 · 3 comments
Closed

State trie clearing implementation detail #35

austinabell opened this issue May 22, 2019 · 3 comments

Comments

@austinabell
Copy link
Contributor

austinabell commented May 22, 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"}
@steviezhang
Copy link
Contributor

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

soc1c commented May 31, 2019

Adding it to the agenda, are you able to talk about that?

etclabscore/ECIPs#25

@soc1c
Copy link
Contributor

soc1c commented Aug 7, 2019

Moved to etclabscore/go-ethereum#26

@soc1c soc1c closed this as completed Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants