From 9f5b11345dc5dd055442eaf7673227fe7cbaf262 Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:03:47 +0200 Subject: [PATCH] test(avm): Modify unit test to have a calldatacopy over 4 elements (#6893) --- .../vm/tests/avm_execution.test.cpp | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index c6c32a21f1a..3dc4d4081d2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -1008,51 +1008,45 @@ TEST_F(AvmExecutionTests, sha256Opcode) // Positive test with POSEIDON2_PERM. TEST_F(AvmExecutionTests, poseidon2PermutationOpCode) { - // Test vectors taken from barretenberg/permutation/test std::vector calldata{ FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")), FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")), FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")), FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")) }; - std::string bytecode_hex = to_hex(OpCode::CALLDATACOPY) + // opcode CALL DATA COPY - "00" // Indirect Flag - "00000000" // cd_offset - "00000003" // copy_size - "00000001" // dst_offset 1 - + to_hex(OpCode::CALLDATACOPY) + // opcode CALL DATA COPY (for 4th input) - "00" // Indirect Flag - "00000003" // cd_offset - "00000001" // copy_size - "00000004" + // dst_offset 4 - to_hex(OpCode::SET) + // opcode SET for indirect src (input) - "00" // Indirect flag - "03" // U32 - "00000001" // value 1 (i.e. where the src will be read from) - "00000024" // dst_offset 36 - + to_hex(OpCode::SET) + // opcode SET for indirect dst (output) - "00" // Indirect flag - "03" // U32 - "00000009" // value 9 (i.e. where the ouput will be written to) - "00000023" // 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) - + to_hex(OpCode::RETURN) + // opcode RETURN - "00" // Indirect flag - "00000009" // ret offset 256 - "00000004"; // ret size 8 + std::string bytecode_hex = to_hex(OpCode::CALLDATACOPY) + // opcode CALL DATA COPY + "00" // Indirect Flag + "00000000" // cd_offset + "00000004" // copy_size + "00000001" // dst_offset 1 + + to_hex(OpCode::SET) + // opcode SET for indirect src (input) + "00" // Indirect flag + "03" // U32 + "00000001" // value 1 (i.e. where the src will be read from) + "00000024" // dst_offset 36 + + to_hex(OpCode::SET) + // opcode SET for indirect dst (output) + "00" // Indirect flag + "03" // U32 + "00000009" // value 9 (i.e. where the ouput will be written to) + "00000023" // 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) + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "00000009" // ret offset 256 + "00000004"; // ret size 8 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); - // 2 CALLDATACOPY for input + 2 SET for setting up indirects + 1 POSEIDON2 + 1 RETURN - ASSERT_THAT(instructions, SizeIs(6)); + // 1 CALLDATACOPY for input + 2 SET for setting up indirects + 1 POSEIDON2 + 1 RETURN + ASSERT_THAT(instructions, SizeIs(5)); // POSEIDON2_PERM EXPECT_THAT( - instructions.at(4), + instructions.at(3), AllOf(Field(&Instruction::op_code, OpCode::POSEIDON2), Field(&Instruction::operands, ElementsAre(VariantWith(3), VariantWith(36), VariantWith(35)))));