Skip to content

Commit

Permalink
test(avm): Modify unit test to have a calldatacopy over 4 elements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon authored Jun 5, 2024
1 parent 6c98529 commit 9f5b113
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FF> 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<uint8_t>(3), VariantWith<uint32_t>(36), VariantWith<uint32_t>(35)))));
Expand Down

0 comments on commit 9f5b113

Please sign in to comment.