1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
15using ::testing::SizeIs;
17TEST(AvmInputsTest, Deserialization)
20 auto data =
read_file(
"../src/barretenberg/vm2/testing/avm_inputs.testdata.bin");
29TEST(AvmInputsTest, FormatTransformations)
31 using ::testing::AllOf;
32 using ::testing::ElementsAre;
35 auto as_cols = pi.to_columns();
45 EXPECT_EQ(as_cols, unflattened);
48TEST(AvmInputsTest, ValuesInColumns)
54 pi.globalVariables.chainId = 123;
55 pi.globalVariables.version = 456;
56 pi.globalVariables.blockNumber = 12345;
57 pi.globalVariables.slotNumber = 67890;
58 pi.globalVariables.timestamp = 789000;
59 pi.globalVariables.coinbase = 123123;
60 pi.globalVariables.feeRecipient = 9876;
63 pi.globalVariables.gasFees.feePerDaGas = 111;
64 pi.globalVariables.gasFees.feePerL2Gas = 222;
67 pi.startTreeSnapshots.l1ToL2MessageTree.root = 1000;
68 pi.startTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex = 2000;
69 pi.startTreeSnapshots.noteHashTree.root = 3000;
70 pi.startTreeSnapshots.noteHashTree.nextAvailableLeafIndex = 4000;
71 pi.startTreeSnapshots.nullifierTree.root = 5000;
72 pi.startTreeSnapshots.nullifierTree.nextAvailableLeafIndex = 6000;
73 pi.startTreeSnapshots.publicDataTree.root = 7000;
74 pi.startTreeSnapshots.publicDataTree.nextAvailableLeafIndex = 8000;
77 pi.startGasUsed.daGas = 100;
78 pi.startGasUsed.l2Gas = 200;
81 pi.gasSettings.gasLimits.daGas = 1234;
82 pi.gasSettings.gasLimits.l2Gas = 5678;
83 pi.gasSettings.teardownGasLimits.daGas = 9012;
84 pi.gasSettings.teardownGasLimits.l2Gas = 3456;
85 pi.gasSettings.maxFeesPerGas.feePerDaGas = 7890;
86 pi.gasSettings.maxFeesPerGas.feePerL2Gas = 1234;
87 pi.gasSettings.maxPriorityFeesPerGas.feePerDaGas = 5678;
88 pi.gasSettings.maxPriorityFeesPerGas.feePerL2Gas = 9012;
94 pi.publicCallRequestArrayLengths.setupCalls = 2;
95 pi.publicCallRequestArrayLengths.appLogicCalls = 3;
96 pi.publicCallRequestArrayLengths.teardownCall =
true;
99 pi.publicSetupCallRequests[0].msgSender = 1111;
100 pi.publicSetupCallRequests[0].contractAddress = 2222;
101 pi.publicSetupCallRequests[0].isStaticCall =
true;
102 pi.publicSetupCallRequests[0].calldataHash = 3333;
104 pi.publicAppLogicCallRequests[1].msgSender = 4444;
105 pi.publicAppLogicCallRequests[1].contractAddress = 5555;
106 pi.publicAppLogicCallRequests[1].isStaticCall =
false;
107 pi.publicAppLogicCallRequests[1].calldataHash = 6666;
109 pi.publicTeardownCallRequest.msgSender = 7777;
110 pi.publicTeardownCallRequest.contractAddress = 8888;
111 pi.publicTeardownCallRequest.isStaticCall =
true;
112 pi.publicTeardownCallRequest.calldataHash = 9999;
115 pi.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes = 10;
116 pi.previousNonRevertibleAccumulatedDataArrayLengths.nullifiers = 20;
117 pi.previousNonRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs = 30;
119 pi.previousRevertibleAccumulatedDataArrayLengths.noteHashes = 40;
120 pi.previousRevertibleAccumulatedDataArrayLengths.nullifiers = 50;
121 pi.previousRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs = 60;
124 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.recipient = 1234;
125 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.content = 1357;
126 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].contractAddress = 3579;
129 pi.accumulatedData.noteHashes[2] = 54321;
130 pi.accumulatedData.nullifiers[3] = 98765;
133 pi.accumulatedData.l2ToL1Msgs[1].message.recipient = 3333;
134 pi.accumulatedData.l2ToL1Msgs[1].message.content = 7531;
135 pi.accumulatedData.l2ToL1Msgs[1].contractAddress = 9753;
138 pi.accumulatedData.publicLogs[0].contractAddress = 11223;
141 pi.accumulatedData.publicLogs[0].fields[j] = 10000 + j;
145 pi.accumulatedData.publicDataWrites[1].leafSlot = 5555;
146 pi.accumulatedData.publicDataWrites[1].value = 6666;
149 pi.endGasUsed.daGas = 5000;
150 pi.endGasUsed.l2Gas = 7000;
153 pi.endTreeSnapshots.l1ToL2MessageTree.root = 10000;
154 pi.endTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex = 20000;
155 pi.endTreeSnapshots.noteHashTree.root = 30000;
156 pi.endTreeSnapshots.noteHashTree.nextAvailableLeafIndex = 40000;
157 pi.endTreeSnapshots.nullifierTree.root = 50000;
158 pi.endTreeSnapshots.nullifierTree.nextAvailableLeafIndex = 60000;
159 pi.endTreeSnapshots.publicDataTree.root = 70000;
160 pi.endTreeSnapshots.publicDataTree.nextAvailableLeafIndex = 80000;
163 pi.transactionFee = 9876;
166 pi.accumulatedDataArrayLengths.noteHashes = 3;
167 pi.accumulatedDataArrayLengths.nullifiers = 4;
168 pi.accumulatedDataArrayLengths.l2ToL1Msgs = 2;
169 pi.accumulatedDataArrayLengths.publicLogs = 1;
170 pi.accumulatedDataArrayLengths.publicDataWrites = 5;
176 auto columns = pi.to_columns();
183 const size_t col0_offset = 0;
194 pi.globalVariables.blockNumber);
196 pi.globalVariables.slotNumber);
199 pi.globalVariables.feeRecipient);
201 pi.globalVariables.gasFees.feePerDaGas);
203 pi.globalVariables.gasFees.feePerL2Gas);
208 pi.startTreeSnapshots.l1ToL2MessageTree.root);
210 pi.startTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex);
212 pi.startTreeSnapshots.noteHashTree.root);
214 pi.startTreeSnapshots.noteHashTree.nextAvailableLeafIndex);
216 pi.startTreeSnapshots.nullifierTree.root);
218 pi.startTreeSnapshots.nullifierTree.nextAvailableLeafIndex);
220 pi.startTreeSnapshots.publicDataTree.root);
222 pi.startTreeSnapshots.publicDataTree.nextAvailableLeafIndex);
232 pi.gasSettings.teardownGasLimits.daGas);
234 pi.gasSettings.teardownGasLimits.l2Gas);
236 pi.gasSettings.maxFeesPerGas.feePerDaGas);
238 pi.gasSettings.maxFeesPerGas.feePerL2Gas);
240 pi.gasSettings.maxPriorityFeesPerGas.feePerDaGas);
242 pi.gasSettings.maxPriorityFeesPerGas.feePerL2Gas);
249 pi.publicCallRequestArrayLengths.setupCalls);
251 pi.publicCallRequestArrayLengths.appLogicCalls);
253 static_cast<uint8_t
>(pi.publicCallRequestArrayLengths.teardownCall));
257 EXPECT_EQ(flat[col0_offset + setup_row], pi.publicSetupCallRequests[0].msgSender);
258 EXPECT_EQ(flat[col1_offset + setup_row], pi.publicSetupCallRequests[0].contractAddress);
259 EXPECT_EQ(flat[col2_offset + setup_row],
static_cast<uint8_t
>(pi.publicSetupCallRequests[0].isStaticCall));
260 EXPECT_EQ(flat[col3_offset + setup_row], pi.publicSetupCallRequests[0].calldataHash);
263 EXPECT_EQ(flat[col0_offset + app_logic_row], pi.publicAppLogicCallRequests[1].msgSender);
264 EXPECT_EQ(flat[col1_offset + app_logic_row], pi.publicAppLogicCallRequests[1].contractAddress);
265 EXPECT_EQ(flat[col2_offset + app_logic_row],
static_cast<uint8_t
>(pi.publicAppLogicCallRequests[1].isStaticCall));
266 EXPECT_EQ(flat[col3_offset + app_logic_row], pi.publicAppLogicCallRequests[1].calldataHash);
269 EXPECT_EQ(flat[col0_offset + teardown_row], pi.publicTeardownCallRequest.msgSender);
270 EXPECT_EQ(flat[col1_offset + teardown_row], pi.publicTeardownCallRequest.contractAddress);
271 EXPECT_EQ(flat[col2_offset + teardown_row],
static_cast<uint8_t
>(pi.publicTeardownCallRequest.isStaticCall));
272 EXPECT_EQ(flat[col3_offset + teardown_row], pi.publicTeardownCallRequest.calldataHash);
275 EXPECT_EQ(flat[col0_offset +
277 pi.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes);
280 pi.previousNonRevertibleAccumulatedDataArrayLengths.nullifiers);
281 EXPECT_EQ(flat[col0_offset +
283 pi.previousNonRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs);
288 pi.previousRevertibleAccumulatedDataArrayLengths.noteHashes);
291 pi.previousRevertibleAccumulatedDataArrayLengths.nullifiers);
294 pi.previousRevertibleAccumulatedDataArrayLengths.l2ToL1Msgs);
298 pi.accumulatedDataArrayLengths.noteHashes);
300 pi.accumulatedDataArrayLengths.nullifiers);
302 pi.accumulatedDataArrayLengths.l2ToL1Msgs);
304 pi.accumulatedDataArrayLengths.publicLogs);
306 pi.accumulatedDataArrayLengths.publicDataWrites);
310 EXPECT_EQ(flat[col0_offset + l2_to_l1_msg_row],
311 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.recipient);
312 EXPECT_EQ(flat[col1_offset + l2_to_l1_msg_row],
313 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].message.content);
314 EXPECT_EQ(flat[col2_offset + l2_to_l1_msg_row],
315 pi.previousNonRevertibleAccumulatedData.l2ToL1Msgs[0].contractAddress);
319 pi.endTreeSnapshots.l1ToL2MessageTree.root);
321 pi.endTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex);
323 pi.endTreeSnapshots.noteHashTree.root);
325 pi.endTreeSnapshots.noteHashTree.nextAvailableLeafIndex);
333 pi.accumulatedData.noteHashes[2]);
335 pi.accumulatedData.nullifiers[3]);
339 EXPECT_EQ(flat[col0_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].message.recipient);
340 EXPECT_EQ(flat[col1_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].message.content);
341 EXPECT_EQ(flat[col2_offset + acc_l2_to_l1_msg_row], pi.accumulatedData.l2ToL1Msgs[1].contractAddress);
345 for (
size_t j = 0; j < 3; ++j) {
346 EXPECT_EQ(flat[col0_offset + first_log_row + j], pi.accumulatedData.publicLogs[0].contractAddress);
347 EXPECT_EQ(flat[col1_offset + first_log_row + j], pi.accumulatedData.publicLogs[0].emittedLength);
348 EXPECT_EQ(flat[col2_offset + first_log_row + j], pi.accumulatedData.publicLogs[0].fields[j]);
353 EXPECT_EQ(flat[col0_offset + public_data_write_row], pi.accumulatedData.publicDataWrites[1].leafSlot);
354 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 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_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_LOGS_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 PUBLIC_LOG_SIZE_IN_FIELDS
#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)