diff --git a/examples/cfgs/complex3.cfg b/examples/cfgs/complex3.cfg new file mode 100644 index 00000000..bfbb99ce --- /dev/null +++ b/examples/cfgs/complex3.cfg @@ -0,0 +1,1250 @@ + +{ + "object": { + "blocks": [ + { + "exit": "Block0Exit", + "id": "Block0", + "instructions": [ + { + "in": [ + "0x01", + "0x01" + ], + "op": "sstore", + "out": [] + }, + { + "in": [], + "op": "f_108", + "out": [ + "_5" + ] + }, + { + "in": [ + "0x00" + ], + "op": "sload", + "out": [ + "_218" + ] + }, + { + "in": [ + "_218", + "0x05" + ], + "op": "add", + "out": [ + "z" + ] + }, + { + "in": [ + "0x04" + ], + "op": "sload", + "out": [ + "_221" + ] + }, + { + "in": [ + "_221", + "z" + ], + "op": "f", + "out": [ + "w" + ] + }, + { + "in": [ + "w", + "z" + ], + "op": "sstore", + "out": [] + }, + { + "in": [ + "0x05" + ], + "op": "sload", + "out": [ + "_223" + ] + }, + { + "in": [ + "_223", + "w" + ], + "op": "f", + "out": [ + "_224" + ] + }, + { + "in": [ + "_224", + "0x01" + ], + "op": "sstore", + "out": [] + }, + { + "in": [ + "z", + "z" + ], + "op": "mul", + "out": [ + "_226" + ] + }, + { + "in": [ + "_226", + "z" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block0" + ], + "id": "Block0Exit", + "instructions": [], + "type": "MainExit" + } + ], + "functions": { + "f": { + "arguments": [ + "a_1", + "b" + ], + "blocks": [ + { + "exit": "Block20Exit", + "id": "Block20", + "instructions": [ + { + "assignment": [ + "x" + ], + "in": [ + "0x2a" + ], + "out": [ + "x" + ] + } + ], + "type": "Assignment" + }, + { + "exit": [ + "Block21" + ], + "id": "Block20Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block21Exit", + "id": "Block21", + "instructions": [ + { + "in": [ + "a_1", + "x" + ], + "op": "lt", + "out": [ + "_261" + ] + }, + { + "in": [ + "_261" + ], + "op": "iszero", + "out": [ + "_262" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_262" + ], + "exit": [ + "Block22", + "Block23" + ], + "id": "Block21Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block22Exit", + "id": "Block22", + "instructions": [ + { + "in": [ + "x" + ], + "op": "mload", + "out": [ + "_263" + ] + }, + { + "in": [ + "_263", + "0x00" + ], + "op": "eq", + "out": [ + "GHOST[4]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[4]" + ], + "exit": [ + "Block24", + "Block25" + ], + "id": "Block22Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block23Exit", + "id": "Block23", + "instructions": [] + }, + { + "exit": [ + "Block26" + ], + "id": "Block23Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block24Exit", + "id": "Block24", + "instructions": [ + { + "in": [ + "_263", + "0x01" + ], + "op": "eq", + "out": [ + "GHOST[5]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[5]" + ], + "exit": [ + "Block27", + "Block28" + ], + "id": "Block24Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block25Exit", + "id": "Block25", + "instructions": [ + { + "in": [ + "0x0202", + "0x02" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block26" + ], + "id": "Block25Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block26Exit", + "id": "Block26", + "instructions": [ + { + "in": [ + "0x0c0c", + "0x0c" + ], + "op": "sstore", + "out": [] + }, + { + "assignment": [ + "c_2" + ], + "in": [ + "0x1b" + ], + "out": [ + "c_2" + ] + } + ], + "type": "Assignment" + }, + { + "exit": [ + "Block26" + ], + "id": "Block26Exit", + "instructions": [ + "f" + ], + "type": "FunctionReturn" + }, + { + "exit": "Block27Exit", + "id": "Block27", + "instructions": [ + { + "in": [ + "_263", + "0x02" + ], + "op": "eq", + "out": [ + "GHOST[6]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[6]" + ], + "exit": [ + "Block29", + "Block30" + ], + "id": "Block27Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block28Exit", + "id": "Block28", + "instructions": [ + { + "in": [ + "0x0404", + "0x04" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block28" + ], + "id": "Block28Exit", + "instructions": [ + "f" + ], + "type": "FunctionReturn" + }, + { + "exit": "Block29Exit", + "id": "Block29", + "instructions": [ + { + "in": [ + "_263", + "0x03" + ], + "op": "eq", + "out": [ + "GHOST[7]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[7]" + ], + "exit": [ + "Block31", + "Block32" + ], + "id": "Block29Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block30Exit", + "id": "Block30", + "instructions": [ + { + "in": [ + "0x00", + "0x00" + ], + "op": "revert", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block30" + ], + "id": "Block30Exit", + "instructions": [], + "type": "Terminated" + }, + { + "exit": "Block31Exit", + "id": "Block31", + "instructions": [ + { + "in": [ + "b" + ], + "op": "mload", + "out": [ + "_272" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_272" + ], + "exit": [ + "Block33", + "Block34" + ], + "id": "Block31Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block32Exit", + "id": "Block32", + "instructions": [ + { + "in": [ + "0x0808", + "0x08" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block35" + ], + "id": "Block32Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block33Exit", + "id": "Block33", + "instructions": [ + { + "in": [ + "0x0a0a", + "0x0a" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block35" + ], + "id": "Block33Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block34Exit", + "id": "Block34", + "instructions": [ + { + "in": [ + "0x00", + "0x00" + ], + "op": "return", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block34" + ], + "id": "Block34Exit", + "instructions": [], + "type": "Terminated" + }, + { + "exit": "Block35Exit", + "id": "Block35", + "instructions": [ + { + "in": [ + "0x0b0b", + "0x0b" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block36" + ], + "id": "Block35Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block36Exit", + "id": "Block36", + "instructions": [ + { + "in": [ + "0x01", + "x" + ], + "op": "add", + "out": [ + "x" + ] + }, + { + "in": [ + "x" + ], + "op": "calldataload", + "out": [ + "_256" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_256" + ], + "exit": [ + "Block37", + "Block38" + ], + "id": "Block36Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block37Exit", + "id": "Block37", + "instructions": [ + { + "in": [ + "0xffff", + "0xff" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block21" + ], + "id": "Block37Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block38Exit", + "id": "Block38", + "instructions": [ + { + "in": [ + "x" + ], + "op": "g", + "out": [ + "_257" + ] + }, + { + "in": [ + "_257", + "0x00" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block38" + ], + "id": "Block38Exit", + "instructions": [ + "f" + ], + "type": "FunctionReturn" + } + ], + "entry": "Block20", + "returns": [ + "c_2" + ], + "type": "Function" + }, + "f_108": { + "arguments": [], + "blocks": [ + { + "exit": "Block1Exit", + "id": "Block1", + "instructions": [ + { + "assignment": [ + "x_121" + ], + "in": [ + "0x2a" + ], + "out": [ + "x_121" + ] + } + ], + "type": "Assignment" + }, + { + "exit": [ + "Block2" + ], + "id": "Block1Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block2Exit", + "id": "Block2", + "instructions": [ + { + "in": [ + "0x01", + "x_121" + ], + "op": "lt", + "out": [ + "_234" + ] + }, + { + "in": [ + "_234" + ], + "op": "iszero", + "out": [ + "_235" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_235" + ], + "exit": [ + "Block3", + "Block4" + ], + "id": "Block2Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block3Exit", + "id": "Block3", + "instructions": [ + { + "in": [ + "x_121" + ], + "op": "mload", + "out": [ + "_236" + ] + }, + { + "in": [ + "_236", + "0x00" + ], + "op": "eq", + "out": [ + "GHOST[0]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[0]" + ], + "exit": [ + "Block5", + "Block6" + ], + "id": "Block3Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block4Exit", + "id": "Block4", + "instructions": [] + }, + { + "exit": [ + "Block7" + ], + "id": "Block4Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block5Exit", + "id": "Block5", + "instructions": [ + { + "in": [ + "_236", + "0x01" + ], + "op": "eq", + "out": [ + "GHOST[1]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[1]" + ], + "exit": [ + "Block8", + "Block9" + ], + "id": "Block5Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block6Exit", + "id": "Block6", + "instructions": [ + { + "in": [ + "0x0202", + "0x02" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block7" + ], + "id": "Block6Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block7Exit", + "id": "Block7", + "instructions": [ + { + "in": [ + "0x0c0c", + "0x0c" + ], + "op": "sstore", + "out": [] + }, + { + "assignment": [ + "c_2_151" + ], + "in": [ + "0x1b" + ], + "out": [ + "c_2_151" + ] + } + ], + "type": "Assignment" + }, + { + "exit": [ + "Block7" + ], + "id": "Block7Exit", + "instructions": [ + "f_108" + ], + "type": "FunctionReturn" + }, + { + "exit": "Block8Exit", + "id": "Block8", + "instructions": [ + { + "in": [ + "_236", + "0x02" + ], + "op": "eq", + "out": [ + "GHOST[2]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[2]" + ], + "exit": [ + "Block10", + "Block11" + ], + "id": "Block8Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block9Exit", + "id": "Block9", + "instructions": [ + { + "in": [ + "0x0404", + "0x04" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block9" + ], + "id": "Block9Exit", + "instructions": [ + "f_108" + ], + "type": "FunctionReturn" + }, + { + "exit": "Block10Exit", + "id": "Block10", + "instructions": [ + { + "in": [ + "_236", + "0x03" + ], + "op": "eq", + "out": [ + "GHOST[3]" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "GHOST[3]" + ], + "exit": [ + "Block12", + "Block13" + ], + "id": "Block10Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block11Exit", + "id": "Block11", + "instructions": [ + { + "in": [ + "0x00", + "0x00" + ], + "op": "revert", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block11" + ], + "id": "Block11Exit", + "instructions": [], + "type": "Terminated" + }, + { + "exit": "Block12Exit", + "id": "Block12", + "instructions": [ + { + "in": [ + "0x02" + ], + "op": "mload", + "out": [ + "_246" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_246" + ], + "exit": [ + "Block14", + "Block15" + ], + "id": "Block12Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block13Exit", + "id": "Block13", + "instructions": [ + { + "in": [ + "0x0808", + "0x08" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block16" + ], + "id": "Block13Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block14Exit", + "id": "Block14", + "instructions": [ + { + "in": [ + "0x0a0a", + "0x0a" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block16" + ], + "id": "Block14Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block15Exit", + "id": "Block15", + "instructions": [ + { + "in": [ + "0x00", + "0x00" + ], + "op": "return", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block15" + ], + "id": "Block15Exit", + "instructions": [], + "type": "Terminated" + }, + { + "exit": "Block16Exit", + "id": "Block16", + "instructions": [ + { + "in": [ + "0x0b0b", + "0x0b" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block17" + ], + "id": "Block16Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block17Exit", + "id": "Block17", + "instructions": [ + { + "in": [ + "0x01", + "x_121" + ], + "op": "add", + "out": [ + "x_121" + ] + }, + { + "in": [ + "x_121" + ], + "op": "calldataload", + "out": [ + "_228" + ] + } + ], + "type": "BuiltinCall" + }, + { + "cond": [ + "_228" + ], + "exit": [ + "Block18", + "Block19" + ], + "id": "Block17Exit", + "instructions": [], + "type": "ConditionalJump" + }, + { + "exit": "Block18Exit", + "id": "Block18", + "instructions": [ + { + "in": [ + "0xffff", + "0xff" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block2" + ], + "id": "Block18Exit", + "instructions": [], + "type": "Jump" + }, + { + "exit": "Block19Exit", + "id": "Block19", + "instructions": [ + { + "in": [ + "x_121" + ], + "op": "g", + "out": [ + "_229" + ] + }, + { + "in": [ + "_229", + "0x00" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block19" + ], + "id": "Block19Exit", + "instructions": [ + "f_108" + ], + "type": "FunctionReturn" + } + ], + "entry": "Block1", + "returns": [ + "c_2_151" + ], + "type": "Function" + }, + "g": { + "arguments": [ + "a" + ], + "blocks": [ + { + "exit": "Block39Exit", + "id": "Block39", + "instructions": [ + { + "in": [ + "a", + "a" + ], + "op": "mul", + "out": [ + "c" + ] + }, + { + "in": [ + "c", + "a" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": [ + "Block39" + ], + "id": "Block39Exit", + "instructions": [ + "g" + ], + "type": "FunctionReturn" + } + ], + "entry": "Block39", + "returns": [ + "c" + ], + "type": "Function" + } + } + }, + "subObjects": {}, + "type": "Object" +} diff --git a/examples/cfgs/yul-files/complex3.yul b/examples/cfgs/yul-files/complex3.yul new file mode 100644 index 00000000..0ee576cb --- /dev/null +++ b/examples/cfgs/yul-files/complex3.yul @@ -0,0 +1,60 @@ +{ + + function g(a) -> c { + c:= mul(a,a) + sstore(a, c) + } + + function f(a, b) -> c { + for { let x := 42 } lt(x, a) { + x := add(x, 1) + if calldataload(x) + { + + sstore(0, g(x)) + leave + sstore(0x01, 0x0101) + } + sstore(0xFF, 0xFFFF) + } + { + switch mload(x) + case 0 { + sstore(0x02, 0x0202) + break + sstore(0x03, 0x0303) + } + case 1 { + sstore(0x04, 0x0404) + leave + sstore(0x05, 0x0505) + } + case 2 { + sstore(0x06, 0x0606) + revert(0, 0) + sstore(0x07, 0x0707) + } + case 3 { + sstore(0x08, 0x0808) + } + default { + if mload(b) { + return(0, 0) + sstore(0x09, 0x0909) + } + sstore(0x0A, 0x0A0A) + } + sstore(0x0B, 0x0B0B) + } + sstore(0x0C, 0x0C0C) + c:=27 + } + sstore(0x1,0x1) + pop(f(1,2)) + let z:= add(5,sload(0)) + let w := f(z,sload(4)) + sstore(z,w) + let x := f(w,sload(5)) + sstore(0x1,x) + let m:= g(z) +}