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

Commit 198cd01

Browse files
authored
GAS opcode only allowed if followed by CALL opcodes (#49)
1 parent 58b77a6 commit 198cd01

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pkg/entrypoint/simulation.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ var (
2828
allowedDepth = float64(1)
2929

3030
// The gas opcode is only allowed if followed immediately by callOpcodes.
31-
// gasOpCode = "GAS"
31+
gasOpCode = "GAS"
3232

3333
// Only one create2 opcode is allowed if these two conditions are met:
3434
// 1. op.initcode.length != 0
3535
// 2. During account simulation (i.e. before markerOpCode)
3636
// create2OpCode = "CREATE2"
3737

3838
// List of opcodes related to CALL.
39-
// callOpcodes = mapset.NewSet(
40-
// "CALL",
41-
// "DELEGATECALL",
42-
// "CALLCODE",
43-
// "STATICCALL",
44-
// )
39+
callOpcodes = mapset.NewSet(
40+
"CALL",
41+
"DELEGATECALL",
42+
"CALLCODE",
43+
"STATICCALL",
44+
)
4545

4646
// List of opcodes not allowed during simulation for depth > allowedDepth (i.e. account, paymaster, or
4747
// contracts called by them).
@@ -147,19 +147,25 @@ func TraceSimulateValidation(rpc *rpc.Client, entryPoint common.Address, op *use
147147
return err
148148
}
149149

150+
var prev structLog
150151
simFor := "account"
151152
for _, sl := range res.StructLogs {
152-
if sl.Depth == allowedDepth && sl.Op == markerOpCode {
153-
simFor = "paymaster"
154-
}
155-
156153
if sl.Depth == allowedDepth {
154+
if sl.Op == markerOpCode {
155+
simFor = "paymaster"
156+
}
157157
continue
158158
}
159159

160+
if prev.Op == gasOpCode && !callOpcodes.Contains(sl.Op) {
161+
return fmt.Errorf("%s: uses opcode %s incorrectly", simFor, gasOpCode)
162+
}
163+
160164
if baseForbiddenOpCodes.Contains(sl.Op) {
161165
return fmt.Errorf("%s: uses forbidden opcode %s", simFor, sl.Op)
162166
}
167+
168+
prev = sl
163169
}
164170

165171
return nil

0 commit comments

Comments
 (0)