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

[Testing] Integrate testing with evm in go-ethereum #27

Closed
lialan opened this issue Nov 15, 2019 · 6 comments
Closed

[Testing] Integrate testing with evm in go-ethereum #27

lialan opened this issue Nov 15, 2019 · 6 comments
Labels

Comments

@lialan
Copy link

lialan commented Nov 15, 2019

go-ethereum provides a decent interface for executing EVM code. We could use it for our use of testing.
We will start with non-blockchain interacting correctness checking. In such cases, we compile a single function and feed it into evm and execute.
The compiled function takes a certain amount of arguments as input, plus the return address at the bottom of the stack. When function finishes executing, the last instruction will jump to the return address.
So to test the result and make sure the function returns correctly, we should push a return address onto stack before anything else. But that would alter the relocation offset.
One way to do this is to add an option to specify an offset to the relocation offset. Let’s say when we are fixing up a jump destination, and we have determined location at 0xabcd, and if we have specified -debug-offset-offset=2, then the 0xabcd will become 0xabcd + 2 = 0xabcf. By doing this we can acknowledge the prefix offsets added to test cases.

@lialan

This comment has been minimized.

@lialan
Copy link
Author

lialan commented Nov 15, 2019

This is the dispatcher for 1 argument, 1 return value function:

[1] PUSH1 0x08
[3] PUSH1 0x0A
[5] PUSH1 0xFF # this is the input value we wish to specify
[8] PUSH2 0x0013
[9] JUMP
[10] JUMPDEST
[12] PUSH1 0x00
[13] MSTORE
[15] PUSH1 0x20
[17] PUSH1 0x00
[18] RETURN
[19] JUMPDEST # Start of function body, in this case do nothing
[20] SWAP1
[21] JUMP

Binary:

6008600A60FF610013565b60005260206000f35b9056

@lialan
Copy link
Author

lialan commented Nov 15, 2019

Here is the example we perform 2 arguments 1 output function dispatching:

[1] PUSH1 0x0a
[3] PUSH1 0x0c
[5] PUSH1 0x11
[7] PUSH1 0x22
[10] PUSH2 0x0015
[11] JUMP
[12] JUMPDEST
[14] PUSH1 0x00
[15] MSTORE
[17] PUSH1 0x20
[19] PUSH1 0x00
[20] RETURN
[21] JUMPDEST
[22] ADD
[23] SWAP1
[24] JUMP

Binary:

600a600c60116022610015565b60005260206000f35b019056

@lialan
Copy link
Author

lialan commented Nov 16, 2019

Spent a bit of time refining a third party assembler: crytic/pyevmasm#36

We will use this little tool to inject a simple function dispatcher in our tests.

lialan added a commit that referenced this issue Nov 16, 2019
@lialan
Copy link
Author

lialan commented Nov 16, 2019

Another way to do this completely in Python is to use py-evm. Investigating the possibilities.

lialan added a commit that referenced this issue Nov 17, 2019
lialan added a commit that referenced this issue Nov 17, 2019
lialan added a commit that referenced this issue Nov 17, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
lialan added a commit that referenced this issue Nov 18, 2019
@lialan
Copy link
Author

lialan commented Nov 19, 2019

Closing this function now since we now have a testing utility framework built. We will continue to improve the framework.

@lialan lialan closed this as completed Nov 19, 2019
lialan added a commit that referenced this issue Nov 20, 2019
lialan added a commit that referenced this issue Nov 20, 2019
lialan added a commit that referenced this issue Nov 21, 2019
lialan added a commit that referenced this issue Nov 22, 2019
lialan added a commit that referenced this issue Nov 23, 2019
lialan added a commit that referenced this issue Nov 23, 2019
lialan added a commit that referenced this issue Nov 23, 2019
lialan added a commit that referenced this issue Nov 24, 2019
lialan added a commit that referenced this issue Nov 25, 2019
lialan added a commit that referenced this issue Nov 25, 2019
lialan added a commit that referenced this issue Nov 28, 2019
lialan added a commit that referenced this issue Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant