@@ -67,9 +67,23 @@ func Run(ctx *cli.Context) error {
67
67
outLog := & LoggingWriter {Name : "program std-out" , Log : l }
68
68
errLog := & LoggingWriter {Name : "program std-err" , Log : l }
69
69
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 ))
73
87
}
74
88
stopAtPreimageLargerThan := ctx .Int (cannon .RunStopAtPreimageLargerThanFlag .Name )
75
89
@@ -185,17 +199,11 @@ func Run(ctx *cli.Context) error {
185
199
}
186
200
187
201
if preimageRead := state .PreimageOffset > prevPreimageOffset ; preimageRead {
188
- if stopAtPreimageType == "any" {
202
+ if stopAtAnyPreimage {
189
203
break
190
204
}
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
199
207
}
200
208
if stopAtPreimageLargerThan != 0 && len (us .LastPreimage ()) > stopAtPreimageLargerThan {
201
209
break
0 commit comments