1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
16using ::testing::SizeIs;
18TEST(AvmInputsTest, Deserialization)
21 auto data =
read_file(
"../src/barretenberg/vm2/testing/avm_inputs.testdata.bin");
30TEST(AvmInputsTest, FormatTransformations)
32 using ::testing::AllOf;
33 using ::testing::ElementsAre;
36 auto as_cols = pi.to_columns();
46 EXPECT_EQ(as_cols, unflattened);
49TEST(AvmInputsTest, ValuesInColumns)
55 pi.globalVariables.chainId = 123;
56 pi.globalVariables.version = 456;
57 pi.globalVariables.blockNumber = 12345;
58 pi.globalVariables.slotNumber = 67890;
59 pi.globalVariables.timestamp = 789000;
60 pi.globalVariables.coinbase = 123123;
61 pi.globalVariables.feeRecipient = 9876;
64 pi.globalVariables.gasFees.feePerDaGas = 111;
65 pi.globalVariables.gasFees.feePerL2Gas = 222;
68 pi.startTreeSnapshots.l1ToL2MessageTree.root = 1000;
69 pi.startTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex = 2000;
70 pi.startTreeSnapshots.noteHashTree.root = 3000;
71 pi.startTreeSnapshots.noteHashTree.nextAvailableLeafIndex = 4000;
72 pi.startTreeSnapshots.nullifierTree.root = 5000;
73 pi.startTreeSnapshots.nullifierTree.nextAvailableLeafIndex = 6000;
74 pi.startTreeSnapshots.publicDataTree.root = 7000;
75 pi.startTreeSnapshots.publicDataTree.nextAvailableLeafIndex = 8000;
78 pi.startGasUsed.daGas = 100;
79 pi.startGasUsed.l2Gas = 200;
82 pi.gasSettings.gasLimits.daGas = 1234;
83 pi.gasSettings.gasLimits.l2Gas = 5678;
84 pi.gasSettings.teardownGasLimits.daGas = 9012;
85 pi.gasSettings.teardownGasLimits.l2Gas = 3456;
86 pi.gasSettings.maxFeesPerGas.feePerDaGas = 7890;
87 pi.gasSettings.maxFeesPerGas.feePerL2Gas = 1234;
88 pi.gasSettings.maxPriorityFeesPerGas.feePerDaGas = 5678;
89 pi.gasSettings.maxPriorityFeesPerGas.feePerL2Gas = 9012;
95 pi.publicCallRequestArrayLengths.setupCalls = 2;
96 pi.publicCallRequestArrayLengths.appLogicCalls = 3;
97 pi.publicCallRequestArrayLengths.teardownCall =
true;
100 pi.publicSetupCallRequests[0].msgSender = 1111;
101 pi.publicSetupCallRequests[0].contractAddress = 2222;
102 pi.publicSetupCallRequests[0].isStaticCall =
true;
103 pi.publicSetupCallRequests[0].calldataHash = 3333;
105 pi.publicAppLogicCallRequests[1].msgSender = 4444;
106 pi.publicAppLogicCallRequests[1].contractAddress = 5555;
107 pi.publicAppLogicCallRequests[1].isStaticCall =
false;
108 pi.publicAppLogicCallRequests[1].calldataHash = 6666;
110 pi.publicTeardownCallRequest.msgSender = 7777;
111 pi.publicTeardownCallRequest.contractAddress = 8888;
112 pi.publicTeardownCallRequest.isStaticCall =
true;
113 pi.publicTeardownCallRequest.calldataHash = 9999;
116 pi.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes = 10;
117 pi.previousNonRevertibleAccumulatedDataArrayLengths.nullifiers = 20;
118 pi.previousNonRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs = 30;
120 pi.previousRevertibleAccumulatedDataArrayLengths.noteHashes = 40;
121 pi.previousRevertibleAccumulatedDataArrayLengths.nullifiers = 50;
122 pi.previousRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs = 60;
125 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.recipient = 1234;
126 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.content = 1357;
127 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].contractAddress = 3579;
130 pi.accumulatedData.noteHashes[2] = 54321;
131 pi.accumulatedData.nullifiers[3] = 98765;
134 pi.accumulatedData.l2ToL1Msgs[1].message.recipient = 3333;
135 pi.accumulatedData.l2ToL1Msgs[1].message.content = 7531;
136 pi.accumulatedData.l2ToL1Msgs[1].contractAddress = 9753;
139 std::vector<FF> public_log_fields;
140 public_log_fields.reserve(3);
141 for (
size_t j = 0; j < 3; ++j) {
142 public_log_fields.push_back(10000 + j);
144 pi.accumulatedData.publicLogs.add_log({
145 .fields = public_log_fields,
146 .contractAddress = 11223,
150 pi.accumulatedData.publicDataWrites[1].leafSlot = 5555;
151 pi.accumulatedData.publicDataWrites[1].value = 6666;
154 pi.endGasUsed.daGas = 5000;
155 pi.endGasUsed.l2Gas = 7000;
158 pi.endTreeSnapshots.l1ToL2MessageTree.root = 10000;
159 pi.endTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex = 20000;
160 pi.endTreeSnapshots.noteHashTree.root = 30000;
161 pi.endTreeSnapshots.noteHashTree.nextAvailableLeafIndex = 40000;
162 pi.endTreeSnapshots.nullifierTree.root = 50000;
163 pi.endTreeSnapshots.nullifierTree.nextAvailableLeafIndex = 60000;
164 pi.endTreeSnapshots.publicDataTree.root = 70000;
165 pi.endTreeSnapshots.publicDataTree.nextAvailableLeafIndex = 80000;
168 pi.transactionFee = 9876;
171 pi.accumulatedDataArrayLengths.noteHashes = 3;
172 pi.accumulatedDataArrayLengths.nullifiers = 4;
173 pi.accumulatedDataArrayLengths.l2ToL1Msgs = 2;
174 pi.accumulatedDataArrayLengths.publicDataWrites = 5;
180 auto columns = pi.to_columns();
187 const size_t col0_offset = 0;
198 pi.globalVariables.blockNumber);
200 pi.globalVariables.slotNumber);
203 pi.globalVariables.feeRecipient);
205 pi.globalVariables.gasFees.feePerDaGas);
207 pi.globalVariables.gasFees.feePerL2Gas);
212 pi.startTreeSnapshots.l1ToL2MessageTree.root);
214 pi.startTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex);
216 pi.startTreeSnapshots.noteHashTree.root);
218 pi.startTreeSnapshots.noteHashTree.nextAvailableLeafIndex);
220 pi.startTreeSnapshots.nullifierTree.root);
222 pi.startTreeSnapshots.nullifierTree.nextAvailableLeafIndex);
224 pi.startTreeSnapshots.publicDataTree.root);
226 pi.startTreeSnapshots.publicDataTree.nextAvailableLeafIndex);
236 pi.gasSettings.teardownGasLimits.daGas);
238 pi.gasSettings.teardownGasLimits.l2Gas);
240 pi.gasSettings.maxFeesPerGas.feePerDaGas);
242 pi.gasSettings.maxFeesPerGas.feePerL2Gas);
244 pi.gasSettings.maxPriorityFeesPerGas.feePerDaGas);
246 pi.gasSettings.maxPriorityFeesPerGas.feePerL2Gas);
253 pi.publicCallRequestArrayLengths.setupCalls);
255 pi.publicCallRequestArrayLengths.appLogicCalls);
257 static_cast<uint8_t
>(pi.publicCallRequestArrayLengths.teardownCall));
261 EXPECT_EQ(flat[col0_offset + setup_row], pi.publicSetupCallRequests[0].msgSender);
262 EXPECT_EQ(flat[col1_offset + setup_row], pi.publicSetupCallRequests[0].contractAddress);
263 EXPECT_EQ(flat[col2_offset + setup_row],
static_cast<uint8_t
>(pi.publicSetupCallRequests[0].isStaticCall));
264 EXPECT_EQ(flat[col3_offset + setup_row], pi.publicSetupCallRequests[0].calldataHash);
267 EXPECT_EQ(flat[col0_offset + app_logic_row], pi.publicAppLogicCallRequests[1].msgSender);
268 EXPECT_EQ(flat[col1_offset + app_logic_row], pi.publicAppLogicCallRequests[1].contractAddress);
269 EXPECT_EQ(flat[col2_offset + app_logic_row],
static_cast<uint8_t
>(pi.publicAppLogicCallRequests[1].isStaticCall));
270 EXPECT_EQ(flat[col3_offset + app_logic_row], pi.publicAppLogicCallRequests[1].calldataHash);
273 EXPECT_EQ(flat[col0_offset + teardown_row], pi.publicTeardownCallRequest.msgSender);
274 EXPECT_EQ(flat[col1_offset + teardown_row], pi.publicTeardownCallRequest.contractAddress);
275 EXPECT_EQ(flat[col2_offset + teardown_row],
static_cast<uint8_t
>(pi.publicTeardownCallRequest.isStaticCall));
276 EXPECT_EQ(flat[col3_offset + teardown_row], pi.publicTeardownCallRequest.calldataHash);
279 EXPECT_EQ(flat[col0_offset +
281 pi.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes);
284 pi.previousNonRevertibleAccumulatedDataArrayLengths.nullifiers);
285 EXPECT_EQ(flat[col0_offset +
287 pi.previousNonRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs);
292 pi.previousRevertibleAccumulatedDataArrayLengths.noteHashes);
295 pi.previousRevertibleAccumulatedDataArrayLengths.nullifiers);
298 pi.previousRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs);
302 pi.accumulatedDataArrayLengths.noteHashes);
304 pi.accumulatedDataArrayLengths.nullifiers);
306 pi.accumulatedDataArrayLengths.l2ToL1Msgs);
308 pi.accumulatedDataArrayLengths.publicDataWrites);
312 EXPECT_EQ(flat[col0_offset + l2_to_l1_msg_row],
313 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.recipient);
314 EXPECT_EQ(flat[col1_offset + l2_to_l1_msg_row],
315 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.content);
316 EXPECT_EQ(flat[col2_offset + l2_to_l1_msg_row],
317 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].contractAddress);
321 pi.endTreeSnapshots.l1ToL2MessageTree.root);
323 pi.endTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex);
325 pi.endTreeSnapshots.noteHashTree.root);
327 pi.endTreeSnapshots.noteHashTree.nextAvailableLeafIndex);
335 pi.accumulatedData.noteHashes[2]);
337 pi.accumulatedData.nullifiers[3]);
341 EXPECT_EQ(flat[col0_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].message.recipient);
342 EXPECT_EQ(flat[col1_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].message.content);
343 EXPECT_EQ(flat[col2_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].contractAddress);
348 EXPECT_EQ(flat[col0_offset + public_logs_row], pi.accumulatedData.publicLogs.length);
350 for (
size_t j = 0; j < 3; ++j) {
352 pi.accumulatedData.publicLogs.payload[j]);
357 EXPECT_EQ(flat[col0_offset + public_data_write_row], pi.accumulatedData.publicDataWrites[1].leafSlot);
358 EXPECT_EQ(flat[col1_offset + public_data_write_row], pi.accumulatedData.publicDataWrites[1].value);
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_APP_LOGIC_CALL_REQUESTS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_GAS_FEES_ROW_IDX
#define AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_TEARDOWN_CALL_REQUEST_ROW_IDX
#define AVM_PUBLIC_INPUTS_FEE_PAYER_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_FEE_RECIPIENT_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_COINBASE_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GAS_SETTINGS_TEARDOWN_GAS_LIMITS_ROW_IDX
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH
#define AVM_PUBLIC_INPUTS_TRANSACTION_FEE_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_BLOCK_NUMBER_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_SETUP_CALL_REQUESTS_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_CALL_REQUEST_ARRAY_LENGTHS_APP_LOGIC_CALLS_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_SLOT_NUMBER_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_VERSION_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_CALL_REQUEST_ARRAY_LENGTHS_TEARDOWN_CALL_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_TIMESTAMP_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GAS_SETTINGS_MAX_FEES_PER_GAS_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX
#define AVM_PUBLIC_INPUTS_PUBLIC_CALL_REQUEST_ARRAY_LENGTHS_SETUP_CALLS_ROW_IDX
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX
#define AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_CHAIN_ID_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
#define AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GAS_SETTINGS_MAX_PRIORITY_FEES_PER_GAS_ROW_IDX
#define AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH
const std::vector< FF > data
TEST(EmitUnencryptedLogTest, Basic)
std::pair< tracegen::TraceContainer, PublicInputs > get_minimal_trace_with_pi()
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)