Skip to content

Commit c00a3f6

Browse files
committed
Handle blob preimage key
1 parent 76a7371 commit c00a3f6

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

rvgo/cmd/run.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,23 @@ func Run(ctx *cli.Context) error {
6767
outLog := &LoggingWriter{Name: "program std-out", Log: l}
6868
errLog := &LoggingWriter{Name: "program std-err", Log: l}
6969

70-
stopAtPreimageType := ctx.String(cannon.RunStopAtPreimageTypeFlag.Name)
71-
if stopAtPreimageType != "" && stopAtPreimageType != "any" && stopAtPreimageType != "local" && stopAtPreimageType != "global" {
72-
return fmt.Errorf("invalid preimage type %q, must be either 'any', 'local' or 'global'", stopAtPreimageType)
70+
stopAtAnyPreimage := false
71+
var stopAtPreimageTypeByte preimage.KeyType
72+
switch ctx.String(cannon.RunStopAtPreimageTypeFlag.Name) {
73+
case "local":
74+
stopAtPreimageTypeByte = preimage.LocalKeyType
75+
case "keccak":
76+
stopAtPreimageTypeByte = preimage.Keccak256KeyType
77+
case "sha256":
78+
stopAtPreimageTypeByte = preimage.Sha256KeyType
79+
case "blob":
80+
stopAtPreimageTypeByte = preimage.BlobKeyType
81+
case "any":
82+
stopAtAnyPreimage = true
83+
case "":
84+
// 0 preimage type is forbidden so will not stop at any preimage
85+
default:
86+
return fmt.Errorf("invalid preimage type %q", ctx.String(cannon.RunStopAtPreimageTypeFlag.Name))
7387
}
7488
stopAtPreimageLargerThan := ctx.Int(cannon.RunStopAtPreimageLargerThanFlag.Name)
7589

@@ -185,17 +199,11 @@ func Run(ctx *cli.Context) error {
185199
}
186200

187201
if preimageRead := state.PreimageOffset > prevPreimageOffset; preimageRead {
188-
if stopAtPreimageType == "any" {
202+
if stopAtAnyPreimage {
189203
break
190204
}
191-
if stopAtPreimageType != "" {
192-
keyType := byte(preimage.LocalKeyType)
193-
if stopAtPreimageType == "global" {
194-
keyType = byte(preimage.Keccak256KeyType)
195-
}
196-
if state.PreimageKey[0] == keyType {
197-
break
198-
}
205+
if state.PreimageKey[0] == byte(stopAtPreimageTypeByte) {
206+
break
199207
}
200208
if stopAtPreimageLargerThan != 0 && len(us.LastPreimage()) > stopAtPreimageLargerThan {
201209
break

0 commit comments

Comments
 (0)