Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gt_trace.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
7
8namespace bb::avm2::tracegen {
9
22{
23 using C = Column;
24
25 uint32_t row = 0;
26 for (const auto& event : events) {
27 FF a_ff = FF(event.a);
28 FF b_ff = FF(event.b);
29 FF abs_diff = event.result ? a_ff - b_ff - 1 : b_ff - a_ff;
30 // Compute the bit-size of abs_diff, rounded up to a multiple of 16.
31 // This must match the num_bits used in the range check event emitted by simulation
32 // so that the #[GT_RANGE] lookup between this trace and range_check succeeds.
33 const uint8_t num_bits_bound = static_cast<uint8_t>(static_cast<uint256_t>(abs_diff).get_msb() + 1);
34 const uint8_t num_bits_bound_16 =
35 static_cast<uint8_t>(((num_bits_bound - 1) / 16 + 1) * 16); // round up to multiple of 16
36 trace.set(row,
37 { {
38 { C::gt_sel, 1 },
39 { C::gt_input_a, event.a },
40 { C::gt_input_b, event.b },
41 { C::gt_res, event.result ? 1 : 0 },
42 { C::gt_abs_diff, abs_diff },
43 { C::gt_num_bits, num_bits_bound_16 },
44 } });
45 row++;
46 };
47}
48
51
52} // namespace bb::avm2::tracegen
void process(const simulation::EventEmitterInterface< simulation::GreaterThanEvent >::Container &events, TraceContainer &trace)
Process the greater-than events and populate the relevant columns in the trace.
Definition gt_trace.cpp:20
static const InteractionDefinition interactions
Definition gt_trace.hpp:15
InteractionDefinition & add(auto &&... args)
TestTraceContainer trace
lookup_settings< lookup_gt_gt_range_settings_ > lookup_gt_gt_range_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr T get_msb(const T in)
Definition get_msb.hpp:49
simulation::PublicDataTreeReadWriteEvent event