24
24
// A marker to delimit between account and paymaster simulation.
25
25
markerOpCode = "NUMBER"
26
26
27
+ // Pre-marker represents account validation.
28
+ preMarker = "account"
29
+
30
+ // Post-marker represents paymaster validation.
31
+ postMarker = "paymaster"
32
+
27
33
// All opcodes executed at this depth are from the EntryPoint and allowed.
28
34
allowedDepth = float64 (1 )
29
35
33
39
// Only one create2 opcode is allowed if these two conditions are met:
34
40
// 1. op.initcode.length != 0
35
41
// 2. During account simulation (i.e. before markerOpCode)
36
- // create2OpCode = "CREATE2"
42
+ create2OpCode = "CREATE2"
37
43
38
44
// List of opcodes related to CALL.
39
45
callOpcodes = mapset .NewSet (
@@ -148,11 +154,12 @@ func TraceSimulateValidation(rpc *rpc.Client, entryPoint common.Address, op *use
148
154
}
149
155
150
156
var prev structLog
151
- simFor := "account"
157
+ create2count := 0
158
+ simFor := preMarker
152
159
for _ , sl := range res .StructLogs {
153
160
if sl .Depth == allowedDepth {
154
161
if sl .Op == markerOpCode {
155
- simFor = "paymaster"
162
+ simFor = postMarker
156
163
}
157
164
continue
158
165
}
@@ -161,6 +168,14 @@ func TraceSimulateValidation(rpc *rpc.Client, entryPoint common.Address, op *use
161
168
return fmt .Errorf ("%s: uses opcode %s incorrectly" , simFor , gasOpCode )
162
169
}
163
170
171
+ if sl .Op == create2OpCode {
172
+ create2count ++
173
+
174
+ if create2count > 1 || len (op .InitCode ) == 0 || simFor != preMarker {
175
+ return fmt .Errorf ("%s: uses opcode %s incorrectly" , simFor , sl .Op )
176
+ }
177
+ }
178
+
164
179
if baseForbiddenOpCodes .Contains (sl .Op ) {
165
180
return fmt .Errorf ("%s: uses forbidden opcode %s" , simFor , sl .Op )
166
181
}
0 commit comments