From a65937cec046610270fe30426679c052b932e35a Mon Sep 17 00:00:00 2001 From: Pablo Gordillo Date: Tue, 22 Oct 2024 10:44:33 +0200 Subject: [PATCH] adding example --- examples/if/if-asm-solc.asm | 135 ++++++++++++++++++++++++++++++++++++ examples/if/if.cfg | 77 ++++++++++++++++++++ examples/if/if.yul | 37 ++++++++++ 3 files changed, 249 insertions(+) create mode 100644 examples/if/if-asm-solc.asm create mode 100644 examples/if/if.cfg create mode 100644 examples/if/if.yul diff --git a/examples/if/if-asm-solc.asm b/examples/if/if-asm-solc.asm new file mode 100644 index 00000000..1d91cee9 --- /dev/null +++ b/examples/if/if-asm-solc.asm @@ -0,0 +1,135 @@ +{ + ".code": [ + { + "begin": 64, + "end": 70, + "name": "PUSH", + "source": -1, + "value": "101" + }, + { + "begin": 58, + "end": 62, + "name": "PUSH", + "source": -1, + "value": "1" + }, + { + "begin": 51, + "end": 71, + "name": "SSTORE", + "source": -1 + }, + { + "begin": 100, + "end": 101, + "name": "PUSH", + "source": -1, + "value": "0" + }, + { + "begin": 87, + "end": 102, + "name": "CALLDATALOAD", + "source": -1 + }, + { + "begin": 84, + "end": 127, + "name": "PUSH [tag]", + "source": -1, + "value": "1" + }, + { + "begin": 84, + "end": 127, + "name": "JUMPI", + "source": -1 + }, + { + "begin": 27, + "end": 176, + "name": "tag", + "source": -1, + "value": "2" + }, + { + "begin": 27, + "end": 176, + "name": "JUMPDEST", + "source": -1 + }, + { + "begin": 154, + "end": 159, + "name": "PUSH", + "source": -1, + "value": "3" + }, + { + "begin": 140, + "end": 160, + "name": "DUP1", + "source": -1 + }, + { + "begin": 140, + "end": 160, + "name": "SSTORE", + "source": -1 + }, + { + "begin": 27, + "end": 176, + "name": "STOP", + "source": -1 + }, + { + "begin": 103, + "end": 127, + "name": "tag", + "source": -1, + "value": "1" + }, + { + "begin": 103, + "end": 127, + "name": "JUMPDEST", + "source": -1 + }, + { + "begin": 118, + "end": 124, + "name": "PUSH", + "source": -1, + "value": "202" + }, + { + "begin": 112, + "end": 116, + "name": "PUSH", + "source": -1, + "value": "2" + }, + { + "begin": 105, + "end": 125, + "name": "SSTORE", + "source": -1 + }, + { + "begin": 103, + "end": 127, + "name": "PUSH [tag]", + "source": -1, + "value": "2" + }, + { + "begin": 103, + "end": 127, + "name": "JUMP", + "source": -1 + } + ], + "sourceList": [] +} diff --git a/examples/if/if.cfg b/examples/if/if.cfg new file mode 100644 index 00000000..a831dd94 --- /dev/null +++ b/examples/if/if.cfg @@ -0,0 +1,77 @@ +{ + "object": { + "blocks": [ + { + "exit": { + "cond": "v3", + "targets": [ + "Block2", + "Block1" + ], + "type": "ConditionalJump" + }, + "id": "Block0", + "instructions": [ + { + "in": [ + "0x0101", + "0x01" + ], + "op": "sstore", + "out": [] + }, + { + "in": [ + "0x00" + ], + "op": "calldataload", + "out": [ + "v3" + ] + } + ], + "type": "BuiltinCall" + }, + { + "exit": { + "type": "MainExit" + }, + "id": "Block2", + "instructions": [ + { + "in": [ + "0x03", + "0x03" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + }, + { + "exit": { + "targets": [ + "Block2" + ], + "type": "Jump" + }, + "id": "Block1", + "instructions": [ + { + "in": [ + "0x0202", + "0x02" + ], + "op": "sstore", + "out": [] + } + ], + "type": "BuiltinCall" + } + ], + "functions": {} + }, + "subObjects": {}, + "type": "Object" +} diff --git a/examples/if/if.yul b/examples/if/if.yul new file mode 100644 index 00000000..a313c53e --- /dev/null +++ b/examples/if/if.yul @@ -0,0 +1,37 @@ +{ + sstore(0x01, 0x0101) + if calldataload(0) { + sstore(0x02, 0x0202) + } + sstore(0x03, 0x003) +} +// ---- +// digraph CFG { +// nodesep=0.7; +// node[shape=box]; +// +// Entry [label="Entry"]; +// Entry -> Block0; +// Block0 [label="\ +// sstore: [ 0x0101 0x01 ] => [ ]\l\ +// calldataload: [ 0x00 ] => [ TMP[calldataload, 0] ]\l\ +// "]; +// Block0 -> Block0Exit; +// Block0Exit [label="{ TMP[calldataload, 0]| { <0> Zero | <1> NonZero }}" shape=Mrecord]; +// Block0Exit:0 -> Block1; +// Block0Exit:1 -> Block2; +// +// Block1 [label="\ +// sstore: [ 0x03 0x03 ] => [ ]\l\ +// "]; +// Block1Exit [label="MainExit"]; +// Block1 -> Block1Exit; +// +// Block2 [label="\ +// sstore: [ 0x0202 0x02 ] => [ ]\l\ +// "]; +// Block2 -> Block2Exit [arrowhead=none]; +// Block2Exit [label="Jump" shape=oval]; +// Block2Exit -> Block1; +// +// }