Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(avm): Modify unit test to have a calldatacopy over 4 elements #6893

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading