@@ -403,7 +403,6 @@ TEST_F(AvmExecutionTests, nestedInternalCalls)
403
403
// 0 1 2 3 4
404
404
TEST_F (AvmExecutionTests, jumpAndCalldatacopy)
405
405
{
406
- GTEST_SKIP ();
407
406
std::string bytecode_hex = to_hex (OpCode::SET_8) + // opcode SET
408
407
" 00" // Indirect flag
409
408
" 03" // U32
@@ -419,8 +418,8 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy)
419
418
" 00000000" // cd_offset
420
419
" 00000001" // copy_size
421
420
" 0000000A" // dst_offset // M[10] = 13, M[11] = 156
422
- + to_hex (OpCode::JUMP ) + // opcode JUMP
423
- " 00000005 " // jmp_dest (FDIV located at 3)
421
+ + to_hex (OpCode::JUMP_16 ) + // opcode JUMP
422
+ " 0005 " // jmp_dest (FDIV located at 3)
424
423
+ to_hex (OpCode::SUB) + // opcode SUB
425
424
" 00" // Indirect flag
426
425
" 06" // FF
@@ -456,14 +455,16 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy)
456
455
457
456
// JUMP
458
457
EXPECT_THAT (instructions.at (3 ),
459
- AllOf (Field (&Instruction::op_code, OpCode::JUMP ),
460
- Field (&Instruction::operands, ElementsAre (VariantWith<uint32_t >( 3 )))));
458
+ AllOf (Field (&Instruction::op_code, OpCode::JUMP_16 ),
459
+ Field (&Instruction::operands, ElementsAre (VariantWith<uint16_t >( 5 )))));
461
460
462
461
std::vector<FF> returndata;
463
462
auto trace = Execution::gen_trace (instructions, returndata, std::vector<FF>{ 13 , 156 }, public_inputs_vec);
464
463
465
464
// Expected sequence of PCs during execution
466
- std::vector<FF> pc_sequence{ 0 , 1 , 3 , 4 };
465
+ std::vector<FF> pc_sequence{
466
+ 0 , 1 , 2 , 3 , 4 , 6 ,
467
+ };
467
468
468
469
for (size_t i = 0 ; i < 4 ; i++) {
469
470
EXPECT_EQ (trace.at (i + 1 ).main_pc , pc_sequence.at (i));
@@ -492,61 +493,70 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy)
492
493
// We test this bytecode with two calldatacopy values: 9873123 and 0.
493
494
TEST_F (AvmExecutionTests, jumpiAndCalldatacopy)
494
495
{
495
- GTEST_SKIP ();
496
- std::string bytecode_hex = to_hex (OpCode::CALLDATACOPY) + // opcode CALLDATACOPY (no in tag)
497
- " 00" // Indirect flag
498
- " 00000000" // cd_offset
499
- " 00000001" // copy_size
500
- " 0000000A" // dst_offset 10
501
- + to_hex (OpCode::SET_16) + // opcode SET
502
- " 00" // Indirect flag
503
- " 02" // U16
504
- " 0014" // val 20
505
- " 0065" // dst_offset 101
506
- + to_hex (OpCode::JUMPI) + // opcode JUMPI
507
- " 00" // Indirect flag
508
- " 00000004" // jmp_dest (MUL located at 4)
509
- " 0000000A" // cond_offset 10
510
- + to_hex (OpCode::ADD) + // opcode ADD
511
- " 00" // Indirect flag
512
- " 02" // U16
513
- " 00000065" // addr 101
514
- " 00000065" // addr 101
515
- " 00000065" // output addr 101
516
- + to_hex (OpCode::MUL) + // opcode MUL
517
- " 00" // Indirect flag
518
- " 02" // U16
519
- " 00000065" // addr 101
520
- " 00000065" // addr 101
521
- " 00000066" // output of MUL addr 102
522
- + to_hex (OpCode::RETURN) + // opcode RETURN
523
- " 00" // Indirect flag
524
- " 00000000" // ret offset 0
525
- " 00000000" // ret size 0
496
+ std::string bytecode_hex = to_hex (OpCode::SET_8) + // opcode SET
497
+ " 00" // Indirect flag
498
+ " 03" // U32
499
+ " 00" // val
500
+ " 00" // dst_offset
501
+ + to_hex (OpCode::SET_8) + // opcode SET
502
+ " 00" // Indirect flag
503
+ " 03" // U32
504
+ " 01" // val
505
+ " 01" // dst_offset
506
+ + to_hex (OpCode::CALLDATACOPY) + // opcode CALLDATACOPY (no in tag)
507
+ " 00" // Indirect flag
508
+ " 00000000" // cd_offset
509
+ " 00000001" // copy_size
510
+ " 0000000A" // dst_offset 10
511
+ + to_hex (OpCode::SET_8) + // opcode SET
512
+ " 00" // Indirect flag
513
+ " 02" // U16
514
+ " 14" // val 20
515
+ " 65" // dst_offset 101
516
+ + to_hex (OpCode::JUMPI_16) + // opcode JUMPI
517
+ " 00" // Indirect flag
518
+ " 0006" // jmp_dest (MUL located at 6)
519
+ " 000A" // cond_offset 10
520
+ + to_hex (OpCode::ADD) + // opcode ADD
521
+ " 00" // Indirect flag
522
+ " 02" // U16
523
+ " 00000065" // addr 101
524
+ " 00000065" // addr 101
525
+ " 00000065" // output addr 101
526
+ + to_hex (OpCode::MUL) + // opcode MUL
527
+ " 00" // Indirect flag
528
+ " 02" // U16
529
+ " 00000065" // addr 101
530
+ " 00000065" // addr 101
531
+ " 00000066" // output of MUL addr 102
532
+ + to_hex (OpCode::RETURN) + // opcode RETURN
533
+ " 00" // Indirect flag
534
+ " 00000000" // ret offset 0
535
+ " 00000000" // ret size 0
526
536
;
527
537
528
538
auto bytecode = hex_to_bytes (bytecode_hex);
529
539
auto instructions = Deserialization::parse (bytecode);
530
540
531
- ASSERT_THAT (instructions, SizeIs (6 ));
541
+ ASSERT_THAT (instructions, SizeIs (8 ));
532
542
533
543
// We test parsing of JUMPI.
534
544
535
545
// JUMPI
536
546
EXPECT_THAT (
537
- instructions.at (2 ),
538
- AllOf (Field (&Instruction::op_code, OpCode::JUMPI ),
547
+ instructions.at (4 ),
548
+ AllOf (Field (&Instruction::op_code, OpCode::JUMPI_16 ),
539
549
Field (&Instruction::operands,
540
- ElementsAre (VariantWith<uint8_t >(0 ), VariantWith<uint32_t >( 4 ), VariantWith<uint32_t >(10 )))));
550
+ ElementsAre (VariantWith<uint8_t >(0 ), VariantWith<uint16_t >( 6 ), VariantWith<uint16_t >(10 )))));
541
551
542
- std::vector<FF> returndata{} ;
552
+ std::vector<FF> returndata;
543
553
auto trace_jump = Execution::gen_trace (instructions, returndata, std::vector<FF>{ 9873123 }, public_inputs_vec);
544
554
auto trace_no_jump = Execution::gen_trace (instructions, returndata, std::vector<FF>{ 0 }, public_inputs_vec);
545
555
546
556
// Expected sequence of PCs during execution with jump
547
- std::vector<FF> pc_sequence_jump{ 0 , 1 , 2 , 4 , 5 };
557
+ std::vector<FF> pc_sequence_jump{ 0 , 1 , 2 , 3 , 4 , 6 , 7 };
548
558
// Expected sequence of PCs during execution without jump
549
- std::vector<FF> pc_sequence_no_jump{ 0 , 1 , 2 , 3 , 4 , 5 };
559
+ std::vector<FF> pc_sequence_no_jump{ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 };
550
560
551
561
for (size_t i = 0 ; i < 5 ; i++) {
552
562
EXPECT_EQ (trace_jump.at (i + 1 ).main_pc , pc_sequence_jump.at (i));
@@ -556,22 +566,6 @@ TEST_F(AvmExecutionTests, jumpiAndCalldatacopy)
556
566
EXPECT_EQ (trace_no_jump.at (i + 1 ).main_pc , pc_sequence_no_jump.at (i));
557
567
}
558
568
559
- // JUMP CASE
560
- // Find the first row enabling the MUL opcode
561
- auto row = std::ranges::find_if (trace_jump.begin (), trace_jump.end (), [](Row r) { return r.main_sel_op_mul == 1 ; });
562
- EXPECT_EQ (row->main_ic , 400 ); // 400 = 20 * 20
563
-
564
- // Find the first row enabling the addition selector.
565
- row = std::ranges::find_if (trace_jump.begin (), trace_jump.end (), [](Row r) { return r.main_sel_op_add == 1 ; });
566
- // It must have failed as addition was "jumped over".
567
- EXPECT_EQ (row, trace_jump.end ());
568
-
569
- // NO JUMP CASE
570
- // Find the first row enabling the MUL opcode
571
- row =
572
- std::ranges::find_if (trace_no_jump.begin (), trace_no_jump.end (), [](Row r) { return r.main_sel_op_mul == 1 ; });
573
- EXPECT_EQ (row->main_ic , 1600 ); // 800 = (20 + 20) * (20 + 20)
574
-
575
569
// traces validation
576
570
validate_trace (std::move (trace_jump), public_inputs, { 9873123 });
577
571
validate_trace (std::move (trace_no_jump), public_inputs, { 0 });
0 commit comments