Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 3ea0dd8

Browse files
authored
One CREATE2 opcode allowed if initCode > 0 and called during account validation (#51)
1 parent 561ac76 commit 3ea0dd8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pkg/entrypoint/simulation.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ var (
2424
// A marker to delimit between account and paymaster simulation.
2525
markerOpCode = "NUMBER"
2626

27+
// Pre-marker represents account validation.
28+
preMarker = "account"
29+
30+
// Post-marker represents paymaster validation.
31+
postMarker = "paymaster"
32+
2733
// All opcodes executed at this depth are from the EntryPoint and allowed.
2834
allowedDepth = float64(1)
2935

@@ -33,7 +39,7 @@ var (
3339
// Only one create2 opcode is allowed if these two conditions are met:
3440
// 1. op.initcode.length != 0
3541
// 2. During account simulation (i.e. before markerOpCode)
36-
// create2OpCode = "CREATE2"
42+
create2OpCode = "CREATE2"
3743

3844
// List of opcodes related to CALL.
3945
callOpcodes = mapset.NewSet(
@@ -148,11 +154,12 @@ func TraceSimulateValidation(rpc *rpc.Client, entryPoint common.Address, op *use
148154
}
149155

150156
var prev structLog
151-
simFor := "account"
157+
create2count := 0
158+
simFor := preMarker
152159
for _, sl := range res.StructLogs {
153160
if sl.Depth == allowedDepth {
154161
if sl.Op == markerOpCode {
155-
simFor = "paymaster"
162+
simFor = postMarker
156163
}
157164
continue
158165
}
@@ -161,6 +168,14 @@ func TraceSimulateValidation(rpc *rpc.Client, entryPoint common.Address, op *use
161168
return fmt.Errorf("%s: uses opcode %s incorrectly", simFor, gasOpCode)
162169
}
163170

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+
164179
if baseForbiddenOpCodes.Contains(sl.Op) {
165180
return fmt.Errorf("%s: uses forbidden opcode %s", simFor, sl.Op)
166181
}

0 commit comments

Comments
 (0)