@@ -169,11 +169,31 @@ def validate():
169
169
0x71e3cf81 , # magic - always SIGSTACK (ignore call_whitelist)
170
170
0x12345678 , # invalid
171
171
0x0b00c380 , # inverse of magic - just invalid
172
+ 0x3770fb22 , # syscall: sol_memset_
173
+ 1 , # success without relocation. works in v3+
174
+ 0 ,
175
+ 2 ,
176
+ 3 ,
177
+ 4 ,
178
+ 0xffffffff , # overflow ok because of negative offsets
172
179
]:
173
180
test_vectors_all_ix .append ({
174
181
"op" : f"{ op :02x} " ,
175
182
"cu_avail" : 100 ,
176
- # hashmap containing vaild pc: 0, 1, 2 (higher are trimmed)
183
+ # hashmap containing valid function
184
+ "call_whitelist" : [0x04 ],
185
+ "rodata" :
186
+ bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
187
+ bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]) + \
188
+ bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
189
+ })
190
+ # TODO: the following generates invalid functions to test validate()
191
+ # it's ok in v0-v2, it should return -2 in v3+
192
+ test_vectors_all_ix .append ({
193
+ "op" : f"{ op :02x} " ,
194
+ "cu_avail" : 100 ,
195
+ # hashmap containing valid pc: 0, 1, 2 (higher are trimmed)
196
+ # these are invalid fn in v3+
177
197
"call_whitelist" : [0xff ],
178
198
"rodata" :
179
199
bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
@@ -248,6 +268,22 @@ def validate():
248
268
bytes ([op , ((sreg << 4 ) + dreg ) % 0xFF ]) + offset .to_bytes (2 , "little" ) + imm .to_bytes (4 , "little" ) + \
249
269
bytes ([0x95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
250
270
})
271
+
272
+ # syscall (v3)
273
+ if op == 0x95 :
274
+ sreg = 0
275
+ dreg = 0
276
+ for imm in [
277
+ 3 , # sol_memset_
278
+ 100 , # invalid
279
+ ]:
280
+ test_vectors_all_ix .append ({
281
+ "op" : f"{ op :02x} " ,
282
+ "cu_avail" : 100 ,
283
+ "rodata" :
284
+ bytes ([ op , 0 , 0 , 0 ]) + imm .to_bytes (4 , "little" ) + \
285
+ bytes ([0x9d , 0 , 0 , 0 , 0 , 0 , 0 , 0 ])
286
+ })
251
287
# fmt: on
252
288
253
289
@@ -310,14 +346,22 @@ def _into_key_data(key_prefix, test_vectors):
310
346
with open (f"{ OUTPUT_DIR } /{ testname } /v0/{ filename } .bin" , "wb" ) as f :
311
347
f .write (serialized_instr )
312
348
313
- syscall_ctx .vm_ctx .sbpf_version = 1
314
- serialized_instr = syscall_ctx .SerializeToString (deterministic = True )
315
- with open (f"{ OUTPUT_DIR } /{ testname } /v1/{ filename } .bin" , "wb" ) as f :
316
- f .write (serialized_instr )
349
+ # syscall_ctx.vm_ctx.sbpf_version = 1
350
+ # serialized_instr = syscall_ctx.SerializeToString(deterministic=True)
351
+ # with open(f"{OUTPUT_DIR}/{testname}/v1/{filename}.bin", "wb") as f:
352
+ # f.write(serialized_instr)
317
353
318
354
syscall_ctx .vm_ctx .sbpf_version = 2
319
355
serialized_instr = syscall_ctx .SerializeToString (deterministic = True )
320
356
with open (f"{ OUTPUT_DIR } /{ testname } /v2/{ filename } .bin" , "wb" ) as f :
321
357
f .write (serialized_instr )
322
358
359
+ syscall_ctx .vm_ctx .sbpf_version = 3
360
+ syscall_ctx .vm_ctx .rodata = bytes (
361
+ [x if x != 0x95 else 0x9D for x in syscall_ctx .vm_ctx .rodata ]
362
+ )
363
+ serialized_instr = syscall_ctx .SerializeToString (deterministic = True )
364
+ with open (f"{ OUTPUT_DIR } /{ testname } /v3/{ filename } .bin" , "wb" ) as f :
365
+ f .write (serialized_instr )
366
+
323
367
print ("done!" )
0 commit comments