From 3a01ad93e21e9e6cd27b7a2a4c1e2c9f24d6363e Mon Sep 17 00:00:00 2001 From: Facundo Date: Fri, 11 Oct 2024 16:19:36 +0100 Subject: [PATCH] feat(avm)!: more instr wire format takes u16 (#9174) Make most instructions take offsets as u16. The ones that were not migrated are expected to change or be removed. Yields ~2% bytecode size improvement in public_dispatch. Part of #9059. --- avm-transpiler/src/transpile.rs | 138 ++++--- .../vm/avm/tests/execution.test.cpp | 340 +++++++++--------- .../vm/avm/trace/deserialization.cpp | 92 ++--- .../barretenberg/vm/avm/trace/execution.cpp | 128 +++---- .../src/avm/opcodes/accrued_substate.test.ts | 60 ++-- .../src/avm/opcodes/accrued_substate.ts | 26 +- .../src/avm/opcodes/control_flow.test.ts | 4 +- .../simulator/src/avm/opcodes/control_flow.ts | 2 +- .../src/avm/opcodes/conversion.test.ts | 14 +- .../simulator/src/avm/opcodes/conversion.ts | 8 +- .../simulator/src/avm/opcodes/ec_add.test.ts | 24 +- .../simulator/src/avm/opcodes/ec_add.ts | 14 +- .../src/avm/opcodes/external_calls.test.ts | 70 ++-- .../src/avm/opcodes/external_calls.ts | 20 +- .../simulator/src/avm/opcodes/hashing.test.ts | 30 +- .../simulator/src/avm/opcodes/hashing.ts | 16 +- .../simulator/src/avm/opcodes/memory.test.ts | 12 +- .../simulator/src/avm/opcodes/memory.ts | 6 +- .../simulator/src/avm/opcodes/misc.ts | 8 +- .../src/avm/opcodes/multi_scalar_mul.test.ts | 16 +- .../src/avm/opcodes/multi_scalar_mul.ts | 8 +- .../simulator/src/avm/opcodes/storage.test.ts | 12 +- .../simulator/src/avm/opcodes/storage.ts | 4 +- .../bytecode_serialization.test.ts | 64 ++-- 24 files changed, 553 insertions(+), 563 deletions(-) diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index d900923d217..04e02fecf0e 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -229,12 +229,12 @@ pub fn brillig_to_avm( .build(), ), operands: vec![ - AvmOperand::U32 { - value: offset_address.to_usize() as u32, // cdOffset (calldata offset) + AvmOperand::U16 { + value: offset_address.to_usize() as u16, // cdOffset (calldata offset) }, - AvmOperand::U32 { value: size_address.to_usize() as u32 }, // sizeOffset - AvmOperand::U32 { - value: destination_address.to_usize() as u32, // dstOffset + AvmOperand::U16 { value: size_address.to_usize() as u16 }, // sizeOffset + AvmOperand::U16 { + value: destination_address.to_usize() as u16, // dstOffset }, ], ..Default::default() @@ -308,7 +308,7 @@ pub fn brillig_to_avm( let avm_loc = brillig_pcs_to_avm_pcs[*location]; avm_instrs.push(AvmInstruction { opcode: AvmOpcode::INTERNALCALL, - operands: vec![AvmOperand::U32 { value: avm_loc as u32 }], + operands: vec![AvmOperand::U16 { value: avm_loc as u16 }], ..Default::default() }); } @@ -319,8 +319,8 @@ pub fn brillig_to_avm( opcode: AvmOpcode::RETURN, indirect: Some(AddressingModeBuilder::default().build()), operands: vec![ - AvmOperand::U32 { value: *return_data_offset as u32 }, - AvmOperand::U32 { value: *return_data_size as u32 }, + AvmOperand::U16 { value: *return_data_offset as u16 }, + AvmOperand::U16 { value: *return_data_size as u16 }, ], ..Default::default() }); @@ -516,14 +516,14 @@ fn handle_external_call( .build(), ), operands: vec![ - AvmOperand::U32 { value: gas_offset_ptr.to_usize() as u32 }, - AvmOperand::U32 { value: address_offset.to_usize() as u32 }, - AvmOperand::U32 { value: args_offset_ptr.to_usize() as u32 }, - AvmOperand::U32 { value: args_size_offset.to_usize() as u32 }, - AvmOperand::U32 { value: ret_offset_ptr.to_usize() as u32 }, - AvmOperand::U32 { value: ret_size }, - AvmOperand::U32 { value: success_offset.to_usize() as u32 }, - AvmOperand::U32 { value: function_selector_offset.to_usize() as u32 }, + AvmOperand::U16 { value: gas_offset_ptr.to_usize() as u16 }, + AvmOperand::U16 { value: address_offset.to_usize() as u16 }, + AvmOperand::U16 { value: args_offset_ptr.to_usize() as u16 }, + AvmOperand::U16 { value: args_size_offset.to_usize() as u16 }, + AvmOperand::U16 { value: ret_offset_ptr.to_usize() as u16 }, + AvmOperand::U16 { value: ret_size as u16 }, + AvmOperand::U16 { value: success_offset.to_usize() as u16 }, + AvmOperand::U16 { value: function_selector_offset.to_usize() as u16 }, ], ..Default::default() }); @@ -571,9 +571,9 @@ fn handle_note_hash_exists( .build(), ), operands: vec![ - AvmOperand::U32 { value: note_hash_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: leaf_index_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: exists_offset_operand.to_usize() as u32 }, + AvmOperand::U16 { value: note_hash_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: leaf_index_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: exists_offset_operand.to_usize() as u16 }, ], ..Default::default() }); @@ -608,8 +608,8 @@ fn handle_emit_unencrypted_log( .build(), ), operands: vec![ - AvmOperand::U32 { value: message_offset.to_usize() as u32 }, - AvmOperand::U32 { value: message_size_offset.to_usize() as u32 }, + AvmOperand::U16 { value: message_offset.to_usize() as u16 }, + AvmOperand::U16 { value: message_size_offset.to_usize() as u16 }, ], ..Default::default() }); @@ -644,7 +644,7 @@ fn handle_emit_note_hash_or_nullifier( avm_instrs.push(AvmInstruction { opcode: if is_nullifier { AvmOpcode::EMITNULLIFIER } else { AvmOpcode::EMITNOTEHASH }, indirect: Some(AddressingModeBuilder::default().direct_operand(offset_operand).build()), - operands: vec![AvmOperand::U32 { value: offset_operand.to_usize() as u32 }], + operands: vec![AvmOperand::U16 { value: offset_operand.to_usize() as u16 }], ..Default::default() }); } @@ -682,9 +682,9 @@ fn handle_nullifier_exists( .build(), ), operands: vec![ - AvmOperand::U32 { value: nullifier_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: address_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: exists_offset_operand.to_usize() as u32 }, + AvmOperand::U16 { value: nullifier_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: address_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: exists_offset_operand.to_usize() as u16 }, ], ..Default::default() }); @@ -733,9 +733,9 @@ fn handle_l1_to_l2_msg_exists( .build(), ), operands: vec![ - AvmOperand::U32 { value: msg_hash_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: msg_leaf_index_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: exists_offset_operand.to_usize() as u32 }, + AvmOperand::U16 { value: msg_hash_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: msg_leaf_index_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: exists_offset_operand.to_usize() as u16 }, ], ..Default::default() }); @@ -777,8 +777,8 @@ fn handle_send_l2_to_l1_msg( .build(), ), operands: vec![ - AvmOperand::U32 { value: recipient_offset_operand.to_usize() as u32 }, - AvmOperand::U32 { value: content_offset_operand.to_usize() as u32 }, + AvmOperand::U16 { value: recipient_offset_operand.to_usize() as u16 }, + AvmOperand::U16 { value: content_offset_operand.to_usize() as u16 }, ], ..Default::default() }); @@ -982,9 +982,9 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B .build(), ), operands: vec![ - AvmOperand::U32 { value: output_offset as u32 }, - AvmOperand::U32 { value: state_offset as u32 }, - AvmOperand::U32 { value: inputs_offset as u32 }, + AvmOperand::U16 { value: output_offset as u16 }, + AvmOperand::U16 { value: state_offset as u16 }, + AvmOperand::U16 { value: inputs_offset as u16 }, ], ..Default::default() }); @@ -1034,8 +1034,8 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B .build(), ), operands: vec![ - AvmOperand::U32 { value: input_state_offset as u32 }, - AvmOperand::U32 { value: output_state_offset as u32 }, + AvmOperand::U16 { value: input_state_offset as u16 }, + AvmOperand::U16 { value: output_state_offset as u16 }, ], ..Default::default() }); @@ -1079,9 +1079,9 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B .build(), ), operands: vec![ - AvmOperand::U32 { value: dest_offset as u32 }, - AvmOperand::U32 { value: message_offset as u32 }, - AvmOperand::U32 { value: message_size_offset as u32 }, + AvmOperand::U16 { value: dest_offset as u16 }, + AvmOperand::U16 { value: message_offset as u16 }, + AvmOperand::U16 { value: message_size_offset as u16 }, ], ..Default::default() }); @@ -1103,10 +1103,10 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B ), tag: None, operands: vec![ - AvmOperand::U32 { value: input_offset }, - AvmOperand::U32 { value: output_offset }, - AvmOperand::U32 { value: radix_offset }, - AvmOperand::U32 { value: num_limbs }, + AvmOperand::U16 { value: input_offset as u16 }, + AvmOperand::U16 { value: output_offset as u16 }, + AvmOperand::U16 { value: radix_offset as u16 }, + AvmOperand::U16 { value: num_limbs as u16 }, AvmOperand::U8 { value: *output_bits as u8 }, ], }); @@ -1135,13 +1135,13 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B .build(), ), operands: vec![ - AvmOperand::U32 { value: p1_x_offset.to_usize() as u32 }, - AvmOperand::U32 { value: p1_y_offset.to_usize() as u32 }, - AvmOperand::U32 { value: p1_infinite_offset.to_usize() as u32 }, - AvmOperand::U32 { value: p2_x_offset.to_usize() as u32 }, - AvmOperand::U32 { value: p2_y_offset.to_usize() as u32 }, - AvmOperand::U32 { value: p2_infinite_offset.to_usize() as u32 }, - AvmOperand::U32 { value: result.pointer.to_usize() as u32 }, + AvmOperand::U16 { value: p1_x_offset.to_usize() as u16 }, + AvmOperand::U16 { value: p1_y_offset.to_usize() as u16 }, + AvmOperand::U16 { value: p1_infinite_offset.to_usize() as u16 }, + AvmOperand::U16 { value: p2_x_offset.to_usize() as u16 }, + AvmOperand::U16 { value: p2_y_offset.to_usize() as u16 }, + AvmOperand::U16 { value: p2_infinite_offset.to_usize() as u16 }, + AvmOperand::U16 { value: result.pointer.to_usize() as u16 }, ], ..Default::default() }), @@ -1166,10 +1166,10 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B .build(), ), operands: vec![ - AvmOperand::U32 { value: points_offset as u32 }, - AvmOperand::U32 { value: scalars_offset as u32 }, - AvmOperand::U32 { value: outputs_offset as u32 }, - AvmOperand::U32 { value: num_points as u32 }, + AvmOperand::U16 { value: points_offset as u16 }, + AvmOperand::U16 { value: scalars_offset as u16 }, + AvmOperand::U16 { value: outputs_offset as u16 }, + AvmOperand::U16 { value: num_points as u16 }, ], ..Default::default() }); @@ -1240,12 +1240,10 @@ fn handle_debug_log( .build(), ), operands: vec![ - AvmOperand::U32 { value: message_offset.to_usize() as u32 }, - AvmOperand::U32 { value: message_size }, - // indirect - AvmOperand::U32 { value: fields_offset_ptr.to_usize() as u32 }, - // indirect - AvmOperand::U32 { value: fields_size_ptr.to_usize() as u32 }, + AvmOperand::U16 { value: message_offset.to_usize() as u16 }, + AvmOperand::U16 { value: message_size as u16 }, + AvmOperand::U16 { value: fields_offset_ptr.to_usize() as u16 }, + AvmOperand::U16 { value: fields_size_ptr.to_usize() as u16 }, ], ..Default::default() }); @@ -1286,13 +1284,9 @@ fn handle_calldata_copy( .build(), ), operands: vec![ - AvmOperand::U32 { - value: cd_offset.to_usize() as u32, // cdOffset (calldata offset) - }, - AvmOperand::U32 { value: copy_size_offset.to_usize() as u32 }, // copy size - AvmOperand::U32 { - value: dest_offset.to_usize() as u32, // dstOffset - }, + AvmOperand::U16 { value: cd_offset.to_usize() as u16 }, + AvmOperand::U16 { value: copy_size_offset.to_usize() as u16 }, + AvmOperand::U16 { value: dest_offset.to_usize() as u16 }, ], ..Default::default() }); @@ -1320,8 +1314,8 @@ fn handle_return( AddressingModeBuilder::default().indirect_operand(&return_data_offset).build(), ), operands: vec![ - AvmOperand::U32 { value: return_data_offset.to_usize() as u32 }, - AvmOperand::U32 { value: return_data_size }, + AvmOperand::U16 { value: return_data_offset.to_usize() as u16 }, + AvmOperand::U16 { value: return_data_size as u16 }, ], ..Default::default() }); @@ -1358,8 +1352,8 @@ fn handle_storage_write( .build(), ), operands: vec![ - AvmOperand::U32 { value: src_offset.to_usize() as u32 }, - AvmOperand::U32 { value: slot_offset.to_usize() as u32 }, + AvmOperand::U16 { value: src_offset.to_usize() as u16 }, + AvmOperand::U16 { value: slot_offset.to_usize() as u16 }, ], ..Default::default() }); @@ -1433,8 +1427,8 @@ fn handle_storage_read( .build(), ), operands: vec![ - AvmOperand::U32 { value: slot_offset.to_usize() as u32 }, - AvmOperand::U32 { value: dest_offset.to_usize() as u32 }, + AvmOperand::U16 { value: slot_offset.to_usize() as u16 }, + AvmOperand::U16 { value: dest_offset.to_usize() as u16 }, ], ..Default::default() }); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp index 188f94e0306..6957a3d8972 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp @@ -88,8 +88,8 @@ TEST_F(AvmExecutionTests, basicAddReturn) "0001" // addr c 1 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -111,7 +111,7 @@ TEST_F(AvmExecutionTests, basicAddReturn) EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); validate_trace(std::move(trace), public_inputs, {}, {}); @@ -138,8 +138,8 @@ TEST_F(AvmExecutionTests, setAndSubOpcodes) "01" // addr c 1 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -210,8 +210,8 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes) std::string const ret_hex = to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 for (int i = 0; i < 12; i++) { bytecode_hex.append(mul_hex); @@ -248,7 +248,7 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes) EXPECT_THAT(instructions.at(14), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); @@ -277,7 +277,7 @@ TEST_F(AvmExecutionTests, simpleInternalCall) "0D3D2518" // val 222111000 = 0xD3D2518 "0004" // dst_offset 4 + to_hex(OpCode::INTERNALCALL) + // opcode INTERNALCALL - "00000004" // jmp_dest + "0004" // jmp_dest + to_hex(OpCode::ADD_16) + // opcode ADD "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -286,8 +286,8 @@ TEST_F(AvmExecutionTests, simpleInternalCall) "0009" // addr c9 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000" // ret size 0 + "0000" // ret offset 0 + "0000" // ret size 0 + to_hex(OpCode::SET_32) + // opcode SET "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -306,7 +306,7 @@ TEST_F(AvmExecutionTests, simpleInternalCall) // INTERNALCALL EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::INTERNALCALL), - Field(&Instruction::operands, ElementsAre(VariantWith(4))))); + Field(&Instruction::operands, ElementsAre(VariantWith(4))))); // INTERNALRETURN EXPECT_EQ(instructions.at(5).op_code, OpCode::INTERNALRETURN); @@ -343,7 +343,7 @@ TEST_F(AvmExecutionTests, nestedInternalCalls) { auto internalCallInstructionHex = [](std::string const& dst_offset) { return to_hex(OpCode::INTERNALCALL) // opcode INTERNALCALL - + "000000" + dst_offset; + + "00" + dst_offset; }; auto setInstructionHex = [](std::string const& val, std::string const& dst_offset) { @@ -361,8 +361,8 @@ TEST_F(AvmExecutionTests, nestedInternalCalls) const std::string return_instruction_hex = to_hex(OpCode::RETURN) // opcode RETURN + "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 const std::string bytecode_f1 = to_hex(OpCode::ADD_8) + tag_address_arguments + to_hex(OpCode::INTERNALRETURN); const std::string bytecode_f2 = to_hex(OpCode::MUL_8) + tag_address_arguments + to_hex(OpCode::INTERNALRETURN); @@ -424,9 +424,9 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) "01" // dst_offset 101 + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY (no in tag) "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "0000000A" // dst_offset // M[10] = 13, M[11] = 156 + "0000" // cd_offset + "0001" // copy_size + "000A" // dst_offset // M[10] = 13, M[11] = 156 + to_hex(OpCode::JUMP_16) + // opcode JUMP "0005" // jmp_dest (FDIV located at 3) + to_hex(OpCode::SUB_8) + // opcode SUB @@ -443,8 +443,8 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) "01" // addr c 1 (156 / 13 = 12) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000" // ret size 0 + "0000" // ret offset 0 + "0000" // ret size 0 ; auto bytecode = hex_to_bytes(bytecode_hex); @@ -459,9 +459,9 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) AllOf(Field(&Instruction::op_code, OpCode::CALLDATACOPY), Field(&Instruction::operands, ElementsAre(VariantWith(0), - VariantWith(0), - VariantWith(1), - VariantWith(10))))); + VariantWith(0), + VariantWith(1), + VariantWith(10))))); // JUMP EXPECT_THAT(instructions.at(3), @@ -515,9 +515,9 @@ TEST_F(AvmExecutionTests, jumpiAndCalldatacopy) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY (no in tag) "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "0000000A" // dst_offset 10 + "0000" // cd_offset + "0001" // copy_size + "000A" // dst_offset 10 + to_hex(OpCode::SET_8) + // opcode SET "00" // Indirect flag + to_hex(AvmMemoryTag::U16) + @@ -541,8 +541,8 @@ TEST_F(AvmExecutionTests, jumpiAndCalldatacopy) "66" // output of MUL addr 102 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000" // ret size 0 + "0000" // ret offset 0 + "0000" // ret size 0 ; auto bytecode = hex_to_bytes(bytecode_hex); @@ -595,8 +595,8 @@ TEST_F(AvmExecutionTests, movOpcode) "21" // dst_offset 33 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -653,8 +653,8 @@ TEST_F(AvmExecutionTests, indMovOpcode) "02" // dst_offset 2 --> direct offset 11 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -692,8 +692,8 @@ TEST_F(AvmExecutionTests, setAndCastOpcodes) "12" // addr casted a + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -733,9 +733,9 @@ TEST_F(AvmExecutionTests, toRadixLeOpcode) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000001" // dst_offset + "0000" // cd_offset + "0001" // copy_size + "0001" // dst_offset + to_hex(OpCode::SET_8) + // opcode SET for indirect src "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -753,15 +753,15 @@ TEST_F(AvmExecutionTests, toRadixLeOpcode) "80" // radix_offset 80 + to_hex(OpCode::TORADIXLE) + // opcode TO_RADIX_LE "03" // Indirect flag - "00000011" // src_offset 17 (indirect) - "00000015" // dst_offset 21 (indirect) - "00000080" // radix_offset 80 (direct) - "00000100" // limbs: 256 + "0011" // src_offset 17 (indirect) + "0015" // dst_offset 21 (indirect) + "0080" // radix_offset 80 (direct) + "0100" // limbs: 256 "00" // output_bits: false + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000005" // ret offset 0 - "00000100"; // ret size 0 + "0005" // ret offset 0 + "0100"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -799,9 +799,9 @@ TEST_F(AvmExecutionTests, toRadixLeOpcodeBitsMode) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000001" // dst_offset + "0000" // cd_offset + "0001" // copy_size + "0001" // dst_offset + to_hex(OpCode::SET_8) + // opcode SET for indirect src "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -819,15 +819,15 @@ TEST_F(AvmExecutionTests, toRadixLeOpcodeBitsMode) "80" // radix_offset 80 + to_hex(OpCode::TORADIXLE) + // opcode TO_RADIX_LE "03" // Indirect flag - "00000011" // src_offset 17 (indirect) - "00000015" // dst_offset 21 (indirect) - "00000080" // radix_offset 80 (direct) - "00000100" // limbs: 256 + "0011" // src_offset 17 (indirect) + "0015" // dst_offset 21 (indirect) + "0080" // radix_offset 80 (direct) + "0100" // limbs: 256 "01" // output_bits: true + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000005" // ret offset 0 - "00000100"; // ret size 0 + "0005" // ret offset 0 + "0100"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -890,13 +890,13 @@ TEST_F(AvmExecutionTests, sha256CompressionOpcode) "23" // dst_offset 35 + to_hex(OpCode::SHA256COMPRESSION) + // opcode SHA256COMPRESSION "00" // Indirect flag - "00000100" // output offset - "00000001" // state offset - "00000009" // input offset + "0100" // output offset + "0001" // state offset + "0009" // input offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000100" // ret offset 256 - "00000008"; // ret size 8 + "0100" // ret offset 256 + "0008"; // ret size 8 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -937,9 +937,9 @@ TEST_F(AvmExecutionTests, poseidon2PermutationOpCode) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // opcode CALL DATA COPY "00" // Indirect Flag - "00000000" // cd_offset - "00000001" // copy_size - "00000001" // dst_offset 1 + "0000" // cd_offset + "0001" // copy_size + "0001" // dst_offset 1 + to_hex(OpCode::SET_8) + // opcode SET for indirect src (input) "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -952,12 +952,12 @@ TEST_F(AvmExecutionTests, poseidon2PermutationOpCode) "23" // dst_offset 35 + to_hex(OpCode::POSEIDON2) + // opcode POSEIDON2 "03" // Indirect flag (first 2 operands indirect) - "00000024" // input offset (indirect 36) - "00000023" // output offset (indirect 35) + "0024" // input offset (indirect 36) + "0023" // output offset (indirect 35) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000009" // ret offset 256 - "00000004"; // ret size 8 + "0009" // ret offset 256 + "0004"; // ret size 8 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1029,13 +1029,13 @@ TEST_F(AvmExecutionTests, keccakf1600OpCode) "0023" // dst_offset 35 + to_hex(OpCode::KECCAKF1600) + // opcode KECCAKF1600 "03" // Indirect flag (first 2 operands indirect) - "00000023" // output offset (indirect 35) - "00000024" // input offset (indirect 36) - "00000025" // length offset 37 + "0023" // output offset (indirect 35) + "0024" // input offset (indirect 36) + "0025" // length offset 37 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000100" // ret offset 256 - "00000019"; // ret size 25 + "0100" // ret offset 256 + "0019"; // ret size 25 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1091,8 +1091,8 @@ TEST_F(AvmExecutionTests, keccakOpCode) "00000025" // length offset 37 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000100" // ret offset 256 - "00000020"; // ret size 32 + "0100" // ret offset 256 + "0020"; // ret size 32 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1127,9 +1127,9 @@ TEST_F(AvmExecutionTests, pedersenHashOpCode) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // Calldatacopy "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000000" // dst_offset + "0000" // cd_offset + "0001" // copy_size + "0000" // dst_offset + to_hex(OpCode::SET_8) + // opcode SET for direct hash index offset "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -1153,8 +1153,8 @@ TEST_F(AvmExecutionTests, pedersenHashOpCode) "00000005" // length offset (direct) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000003" // ret offset 3 - "00000001"; // ret size 1 + "0003" // ret offset 3 + "0001"; // ret size 1 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1191,9 +1191,9 @@ TEST_F(AvmExecutionTests, embeddedCurveAddOpCode) "01" // dst_offset + to_hex(OpCode::CALLDATACOPY) + // Calldatacopy "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000000" // dst_offset + "0000" // cd_offset + "0001" // copy_size + "0000" // dst_offset + to_hex(OpCode::CAST_8) + // opcode CAST inf to U8 "00" // Indirect flag + to_hex(AvmMemoryTag::U8) + @@ -1211,17 +1211,17 @@ TEST_F(AvmExecutionTests, embeddedCurveAddOpCode) "06" // dst_offset + to_hex(OpCode::ECADD) + // opcode ECADD "0040" // Indirect flag (sixth operand indirect) - "00000000" // hash_index offset (direct) - "00000001" // dest offset (direct) - "00000002" // input offset (indirect) - "00000003" // length offset (direct) - "00000004" // length offset (direct) - "00000005" // length offset (direct) - "00000006" // length offset (direct) + "0000" // hash_index offset (direct) + "0001" // dest offset (direct) + "0002" // input offset (indirect) + "0003" // length offset (direct) + "0004" // length offset (direct) + "0005" // length offset (direct) + "0006" // length offset (direct) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000007" // ret offset 3 - "00000003"; // ret size 1 + "0007" // ret offset 3 + "0003"; // ret size 1 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1267,9 +1267,9 @@ TEST_F(AvmExecutionTests, msmOpCode) "01" + to_hex(OpCode::CALLDATACOPY) + // Calldatacopy "00" // Indirect flag - "00000000" // cd_offset 0 - "00000001" // copy_size (10 elements) - "00000000" // dst_offset 0 + "0000" // cd_offset 0 + "0001" // copy_size (10 elements) + "0000" // dst_offset 0 + to_hex(OpCode::CAST_8) + // opcode CAST inf to U8 "00" // Indirect flag + to_hex(AvmMemoryTag::U8) + @@ -1302,14 +1302,14 @@ TEST_F(AvmExecutionTests, msmOpCode) "0f" + // dst offset to_hex(OpCode::MSM) + // opcode MSM "07" // Indirect flag (first 3 indirect) - "0000000d" // points offset - "0000000e" // scalars offset - "0000000f" // output offset - "0000000b" // length offset + "000d" // points offset + "000e" // scalars offset + "000f" // output offset + "000b" // length offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "0000000c" // ret offset 12 (this overwrites) - "00000003"; // ret size 3 + "000c" // ret offset 12 (this overwrites) + "0003"; // ret size 3 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1350,9 +1350,9 @@ TEST_F(AvmExecutionTests, pedersenCommitmentOpcode) "01" + to_hex(OpCode::CALLDATACOPY) + // Calldatacopy "00" // Indirect flag - "00000000" // cd_offset 0 - "00000001" // copy_size (2 elements) - "00000000" // dst_offset 0 + "0000" // cd_offset 0 + "0001" // copy_size (2 elements) + "0000" // dst_offset 0 + to_hex(OpCode::SET_8) + // opcode SET for indirect input "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -1381,8 +1381,8 @@ TEST_F(AvmExecutionTests, pedersenCommitmentOpcode) "0000000f" // gen ctx index offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000020" // ret offset - "00000003"; // ret size 3 + "0020" // ret offset + "0003"; // ret size 3 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1450,8 +1450,8 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) "000C" // dst_offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000001" // ret offset 1 - "0000000C"; // ret size 12 + "0001" // ret offset 1 + "000C"; // ret size 12 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1683,8 +1683,8 @@ TEST_F(AvmExecutionTests, l2GasLeft) "0011" // dst_offset (indirect addr: 17) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1729,8 +1729,8 @@ TEST_F(AvmExecutionTests, daGasLeft) "0027" // dst_offset (indirect addr: 17) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1812,22 +1812,22 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) "01" // dst 1 + to_hex(OpCode::EMITNOTEHASH) + // opcode EMITNOTEHASH "00" // Indirect flag - "00000001" // src offset 1 + "0001" // src offset 1 + to_hex(OpCode::EMITNULLIFIER) + // opcode EMITNULLIFIER "00" // Indirect flag - "00000001" // src offset 1 + "0001" // src offset 1 + to_hex(OpCode::EMITUNENCRYPTEDLOG) + // opcode EMITUNENCRYPTEDLOG "00" // Indirect flag - "00000001" // src offset 1 - "00000002" // src size offset + "0001" // src offset 1 + "0002" // src size offset + to_hex(OpCode::SENDL2TOL1MSG) + // opcode SENDL2TOL1MSG "00" // Indirect flag - "00000001" // src offset 1 - "00000001" // src offset 1 + "0001" // src offset 1 + "0001" // src offset 1 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1918,12 +1918,12 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeSimple) "01" // dst 1 + to_hex(OpCode::SLOAD) + // opcode SLOAD "00" // Indirect flag - "00000001" // slot offset 1 - "00000002" // write storage value to offset 2 + "0001" // slot offset 1 + "0002" // write storage value to offset 2 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -1974,17 +1974,17 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeSimple) "01" + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000001" // dst_offset, (i.e. where we store the addr) + "0000" // cd_offset + "0001" // copy_size + "0001" // dst_offset, (i.e. where we store the addr) + to_hex(OpCode::SSTORE) + // opcode SSTORE "00" // Indirect flag - "00000001" // src offset - "00000003" // slot offset + "0001" // src offset + "0003" // slot offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -2031,16 +2031,16 @@ TEST_F(AvmExecutionTests, kernelOutputStorageOpcodes) "01" // dst 1 + to_hex(OpCode::SLOAD) + // opcode SLOAD "00" // Indirect flag - "00000001" // slot offset 1 - "00000002" // write storage value to offset 2 + "0001" // slot offset 1 + "0002" // write storage value to offset 2 + to_hex(OpCode::SSTORE) + // opcode SSTORE "00" // Indirect flag - "00000002" // src offset 2 (since the sload writes to 2) - "00000001" // slot offset is 1 + "0002" // src offset 2 (since the sload writes to 2) + "0001" // slot offset is 1 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -2106,23 +2106,23 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) "01" // dst 1 + to_hex(OpCode::NOTEHASHEXISTS) + // opcode NOTEHASHEXISTS "00" // Indirect flag - "00000001" // slot offset 1 - "00000002" // Leaf index offset 2 - "00000003" // write storage value to offset 2 (exists value) + "0001" // slot offset 1 + "0002" // Leaf index offset 2 + "0003" // write storage value to offset 2 (exists value) + to_hex(OpCode::NULLIFIEREXISTS) + // opcode NULLIFIEREXISTS "00" // Indirect flag - "00000001" // slot offset 1 - "00000002" // Contract offset 2 - "00000003" // value write offset 2 (exists value) + "0001" // slot offset 1 + "0002" // Contract offset 2 + "0003" // value write offset 2 (exists value) + to_hex(OpCode::L1TOL2MSGEXISTS) + // opcode L1TOL2MSGEXISTS "00" // Indirect flag - "00000001" // slot offset 1 - "00000002" // Lead offset 2 - "00000003" // value write offset 2 (exists value) + "0001" // slot offset 1 + "0002" // Lead offset 2 + "0003" // value write offset 2 (exists value) + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -2240,24 +2240,24 @@ TEST_F(AvmExecutionTests, opCallOpcodes) "01" + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000000" // dst_offset + "0000" // cd_offset + "0001" // copy_size + "0000" // dst_offset + bytecode_preamble // Load up memory offsets + to_hex(OpCode::CALL) + // opcode CALL "003f" // Indirect flag - "00000011" // gas offset - "00000012" // addr offset - "00000013" // args offset - "00000014" // args size offset - "00000015" // ret offset - "00000002" // ret size - "00000016" // success offset - "00000017" // function_selector_offset + "0011" // gas offset + "0012" // addr offset + "0013" // args offset + "0014" // args size offset + "0015" // ret offset + "0002" // ret size + "0016" // success offset + "0017" // function_selector_offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000100" // ret offset 8 - "00000003"; // ret size 3 (extra read is for the success flag) + "0100" // ret offset 8 + "0003"; // ret size 3 (extra read is for the success flag) auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -2293,9 +2293,9 @@ TEST_F(AvmExecutionTests, opGetContractInstanceOpcodes) "01" + to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY for addr "00" // Indirect flag - "00000000" // cd_offset - "00000001" // copy_size - "00000001" // dst_offset, (i.e. where we store the addr) + "0000" // cd_offset + "0001" // copy_size + "0001" // dst_offset, (i.e. where we store the addr) + to_hex(OpCode::SET_8) + // opcode SET for the indirect dst offset "00" // Indirect flag + to_hex(AvmMemoryTag::U32) + @@ -2307,8 +2307,8 @@ TEST_F(AvmExecutionTests, opGetContractInstanceOpcodes) "00000002" // dst offset + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000003" // ret offset 3 - "00000006"; // ret size 6 + "0003" // ret offset 3 + "0006"; // ret size 6 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); @@ -2333,12 +2333,12 @@ TEST_F(AvmExecutionTests, invalidOpcode) std::string bytecode_hex = to_hex(OpCode::ADD_16) + // opcode ADD "00" // Indirect flag + to_hex(AvmMemoryTag::U16) + - "0007" // addr a 7 - "0009" // addr b 9 - "0001" // addr c 1 - "AB" // Invalid opcode byte - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0007" // addr a 7 + "0009" // addr b 9 + "0001" // addr c 1 + "AB" // Invalid opcode byte + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); EXPECT_THROW_WITH_MESSAGE(Deserialization::parse(bytecode), "Invalid opcode"); @@ -2355,8 +2355,8 @@ TEST_F(AvmExecutionTests, invalidInstructionTag) "0001" // addr c 1 + to_hex(OpCode::RETURN) + // opcode RETURN "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 + "0000" // ret offset 0 + "0000"; // ret size 0 auto bytecode = hex_to_bytes(bytecode_hex); EXPECT_THROW_WITH_MESSAGE(Deserialization::parse(bytecode), "Instruction tag is invalid"); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp index 8741a6abbda..103e6a8521b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp @@ -21,17 +21,17 @@ const std::vector three_operand_format8 = { const std::vector three_operand_format16 = { OperandType::INDIRECT8, OperandType::TAG, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16, }; -const std::vector kernel_input_operand_format = { OperandType::INDIRECT8, OperandType::UINT32 }; +const std::vector kernel_input_operand_format = { OperandType::INDIRECT8, OperandType::UINT16 }; const std::vector external_call_format = { OperandType::INDIRECT16, - /*gasOffset=*/OperandType::UINT32, - /*addrOffset=*/OperandType::UINT32, - /*argsOffset=*/OperandType::UINT32, - /*argsSize=*/OperandType::UINT32, - /*retOffset=*/OperandType::UINT32, - /*retSize*/ OperandType::UINT32, - /*successOffset=*/OperandType::UINT32, - /*functionSelector=*/OperandType::UINT32 }; + /*gasOffset=*/OperandType::UINT16, + /*addrOffset=*/OperandType::UINT16, + /*argsOffset=*/OperandType::UINT16, + /*argsSize=*/OperandType::UINT16, + /*retOffset=*/OperandType::UINT16, + /*retSize*/ OperandType::UINT16, + /*successOffset=*/OperandType::UINT16, + /*functionSelector=*/OperandType::UINT16 }; // Contrary to TS, the format does not contain the opcode byte which prefixes any instruction. // The format for OpCode::SET has to be handled separately as it is variable based on the tag. @@ -81,12 +81,12 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = } }, // Execution Environment - Calldata - { OpCode::CALLDATACOPY, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + { OpCode::CALLDATACOPY, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, // Machine State - Internal Control Flow { OpCode::JUMP_16, { OperandType::UINT16 } }, { OpCode::JUMPI_16, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, - { OpCode::INTERNALCALL, { OperandType::UINT32 } }, + { OpCode::INTERNALCALL, { OperandType::UINT16 } }, { OpCode::INTERNALRETURN, {} }, // Machine State - Memory @@ -100,93 +100,93 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = { OpCode::MOV_16, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, // Side Effects - Public Storage - { OpCode::SLOAD, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, - { OpCode::SSTORE, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, + { OpCode::SLOAD, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, + { OpCode::SSTORE, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, // Side Effects - Notes, Nullfiers, Logs, Messages { OpCode::NOTEHASHEXISTS, { OperandType::INDIRECT8, - OperandType::UINT32, - /*TODO: leafIndexOffset is not constrained*/ OperandType::UINT32, - OperandType::UINT32 } }, + OperandType::UINT16, + /*TODO: leafIndexOffset is not constrained*/ OperandType::UINT16, + OperandType::UINT16 } }, { OpCode::EMITNOTEHASH, { OperandType::INDIRECT8, - OperandType::UINT32, + OperandType::UINT16, } }, // TODO: new format for these { OpCode::NULLIFIEREXISTS, { OperandType::INDIRECT8, - OperandType::UINT32, - /*TODO: Address is not constrained*/ OperandType::UINT32, - OperandType::UINT32 } }, + OperandType::UINT16, + /*TODO: Address is not constrained*/ OperandType::UINT16, + OperandType::UINT16 } }, { OpCode::EMITNULLIFIER, { OperandType::INDIRECT8, - OperandType::UINT32, + OperandType::UINT16, } }, // TODO: new format for these /*TODO: leafIndexOffset is not constrained*/ { OpCode::L1TOL2MSGEXISTS, { OperandType::INDIRECT8, - OperandType::UINT32, - /*TODO: leafIndexOffset is not constrained*/ OperandType::UINT32, - OperandType::UINT32 } }, + OperandType::UINT16, + /*TODO: leafIndexOffset is not constrained*/ OperandType::UINT16, + OperandType::UINT16 } }, { OpCode::GETCONTRACTINSTANCE, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, { OpCode::EMITUNENCRYPTEDLOG, { OperandType::INDIRECT8, - OperandType::UINT32, - OperandType::UINT32, + OperandType::UINT16, + OperandType::UINT16, } }, - { OpCode::SENDL2TOL1MSG, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, + { OpCode::SENDL2TOL1MSG, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, // Control Flow - Contract Calls { OpCode::CALL, external_call_format }, { OpCode::STATICCALL, external_call_format }, // DELEGATECALL, -- not in simulator - { OpCode::RETURN, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, + { OpCode::RETURN, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, // REVERT, { OpCode::REVERT_8, { OperandType::INDIRECT8, OperandType::UINT8, OperandType::UINT8 } }, { OpCode::REVERT_16, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, // Misc { OpCode::DEBUGLOG, - { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, // Gadgets // Gadgets - Hashing { OpCode::KECCAK, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, - { OpCode::POSEIDON2, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32 } }, + { OpCode::POSEIDON2, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16 } }, { OpCode::SHA256COMPRESSION, - { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, - { OpCode::KECCAKF1600, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, + { OpCode::KECCAKF1600, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, { OpCode::PEDERSEN, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, // TEMP ECADD without relative memory { OpCode::ECADD, { OperandType::INDIRECT16, - OperandType::UINT32, // lhs.x - OperandType::UINT32, // lhs.y - OperandType::UINT32, // lhs.is_infinite - OperandType::UINT32, // rhs.x - OperandType::UINT32, // rhs.y - OperandType::UINT32, // rhs.is_infinite - OperandType::UINT32 } }, // dst_offset + OperandType::UINT16, // lhs.x + OperandType::UINT16, // lhs.y + OperandType::UINT16, // lhs.is_infinite + OperandType::UINT16, // rhs.x + OperandType::UINT16, // rhs.y + OperandType::UINT16, // rhs.is_infinite + OperandType::UINT16 } }, // dst_offset { OpCode::MSM, - { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, { OpCode::PEDERSENCOMMITMENT, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, // Gadget - Conversion { OpCode::TORADIXLE, { OperandType::INDIRECT8, - OperandType::UINT32, - OperandType::UINT32, - OperandType::UINT32, - OperandType::UINT32, + OperandType::UINT16, + OperandType::UINT16, + OperandType::UINT16, + OperandType::UINT16, OperandType::UINT8 } }, // Gadgets - Unused for now { OpCode::SHA256COMPRESSION, - { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, - { OpCode::KECCAKF1600, { OperandType::INDIRECT8, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, + { OpCode::KECCAKF1600, { OperandType::INDIRECT8, OperandType::UINT16, OperandType::UINT16, OperandType::UINT16 } }, }; const std::unordered_map OPERAND_TYPE_SIZE = { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp index fce0e49d59c..a30ff683510 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp @@ -530,9 +530,9 @@ std::vector Execution::gen_trace(std::vector const& instructio // Execution Environment - Calldata case OpCode::CALLDATACOPY: trace_builder.op_calldata_copy(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; // Machine State - Internal Control Flow @@ -545,7 +545,7 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(2))); break; case OpCode::INTERNALCALL: - trace_builder.op_internal_call(std::get(inst.operands.at(0))); + trace_builder.op_internal_call(std::get(inst.operands.at(0))); break; case OpCode::INTERNALRETURN: trace_builder.op_internal_return(); @@ -608,42 +608,42 @@ std::vector Execution::gen_trace(std::vector const& instructio // World State case OpCode::SLOAD: trace_builder.op_sload(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), + std::get(inst.operands.at(1)), 1, - std::get(inst.operands.at(2))); + std::get(inst.operands.at(2))); break; case OpCode::SSTORE: trace_builder.op_sstore(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), + std::get(inst.operands.at(1)), 1, - std::get(inst.operands.at(2))); + std::get(inst.operands.at(2))); break; case OpCode::NOTEHASHEXISTS: trace_builder.op_note_hash_exists(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; case OpCode::EMITNOTEHASH: trace_builder.op_emit_note_hash(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); + std::get(inst.operands.at(1))); break; case OpCode::NULLIFIEREXISTS: trace_builder.op_nullifier_exists(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; case OpCode::EMITNULLIFIER: trace_builder.op_emit_nullifier(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); + std::get(inst.operands.at(1))); break; case OpCode::L1TOL2MSGEXISTS: trace_builder.op_l1_to_l2_msg_exists(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; case OpCode::GETCONTRACTINSTANCE: trace_builder.op_get_contract_instance(std::get(inst.operands.at(0)), @@ -654,42 +654,42 @@ std::vector Execution::gen_trace(std::vector const& instructio // Accrued Substate case OpCode::EMITUNENCRYPTEDLOG: trace_builder.op_emit_unencrypted_log(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); break; case OpCode::SENDL2TOL1MSG: trace_builder.op_emit_l2_to_l1_msg(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); break; // Control Flow - Contract Calls case OpCode::CALL: trace_builder.op_call(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3)), - std::get(inst.operands.at(4)), - std::get(inst.operands.at(5)), - std::get(inst.operands.at(6)), - std::get(inst.operands.at(7)), - std::get(inst.operands.at(8))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4)), + std::get(inst.operands.at(5)), + std::get(inst.operands.at(6)), + std::get(inst.operands.at(7)), + std::get(inst.operands.at(8))); break; case OpCode::STATICCALL: trace_builder.op_static_call(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3)), - std::get(inst.operands.at(4)), - std::get(inst.operands.at(5)), - std::get(inst.operands.at(6)), - std::get(inst.operands.at(7)), - std::get(inst.operands.at(8))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4)), + std::get(inst.operands.at(5)), + std::get(inst.operands.at(6)), + std::get(inst.operands.at(7)), + std::get(inst.operands.at(8))); break; case OpCode::RETURN: { auto ret = trace_builder.op_return(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); returndata.insert(returndata.end(), ret.begin(), ret.end()); break; @@ -728,8 +728,8 @@ std::vector Execution::gen_trace(std::vector const& instructio break; case OpCode::POSEIDON2: trace_builder.op_poseidon2_permutation(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); break; case OpCode::PEDERSEN: @@ -741,44 +741,44 @@ std::vector Execution::gen_trace(std::vector const& instructio break; case OpCode::ECADD: trace_builder.op_ec_add(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3)), - std::get(inst.operands.at(4)), - std::get(inst.operands.at(5)), - std::get(inst.operands.at(6)), - std::get(inst.operands.at(7))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4)), + std::get(inst.operands.at(5)), + std::get(inst.operands.at(6)), + std::get(inst.operands.at(7))); break; case OpCode::MSM: trace_builder.op_variable_msm(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3)), - std::get(inst.operands.at(4))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4))); break; // Conversions case OpCode::TORADIXLE: trace_builder.op_to_radix_le(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3)), - std::get(inst.operands.at(4)), + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4)), std::get(inst.operands.at(5))); break; case OpCode::SHA256COMPRESSION: trace_builder.op_sha256_compression(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; case OpCode::KECCAKF1600: trace_builder.op_keccakf1600(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1)), - std::get(inst.operands.at(2)), - std::get(inst.operands.at(3))); + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3))); break; case OpCode::PEDERSENCOMMITMENT: diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts index 14841c01950..93c2ed3b86e 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts @@ -49,15 +49,15 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ NoteHashExists.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // noteHashOffset - ...Buffer.from('23456789', 'hex'), // leafIndexOffset - ...Buffer.from('456789AB', 'hex'), // existsOffset + ...Buffer.from('1234', 'hex'), // noteHashOffset + ...Buffer.from('2345', 'hex'), // leafIndexOffset + ...Buffer.from('4567', 'hex'), // existsOffset ]); const inst = new NoteHashExists( /*indirect=*/ 0x01, - /*noteHashOffset=*/ 0x12345678, - /*leafIndexOffset=*/ 0x23456789, - /*existsOffset=*/ 0x456789ab, + /*noteHashOffset=*/ 0x1234, + /*leafIndexOffset=*/ 0x2345, + /*existsOffset=*/ 0x4567, ); expect(NoteHashExists.deserialize(buf)).toEqual(inst); @@ -110,9 +110,9 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ EmitNoteHash.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // offset + ...Buffer.from('1234', 'hex'), // offset ]); - const inst = new EmitNoteHash(/*indirect=*/ 0x01, /*offset=*/ 0x12345678); + const inst = new EmitNoteHash(/*indirect=*/ 0x01, /*offset=*/ 0x1234); expect(EmitNoteHash.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); @@ -134,15 +134,15 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ NullifierExists.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // nullifierOffset - ...Buffer.from('02345678', 'hex'), // addressOffset - ...Buffer.from('456789AB', 'hex'), // existsOffset + ...Buffer.from('1234', 'hex'), // nullifierOffset + ...Buffer.from('0234', 'hex'), // addressOffset + ...Buffer.from('4567', 'hex'), // existsOffset ]); const inst = new NullifierExists( /*indirect=*/ 0x01, - /*nullifierOffset=*/ 0x12345678, - /*addressOffset=*/ 0x02345678, - /*existsOffset=*/ 0x456789ab, + /*nullifierOffset=*/ 0x1234, + /*addressOffset=*/ 0x0234, + /*existsOffset=*/ 0x4567, ); expect(NullifierExists.deserialize(buf)).toEqual(inst); @@ -190,9 +190,9 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ EmitNullifier.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // offset + ...Buffer.from('1234', 'hex'), // offset ]); - const inst = new EmitNullifier(/*indirect=*/ 0x01, /*offset=*/ 0x12345678); + const inst = new EmitNullifier(/*indirect=*/ 0x01, /*offset=*/ 0x1234); expect(EmitNullifier.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); @@ -240,15 +240,15 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ L1ToL2MessageExists.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // msgHashOffset - ...Buffer.from('456789AB', 'hex'), // msgLeafIndexOffset - ...Buffer.from('CDEF0123', 'hex'), // existsOffset + ...Buffer.from('1234', 'hex'), // msgHashOffset + ...Buffer.from('4567', 'hex'), // msgLeafIndexOffset + ...Buffer.from('CDEF', 'hex'), // existsOffset ]); const inst = new L1ToL2MessageExists( /*indirect=*/ 0x01, - /*msgHashOffset=*/ 0x12345678, - /*msgLeafIndexOffset=*/ 0x456789ab, - /*existsOffset=*/ 0xcdef0123, + /*msgHashOffset=*/ 0x1234, + /*msgLeafIndexOffset=*/ 0x4567, + /*existsOffset=*/ 0xcdef, ); expect(L1ToL2MessageExists.deserialize(buf)).toEqual(inst); @@ -306,10 +306,10 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ EmitUnencryptedLog.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // log offset - ...Buffer.from('a2345678', 'hex'), // length offset + ...Buffer.from('1234', 'hex'), // log offset + ...Buffer.from('a234', 'hex'), // length offset ]); - const inst = new EmitUnencryptedLog(/*indirect=*/ 0x01, /*offset=*/ 0x12345678, /*lengthOffset=*/ 0xa2345678); + const inst = new EmitUnencryptedLog(/*indirect=*/ 0x01, /*offset=*/ 0x1234, /*lengthOffset=*/ 0xa234); expect(EmitUnencryptedLog.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); @@ -338,14 +338,10 @@ describe('Accrued Substate', () => { const buf = Buffer.from([ SendL2ToL1Message.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // recipientOffset - ...Buffer.from('a2345678', 'hex'), // contentOffset + ...Buffer.from('1234', 'hex'), // recipientOffset + ...Buffer.from('a234', 'hex'), // contentOffset ]); - const inst = new SendL2ToL1Message( - /*indirect=*/ 0x01, - /*recipientOffset=*/ 0x12345678, - /*contentOffset=*/ 0xa2345678, - ); + const inst = new SendL2ToL1Message(/*indirect=*/ 0x01, /*recipientOffset=*/ 0x1234, /*contentOffset=*/ 0xa234); expect(SendL2ToL1Message.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts index 126bc1ad8af..a1bfe0a63c4 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts @@ -13,9 +13,9 @@ export class NoteHashExists extends Instruction { static readonly wireFormat = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( @@ -55,7 +55,7 @@ export class EmitNoteHash extends Instruction { static type: string = 'EMITNOTEHASH'; static readonly opcode: Opcode = Opcode.EMITNOTEHASH; // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32]; + static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16]; constructor(private indirect: number, private noteHashOffset: number) { super(); @@ -89,9 +89,9 @@ export class NullifierExists extends Instruction { static readonly wireFormat = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( @@ -127,7 +127,7 @@ export class EmitNullifier extends Instruction { static type: string = 'EMITNULLIFIER'; static readonly opcode: Opcode = Opcode.EMITNULLIFIER; // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32]; + static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16]; constructor(private indirect: number, private nullifierOffset: number) { super(); @@ -172,9 +172,9 @@ export class L1ToL2MessageExists extends Instruction { static readonly wireFormat = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( @@ -213,7 +213,7 @@ export class EmitUnencryptedLog extends Instruction { static type: string = 'EMITUNENCRYPTEDLOG'; static readonly opcode: Opcode = Opcode.EMITUNENCRYPTEDLOG; // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32, OperandType.UINT32]; + static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16]; constructor(private indirect: number, private logOffset: number, private logSizeOffset: number) { super(); @@ -248,7 +248,7 @@ export class SendL2ToL1Message extends Instruction { static type: string = 'SENDL2TOL1MSG'; static readonly opcode: Opcode = Opcode.SENDL2TOL1MSG; // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32, OperandType.UINT32]; + static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16]; constructor(private indirect: number, private recipientOffset: number, private contentOffset: number) { super(); diff --git a/yarn-project/simulator/src/avm/opcodes/control_flow.test.ts b/yarn-project/simulator/src/avm/opcodes/control_flow.test.ts index 6c4996a488e..0dac3c087a8 100644 --- a/yarn-project/simulator/src/avm/opcodes/control_flow.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/control_flow.test.ts @@ -84,9 +84,9 @@ describe('Control Flow Opcodes', () => { it('INTERNALCALL Should (de)serialize correctly', () => { const buf = Buffer.from([ InternalCall.opcode, // opcode - ...Buffer.from('12345678', 'hex'), // loc + ...Buffer.from('1234', 'hex'), // loc ]); - const inst = new InternalCall(/*loc=*/ 0x12345678); + const inst = new InternalCall(/*loc=*/ 0x1234); expect(InternalCall.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); diff --git a/yarn-project/simulator/src/avm/opcodes/control_flow.ts b/yarn-project/simulator/src/avm/opcodes/control_flow.ts index 9109682a6a5..a83af756468 100644 --- a/yarn-project/simulator/src/avm/opcodes/control_flow.ts +++ b/yarn-project/simulator/src/avm/opcodes/control_flow.ts @@ -63,7 +63,7 @@ export class InternalCall extends Instruction { static readonly type: string = 'INTERNALCALL'; static readonly opcode: Opcode = Opcode.INTERNALCALL; // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT32]; + static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT16]; constructor(private loc: number) { super(); diff --git a/yarn-project/simulator/src/avm/opcodes/conversion.test.ts b/yarn-project/simulator/src/avm/opcodes/conversion.test.ts index 4903af1992c..b211848780d 100644 --- a/yarn-project/simulator/src/avm/opcodes/conversion.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/conversion.test.ts @@ -16,17 +16,17 @@ describe('Conversion Opcodes', () => { const buf = Buffer.from([ ToRadixLE.opcode, // opcode 1, // indirect - ...Buffer.from('12345678', 'hex'), // inputStateOffset - ...Buffer.from('23456789', 'hex'), // outputStateOffset - ...Buffer.from('3456789A', 'hex'), // radixOffset - ...Buffer.from('00000100', 'hex'), // numLimbs + ...Buffer.from('1234', 'hex'), // inputStateOffset + ...Buffer.from('2345', 'hex'), // outputStateOffset + ...Buffer.from('3456', 'hex'), // radixOffset + ...Buffer.from('0100', 'hex'), // numLimbs ...Buffer.from('01', 'hex'), // outputBits ]); const inst = new ToRadixLE( /*indirect=*/ 1, - /*srcOffset=*/ 0x12345678, - /*dstOffset=*/ 0x23456789, - /*radixOffset=*/ 0x3456789a, + /*srcOffset=*/ 0x1234, + /*dstOffset=*/ 0x2345, + /*radixOffset=*/ 0x3456, /*numLimbs=*/ 256, /*outputBits=*/ 1, ); diff --git a/yarn-project/simulator/src/avm/opcodes/conversion.ts b/yarn-project/simulator/src/avm/opcodes/conversion.ts index 4d3f245e6f1..a9713f96566 100644 --- a/yarn-project/simulator/src/avm/opcodes/conversion.ts +++ b/yarn-project/simulator/src/avm/opcodes/conversion.ts @@ -13,10 +13,10 @@ export class ToRadixLE extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, // Opcode OperandType.UINT8, // Indirect - OperandType.UINT32, // src memory address - OperandType.UINT32, // dst memory address - OperandType.UINT32, // radix memory address - OperandType.UINT32, // number of limbs (Immediate) + OperandType.UINT16, // src memory address + OperandType.UINT16, // dst memory address + OperandType.UINT16, // radix memory address + OperandType.UINT16, // number of limbs (Immediate) OperandType.UINT8, // output is in "bits" mode (Immediate - Uint1 still takes up a whole byte) ]; diff --git a/yarn-project/simulator/src/avm/opcodes/ec_add.test.ts b/yarn-project/simulator/src/avm/opcodes/ec_add.test.ts index 08db9b9b0ab..46629398e38 100644 --- a/yarn-project/simulator/src/avm/opcodes/ec_add.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/ec_add.test.ts @@ -21,23 +21,23 @@ describe('EC Instructions', () => { const buf = Buffer.from([ EcAdd.opcode, // opcode ...Buffer.from('1234', 'hex'), // indirect - ...Buffer.from('12345670', 'hex'), // p1x - ...Buffer.from('12345671', 'hex'), // p1y - ...Buffer.from('00000000', 'hex'), // p1IsInfinite - ...Buffer.from('12345672', 'hex'), // p2x - ...Buffer.from('12345673', 'hex'), // p2y - ...Buffer.from('00000001', 'hex'), // p2IsInfinite - ...Buffer.from('12345674', 'hex'), // dstOffset + ...Buffer.from('1235', 'hex'), // p1x + ...Buffer.from('1236', 'hex'), // p1y + ...Buffer.from('0000', 'hex'), // p1IsInfinite + ...Buffer.from('1237', 'hex'), // p2x + ...Buffer.from('1238', 'hex'), // p2y + ...Buffer.from('0001', 'hex'), // p2IsInfinite + ...Buffer.from('1239', 'hex'), // dstOffset ]); const inst = new EcAdd( /*indirect=*/ 0x1234, - /*p1X=*/ 0x12345670, - /*p1Y=*/ 0x12345671, + /*p1X=*/ 0x1235, + /*p1Y=*/ 0x1236, /*p1IsInfinite=*/ 0, - /*p2X=*/ 0x12345672, - /*p2Y=*/ 0x12345673, + /*p2X=*/ 0x1237, + /*p2Y=*/ 0x1238, /*p2IsInfinite=*/ 1, - /*dstOffset=*/ 0x12345674, + /*dstOffset=*/ 0x1239, ); expect(EcAdd.deserialize(buf)).toEqual(inst); diff --git a/yarn-project/simulator/src/avm/opcodes/ec_add.ts b/yarn-project/simulator/src/avm/opcodes/ec_add.ts index 3cadc46f494..5f17b690a3c 100644 --- a/yarn-project/simulator/src/avm/opcodes/ec_add.ts +++ b/yarn-project/simulator/src/avm/opcodes/ec_add.ts @@ -15,13 +15,13 @@ export class EcAdd extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, // reserved OperandType.UINT16, // indirect - OperandType.UINT32, // p1X - OperandType.UINT32, // p1Y - OperandType.UINT32, // p1IsInfinite - OperandType.UINT32, // p2X - OperandType.UINT32, // p2Y - OperandType.UINT32, // p2IsInfinite - OperandType.UINT32, // dst + OperandType.UINT16, // p1X + OperandType.UINT16, // p1Y + OperandType.UINT16, // p1IsInfinite + OperandType.UINT16, // p2X + OperandType.UINT16, // p2Y + OperandType.UINT16, // p2IsInfinite + OperandType.UINT16, // dst ]; constructor( diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts index 2eab686c3ff..0f74ab3a6eb 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts @@ -37,25 +37,25 @@ describe('External Calls', () => { const buf = Buffer.from([ Call.opcode, // opcode ...Buffer.from('1234', 'hex'), // indirect (16 bit) - ...Buffer.from('12345678', 'hex'), // gasOffset - ...Buffer.from('a2345678', 'hex'), // addrOffset - ...Buffer.from('b2345678', 'hex'), // argsOffset - ...Buffer.from('c2345678', 'hex'), // argsSizeOffset - ...Buffer.from('d2345678', 'hex'), // retOffset - ...Buffer.from('e2345678', 'hex'), // retSize - ...Buffer.from('f2345678', 'hex'), // successOffset - ...Buffer.from('f3345678', 'hex'), // functionSelectorOffset + ...Buffer.from('1234', 'hex'), // gasOffset + ...Buffer.from('a234', 'hex'), // addrOffset + ...Buffer.from('b234', 'hex'), // argsOffset + ...Buffer.from('c234', 'hex'), // argsSizeOffset + ...Buffer.from('d234', 'hex'), // retOffset + ...Buffer.from('e234', 'hex'), // retSize + ...Buffer.from('f234', 'hex'), // successOffset + ...Buffer.from('f334', 'hex'), // functionSelectorOffset ]); const inst = new Call( /*indirect=*/ 0x1234, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSizeOffset=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSizeOffset=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ); expect(Call.deserialize(buf)).toEqual(inst); @@ -186,25 +186,25 @@ describe('External Calls', () => { const buf = Buffer.from([ StaticCall.opcode, // opcode ...Buffer.from('1234', 'hex'), // indirect (16 bit) - ...Buffer.from('12345678', 'hex'), // gasOffset - ...Buffer.from('a2345678', 'hex'), // addrOffset - ...Buffer.from('b2345678', 'hex'), // argsOffset - ...Buffer.from('c2345678', 'hex'), // argsSizeOffset - ...Buffer.from('d2345678', 'hex'), // retOffset - ...Buffer.from('e2345678', 'hex'), // retSize - ...Buffer.from('f2345678', 'hex'), // successOffset - ...Buffer.from('f3345678', 'hex'), // functionSelectorOffset + ...Buffer.from('1234', 'hex'), // gasOffset + ...Buffer.from('a234', 'hex'), // addrOffset + ...Buffer.from('b234', 'hex'), // argsOffset + ...Buffer.from('c234', 'hex'), // argsSizeOffset + ...Buffer.from('d234', 'hex'), // retOffset + ...Buffer.from('e234', 'hex'), // retSize + ...Buffer.from('f234', 'hex'), // successOffset + ...Buffer.from('f334', 'hex'), // functionSelectorOffset ]); const inst = new StaticCall( /*indirect=*/ 0x1234, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSizeOffset=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSizeOffset=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ); expect(StaticCall.deserialize(buf)).toEqual(inst); @@ -259,10 +259,10 @@ describe('External Calls', () => { const buf = Buffer.from([ Return.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // returnOffset - ...Buffer.from('a2345678', 'hex'), // copySize + ...Buffer.from('1234', 'hex'), // returnOffset + ...Buffer.from('a234', 'hex'), // copySize ]); - const inst = new Return(/*indirect=*/ 0x01, /*returnOffset=*/ 0x12345678, /*copySize=*/ 0xa2345678); + const inst = new Return(/*indirect=*/ 0x01, /*returnOffset=*/ 0x1234, /*copySize=*/ 0xa234); expect(Return.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index ebf1ee62f78..2507885f2e0 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -16,14 +16,14 @@ abstract class ExternalCall extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT16, // Indirect - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( @@ -164,8 +164,8 @@ export class Return extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, ]; constructor(private indirect: number, private returnOffset: number, private copySize: number) { diff --git a/yarn-project/simulator/src/avm/opcodes/hashing.test.ts b/yarn-project/simulator/src/avm/opcodes/hashing.test.ts index 6c864e2ae20..ddca0874f6f 100644 --- a/yarn-project/simulator/src/avm/opcodes/hashing.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/hashing.test.ts @@ -18,10 +18,10 @@ describe('Hashing Opcodes', () => { const buf = Buffer.from([ Poseidon2.opcode, // opcode 1, // indirect - ...Buffer.from('12345678', 'hex'), // inputStateOffset - ...Buffer.from('23456789', 'hex'), // outputStateOffset + ...Buffer.from('1234', 'hex'), // inputStateOffset + ...Buffer.from('2345', 'hex'), // outputStateOffset ]); - const inst = new Poseidon2(/*indirect=*/ 1, /*dstOffset=*/ 0x12345678, /*messageOffset=*/ 0x23456789); + const inst = new Poseidon2(/*indirect=*/ 1, /*dstOffset=*/ 0x1234, /*messageOffset=*/ 0x2345); expect(Poseidon2.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); @@ -141,15 +141,15 @@ describe('Hashing Opcodes', () => { const buf = Buffer.from([ KeccakF1600.opcode, // opcode 1, // indirect - ...Buffer.from('12345678', 'hex'), // dstOffset - ...Buffer.from('23456789', 'hex'), // messageOffset - ...Buffer.from('3456789a', 'hex'), // messageSizeOffset + ...Buffer.from('1234', 'hex'), // dstOffset + ...Buffer.from('2345', 'hex'), // messageOffset + ...Buffer.from('3456', 'hex'), // messageSizeOffset ]); const inst = new KeccakF1600( /*indirect=*/ 1, - /*dstOffset=*/ 0x12345678, - /*messageOffset=*/ 0x23456789, - /*messageSizeOffset=*/ 0x3456789a, + /*dstOffset=*/ 0x1234, + /*messageOffset=*/ 0x2345, + /*messageSizeOffset=*/ 0x3456, ); expect(KeccakF1600.deserialize(buf)).toEqual(inst); @@ -178,15 +178,15 @@ describe('Hashing Opcodes', () => { const buf = Buffer.from([ Sha256Compression.opcode, // opcode 1, // indirect - ...Buffer.from('12345678', 'hex'), // dstOffset - ...Buffer.from('23456789', 'hex'), // stateOffset - ...Buffer.from('456789ab', 'hex'), // inputsOffset + ...Buffer.from('1234', 'hex'), // dstOffset + ...Buffer.from('2345', 'hex'), // stateOffset + ...Buffer.from('4567', 'hex'), // inputsOffset ]); const inst = new Sha256Compression( /*indirect=*/ 1, - /*dstOffset=*/ 0x12345678, - /*stateOffset=*/ 0x23456789, - /*inputsOffset=*/ 0x456789ab, + /*dstOffset=*/ 0x1234, + /*stateOffset=*/ 0x2345, + /*inputsOffset=*/ 0x4567, ); expect(Sha256Compression.deserialize(buf)).toEqual(inst); diff --git a/yarn-project/simulator/src/avm/opcodes/hashing.ts b/yarn-project/simulator/src/avm/opcodes/hashing.ts index 04a5001c0f2..a055d0a135e 100644 --- a/yarn-project/simulator/src/avm/opcodes/hashing.ts +++ b/yarn-project/simulator/src/avm/opcodes/hashing.ts @@ -23,8 +23,8 @@ export class Poseidon2 extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, ]; constructor(private indirect: number, private inputStateOffset: number, private outputStateOffset: number) { @@ -106,9 +106,9 @@ export class KeccakF1600 extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( @@ -153,9 +153,9 @@ export class Sha256Compression extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( diff --git a/yarn-project/simulator/src/avm/opcodes/memory.test.ts b/yarn-project/simulator/src/avm/opcodes/memory.test.ts index 9820fb84911..f96d3f3f134 100644 --- a/yarn-project/simulator/src/avm/opcodes/memory.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/memory.test.ts @@ -369,15 +369,15 @@ describe('Memory instructions', () => { const buf = Buffer.from([ CalldataCopy.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // cdOffsetAddress - ...Buffer.from('23456789', 'hex'), // copysizeOffset - ...Buffer.from('3456789a', 'hex'), // dstOffset + ...Buffer.from('1234', 'hex'), // cdOffsetAddress + ...Buffer.from('2345', 'hex'), // copysizeOffset + ...Buffer.from('3456', 'hex'), // dstOffset ]); const inst = new CalldataCopy( /*indirect=*/ 0x01, - /*cdOffsetAddress=*/ 0x12345678, - /*copysizeOffset=*/ 0x23456789, - /*dstOffset=*/ 0x3456789a, + /*cdOffsetAddress=*/ 0x1234, + /*copysizeOffset=*/ 0x2345, + /*dstOffset=*/ 0x3456, ); expect(CalldataCopy.deserialize(buf)).toEqual(inst); diff --git a/yarn-project/simulator/src/avm/opcodes/memory.ts b/yarn-project/simulator/src/avm/opcodes/memory.ts index 7a82db76bce..2ba943e2210 100644 --- a/yarn-project/simulator/src/avm/opcodes/memory.ts +++ b/yarn-project/simulator/src/avm/opcodes/memory.ts @@ -163,9 +163,9 @@ export class CalldataCopy extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, + OperandType.UINT16, ]; constructor( diff --git a/yarn-project/simulator/src/avm/opcodes/misc.ts b/yarn-project/simulator/src/avm/opcodes/misc.ts index 219145778d7..11bfe55234d 100644 --- a/yarn-project/simulator/src/avm/opcodes/misc.ts +++ b/yarn-project/simulator/src/avm/opcodes/misc.ts @@ -15,10 +15,10 @@ export class DebugLog extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8, // Opcode OperandType.UINT8, // Indirect - OperandType.UINT32, // message memory address - OperandType.UINT32, // message size - OperandType.UINT32, // fields memory address - OperandType.UINT32, // fields size address + OperandType.UINT16, // message memory address + OperandType.UINT16, // message size + OperandType.UINT16, // fields memory address + OperandType.UINT16, // fields size address ]; constructor( diff --git a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts index 098a0dcd889..5af0702b10c 100644 --- a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts @@ -16,17 +16,17 @@ describe('MultiScalarMul Opcode', () => { const buf = Buffer.from([ MultiScalarMul.opcode, // opcode 7, // indirect - ...Buffer.from('12345678', 'hex'), // pointsOffset - ...Buffer.from('23456789', 'hex'), // scalars Offset - ...Buffer.from('3456789a', 'hex'), // outputOffset - ...Buffer.from('456789ab', 'hex'), // pointsLengthOffset + ...Buffer.from('1234', 'hex'), // pointsOffset + ...Buffer.from('2345', 'hex'), // scalars Offset + ...Buffer.from('3456', 'hex'), // outputOffset + ...Buffer.from('4567', 'hex'), // pointsLengthOffset ]); const inst = new MultiScalarMul( /*indirect=*/ 7, - /*pointsOffset=*/ 0x12345678, - /*scalarsOffset=*/ 0x23456789, - /*outputOffset=*/ 0x3456789a, - /*pointsLengthOffset=*/ 0x456789ab, + /*pointsOffset=*/ 0x1234, + /*scalarsOffset=*/ 0x2345, + /*outputOffset=*/ 0x3456, + /*pointsLengthOffset=*/ 0x4567, ); expect(MultiScalarMul.deserialize(buf)).toEqual(inst); diff --git a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts index fb3888282f5..26b3686818a 100644 --- a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts +++ b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts @@ -16,10 +16,10 @@ export class MultiScalarMul extends Instruction { static readonly wireFormat: OperandType[] = [ OperandType.UINT8 /* opcode */, OperandType.UINT8 /* indirect */, - OperandType.UINT32 /* points vector offset */, - OperandType.UINT32 /* scalars vector offset */, - OperandType.UINT32 /* output offset (fixed triplet) */, - OperandType.UINT32 /* points length offset */, + OperandType.UINT16 /* points vector offset */, + OperandType.UINT16 /* scalars vector offset */, + OperandType.UINT16 /* output offset (fixed triplet) */, + OperandType.UINT16 /* points length offset */, ]; constructor( diff --git a/yarn-project/simulator/src/avm/opcodes/storage.test.ts b/yarn-project/simulator/src/avm/opcodes/storage.test.ts index fd8cc1e484e..74e55a51d9c 100644 --- a/yarn-project/simulator/src/avm/opcodes/storage.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/storage.test.ts @@ -28,10 +28,10 @@ describe('Storage Instructions', () => { const buf = Buffer.from([ SStore.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // srcOffset - ...Buffer.from('3456789a', 'hex'), // slotOffset + ...Buffer.from('1234', 'hex'), // srcOffset + ...Buffer.from('3456', 'hex'), // slotOffset ]); - const inst = new SStore(/*indirect=*/ 0x01, /*srcOffset=*/ 0x12345678, /*slotOffset=*/ 0x3456789a); + const inst = new SStore(/*indirect=*/ 0x01, /*srcOffset=*/ 0x1234, /*slotOffset=*/ 0x3456); expect(SStore.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); @@ -71,10 +71,10 @@ describe('Storage Instructions', () => { const buf = Buffer.from([ SLoad.opcode, // opcode 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // slotOffset - ...Buffer.from('3456789a', 'hex'), // dstOffset + ...Buffer.from('1234', 'hex'), // slotOffset + ...Buffer.from('3456', 'hex'), // dstOffset ]); - const inst = new SLoad(/*indirect=*/ 0x01, /*slotOffset=*/ 0x12345678, /*dstOffset=*/ 0x3456789a); + const inst = new SLoad(/*indirect=*/ 0x01, /*slotOffset=*/ 0x1234, /*dstOffset=*/ 0x3456); expect(SLoad.deserialize(buf)).toEqual(inst); expect(inst.serialize()).toEqual(buf); diff --git a/yarn-project/simulator/src/avm/opcodes/storage.ts b/yarn-project/simulator/src/avm/opcodes/storage.ts index 4da3a619ab9..8639d3dd818 100644 --- a/yarn-project/simulator/src/avm/opcodes/storage.ts +++ b/yarn-project/simulator/src/avm/opcodes/storage.ts @@ -10,8 +10,8 @@ abstract class BaseStorageInstruction extends Instruction { public static readonly wireFormat: OperandType[] = [ OperandType.UINT8, OperandType.UINT8, - OperandType.UINT32, - OperandType.UINT32, + OperandType.UINT16, + OperandType.UINT16, ]; constructor(protected indirect: number, protected aOffset: number, protected bOffset: number) { diff --git a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts index ccc5fa2f951..43871014a0f 100644 --- a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts +++ b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts @@ -86,25 +86,25 @@ describe('Bytecode Serialization', () => { ), new Call( /*indirect=*/ 0x01, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSize=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSize=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ), new StaticCall( /*indirect=*/ 0x01, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSize=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSize=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ), ]; const bytecode = Buffer.concat(instructions.map(i => i.serialize())); @@ -130,25 +130,25 @@ describe('Bytecode Serialization', () => { ), new Call( /*indirect=*/ 0x01, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSize=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSize=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ), new StaticCall( /*indirect=*/ 0x01, - /*gasOffset=*/ 0x12345678, - /*addrOffset=*/ 0xa2345678, - /*argsOffset=*/ 0xb2345678, - /*argsSize=*/ 0xc2345678, - /*retOffset=*/ 0xd2345678, - /*retSize=*/ 0xe2345678, - /*successOffset=*/ 0xf2345678, - /*functionSelectorOffset=*/ 0xf3345678, + /*gasOffset=*/ 0x1234, + /*addrOffset=*/ 0xa234, + /*argsOffset=*/ 0xb234, + /*argsSize=*/ 0xc234, + /*retOffset=*/ 0xd234, + /*retSize=*/ 0xe234, + /*successOffset=*/ 0xf234, + /*functionSelectorOffset=*/ 0xf334, ), ];