Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
calldata_trace.cpp
Go to the documentation of this file.
2
7
9
10namespace bb::avm2::tracegen {
11
14{
15 using C = Column;
16 uint32_t row = 1; // Has skip relations
17
18 for (const auto& event : events) {
19 const auto& calldata = event.calldata;
20 const auto context_id = event.context_id;
21
22 for (size_t i = 0; i < calldata.size(); i++) {
23 trace.set(row,
24 { {
25 { C::calldata_sel, 1 },
26 { C::calldata_context_id, context_id },
27 { C::calldata_value, calldata[i] },
28 { C::calldata_index, i },
29 { C::calldata_latch, (i == calldata.size() - 1) ? 1 : 0 },
30
31 } });
32 row++;
33 }
34 }
35}
36
39{
40 using C = Column;
41 uint32_t row = 1;
42
43 for (const auto& event : events) {
44 std::vector<FF> calldata_with_sep = { GENERATOR_INDEX__PUBLIC_CALLDATA };
45 size_t input_size = event.calldata.size() + 1; // +1 for the separator
46 calldata_with_sep.reserve(input_size);
47 calldata_with_sep.insert(calldata_with_sep.end(), event.calldata.begin(), event.calldata.end());
48
49 auto calldata_hash = Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash(calldata_with_sep);
50 size_t round = 0;
51 while (input_size > 0) {
52 std::array<FF, 4> input = {};
53 size_t chunk_size = std::min(input_size, static_cast<size_t>(3));
54 // We hash the calldata with the separator
55 for (size_t j = 0; j < chunk_size; j++) {
56 input[j] = calldata_with_sep[(round * 3) + j];
57 }
58
59 input_size -= chunk_size;
60
61 trace.set(row,
62 { {
63 { C::cd_hashing_sel, 1 },
64 { C::cd_hashing_context_id, event.context_id },
65 { C::cd_hashing_length_remaining, input_size },
66 { C::cd_hashing_input_0_, input[0] },
67 { C::cd_hashing_input_1_, input[1] },
68 { C::cd_hashing_input_2_, input[2] },
69 { C::cd_hashing_output_hash, input_size == 0 ? calldata_hash : 0 },
70 { C::cd_hashing_latch, (input_size == 0) ? 1 : 0 },
71 } });
72 round++;
73 row++;
74 }
75 }
76}
77
81 .add<lookup_calldata_hashing_cd_hash_end_settings, InteractionType::LookupSequential>();
82
83} // namespace bb::avm2::tracegen
#define GENERATOR_INDEX__PUBLIC_CALLDATA
void process_hashing(const simulation::EventEmitterInterface< simulation::CalldataEvent >::Container &events, TraceContainer &trace)
static const InteractionDefinition interactions
void process_retrieval(const simulation::EventEmitterInterface< simulation::CalldataEvent >::Container &events, TraceContainer &trace)
InteractionDefinition & add(auto &&... args)
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
TestTraceContainer trace
lookup_settings< lookup_calldata_hashing_cd_hash_settings_ > lookup_calldata_hashing_cd_hash_settings
simulation::PublicDataTreeReadWriteEvent event