nevillegrech / gigahorse-toolchain

A binary lifter and analysis framework for Ethereum smart contracts
Other
290 stars 59 forks source link

Need some constant folding in `GlobalAnalysis` #124

Closed sifislag closed 3 months ago

sifislag commented 7 months ago

We currently only perform constant folding at local.dl:

https://github.com/nevillegrech/gigahorse-toolchain/blob/2c3994b1390aba93ee87922d35bb1acce618ba42/logic/local.dl#L118C1-L135C56

There are cases in which this isn't enough. Relevant snippet:

    Begin block 0x4aaa0xb67
    prev=[0x39db0xb67], succ=[0x4eb10xb67]
    =================================
    0x4aab0xb67: vb674aab(0x4abe) = CONST 
    0x4ab10xb67: vb674ab1(0x4e60) = CONST 
    0x4ab40xb67: vb674ab4(0x555f) = CONST 
    0x4ab70xb67: vb674ab7(0x5586) = CONST 
    0x4aba0xb67: vb674aba(0x4eb1) = CONST 
    0x4abd0xb67: JUMP vb674aba(0x4eb1)

    Begin block 0x4eb10xb67
    prev=[0x4aaa0xb67], succ=[]
    =================================
    0x4eb20xb67: vb674eb2(0x4ebf) = CONST 
    0x4eb80xb67: vb674eb8(0xffffffff) = CONST 
    0x4ebd0xb67: vb674ebd = AND vb674eb8(0xffffffff), vb674ab1(0x4e60)
    0x4ebe0xb67: JUMP vb674ebd

Will tackle soon, will have some difficulty.

iliastsa commented 6 months ago

Would merging basic blocks when there are "chains" (A has B as the only successor block, B has A as the only predecessor block) help?

sifislag commented 6 months ago

Not really, it would be a shallow fix. I tried that at some point last year and it didn't give much benefit so I paused it. I think the fix for the current issue will not be too much work, but I need to test it thoroughly.

sifislag commented 3 months ago

Closed by https://github.com/nevillegrech/gigahorse-toolchain/pull/136