nevillegrech / gigahorse-toolchain

A binary lifter and analysis framework for Ethereum smart contracts
Other
302 stars 63 forks source link

Fix the transformation for conditional throw jumps (old THROWI statements) #19

Closed sifislag closed 3 years ago

sifislag commented 3 years ago

Overview

The old transformation for conditional throw jumps (conditional jumps with the target pointing to an invalid statement) was broken and this resulted in dead code. This PR introduces a fix me and @iliastsa wrote for it.

Issue/fix explanation

The issue of the old code was that because the target of the JUMPI statement was an invalid statement causing the halting of the program's execution, the valid continuation of the control flow was the fallthrough of the JUMPI statement. However the new statements were inserted after the same JUMPI statement, effectively overriding the old fallthrough, resulting in unreachable code.

The fix is more complex than the code it replaces because it needs to insert two generated blocks relative to that JUMPI statement.

Effect

We checked the effect of this fix in 3 datasets:

It seems that this is a pattern no longer produced by the solidity compiler but it can cause a pretty significant increase in coverage for old contracts.