Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

aleth-vm generates abnormal gas used #5759

Closed
ToolmanInside opened this issue Sep 24, 2019 · 5 comments
Closed

aleth-vm generates abnormal gas used #5759

ToolmanInside opened this issue Sep 24, 2019 · 5 comments

Comments

@ToolmanInside
Copy link

When I use aleth-vm --code my_bytecode, it returns:
Gas used: 9223372036854775807 (+21000 for transaction, -0 refunded) Output: 0 logs. 11 operations in 0.000259 seconds. Maximum memory usage: 0 bytes Expensive operations: MSTORE x 1 (3 gas)
This is a abnormal number. It is impossible to have such a large gas used.
same with #5351

@halfalicious
Copy link
Contributor

Can you please share the bytecode that you're executing? Is it just a single MSTORE?

@gumb0
Copy link
Member

gumb0 commented Oct 1, 2019

I guess it throws an exception (e.g. invalid opcode) and this consumes all provided gas. By default gas given to execution is mainnet's max block gas limit, which is 0x7fffffffffffffff = 9223372036854775807

@gumb0
Copy link
Member

gumb0 commented Oct 2, 2019

We should display the error in the summarical info json string described in #4613

For example geth's evm tool outputs this in case of invalid opcode error:

{"pc":0,"op":96,"gas":"0x54620","gasCost":"0x0","memory":"0x","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":2,"op":96,"gas":"0x5461d","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":4,"op":96,"gas":"0x5461a","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":6,"op":96,"gas":"0x54617","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":8,"op":96,"gas":"0x54614","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":10,"op":96,"gas":"0x54611","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":12,"op":96,"gas":"0x5460e","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1","0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":14,"op":96,"gas":"0x5460b","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1","0x1","0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"PUSH1","error":""}
{"pc":16,"op":231,"gas":"0x54608","gasCost":"0x0","memory":"0x","memSize":0,"stack":["0x1","0x1","0x1","0x1","0x1","0x1","0x1","0x1"],"depth":1,"refund":0,"opName":"Missing opcode 0xe7","error":"invalid opcode 0xe7"}
{"output":"","gasUsed":"0x54620","time":77395,"error":"invalid opcode 0xe7"}

@ToolmanInside
Copy link
Author

@halfalicious my bytecode:

73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a723058204f070c071677014c02a45026e463614df8ac6e715549513384baa466cb53ad970029

The running result it returned:

Gas used: 9223372036854775807 (+21000 for transaction, -0 refunded)
Output: 
0 logs.
8 operations in 0.000163 seconds.
Maximum memory usage: 0 bytes
Expensive operations:
MSTORE x 1 (3 gas)

@gumb0 you are right. Bad things happened because there's invalid opcode. But this is not a particular case, it happened in all of my bytecode (compiled from around 3000 contract files).

@gumb0
Copy link
Member

gumb0 commented Nov 1, 2019

@ToolmanInside Could you then please post the example of the valid code, for which this happens?

@gumb0 gumb0 closed this as completed Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants