capstone icon indicating copy to clipboard operation
capstone copied to clipboard

Incomplete EVM Support

Open f0rki opened this issue 4 years ago • 1 comments

I'd like to point out several issues with supporting the EVM architecture. Currently, EVM support is kind of incomplete; couple of things I noticed:

  • Missing/wrong instructions:
    • byte 0xf5 / 245 should be disassembled as CREATE2
    • Newer instructions like SHR, SHL, SAR, SELFBALANCE and more seem to be missing.
  • Correctly disassembling EVM is kind of tricky since there are multiple versions ("hard forks" in Ethereum lingo) of the EVM instruction set. For example, at block 1 the byte 0xf5 would be disassembled as INVALID, while at block 1400000 it must be disassembled as CREATE2. The EVM version can also change the base gas cost associated with instructions (e.g., EXTCODESIZE). Different Ethereum-based block chains also use different EVM versions. Now the question is how to deal with this issue in capstone.
    • pyevmasm has a mechanism to select the right version according to block number or by hard fork name. I am not sure whether this is something that can be supported via the capstone API. Maybe as a mode flag that can be passed to cs_open?
    • Fortunately, the EVM does not remove instructions. So one could just disassemble instructions according to the latest EVM spec and add the EVM version to the details struct leaving the user to deal with the EVM version issue if needed. However, this wouldn't allow for correctly computing gas costs.
  • Bugs:
    • Cannot get large push constants (see my PR #1231)

f0rki avatar Feb 01 '22 09:02 f0rki

yeah I know that, we are planning to renew EVM during capstone 5.0-rc stage

kabeor avatar Feb 15 '22 06:02 kabeor