File tree 1 file changed +79
-0
lines changed
1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
3
+ from typing import List
4
+ from string import Template
5
+
6
+ import pyevmasm as asm
7
+
8
+ template_0_1 = """
9
+ Start:
10
+ PUSH1 Return
11
+ PUSH2 Function
12
+ JUMP
13
+ Return:
14
+ JUMPDEST
15
+ PUSH1 0x00
16
+ MSTORE
17
+ PUSH1 0x20
18
+ PUSH1 0x00
19
+ RETURN
20
+ Function:
21
+ """
22
+
23
+ template_1_1 = """
24
+ Start:
25
+ PUSH1 Return
26
+ PUSH4 ${input_value}
27
+ PUSH2 Function
28
+ JUMP
29
+ Return:
30
+ JUMPDEST
31
+ PUSH1 0x00
32
+ MSTORE
33
+ PUSH1 0x20
34
+ PUSH1 0x00
35
+ RETURN
36
+ Function:\n
37
+ """
38
+
39
+ template_2_1 = """
40
+ Start:
41
+ PUSH1 Return
42
+ PUSH4 ${input_value_1}
43
+ PUSH4 ${input_value_2}
44
+ PUSH2 Function
45
+ JUMP
46
+ Return:
47
+ JUMPDEST
48
+ PUSH1 0x00
49
+ MSTORE
50
+ PUSH1 0x20
51
+ PUSH1 0x00
52
+ RETURN
53
+ Function:\n
54
+ """
55
+
56
+ def generate_header_str (inputs : List [int ]) -> str :
57
+ assert len (inputs ) < 3
58
+ t = ""
59
+ if len (inputs ) is 1 :
60
+ t = Template (template_1_1 ).substitute (input_value = inputs [0 ])
61
+ elif len (inputs ) is 2 :
62
+ t = Template (template_2_1 ).substitute (
63
+ input_value_1 = inputs [0 ], input_value_2 = inputs [1 ])
64
+ return t
65
+
66
+ def generate_header_binary (inputs : List [int ]) -> str :
67
+ asm .assemble_hex (generate_header_str (inputs ))
68
+
69
+ def generate_contract (inputs : List [int ], func : str ) -> str :
70
+ assert len (inputs ) < 3
71
+ complete_str = generate_header_str (inputs ) + func
72
+ return asm .assemble_hex (complete_str )
73
+
74
+ def execute_in_evm (code : str , expected : str ) -> str :
75
+ pass
76
+
77
+
78
+ print (generate_contract (
79
+ inputs = ["0x12345678" , "0x87654321" ], func = "JUMPDEST\n ADD\n SWAP1\n JUMP" ))
You can’t perform that action at this time.
0 commit comments