Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gt.cpp
Go to the documentation of this file.
2
5
6namespace bb::avm2::simulation {
7
15bool GreaterThan::gt(const FF& a, const FF& b)
16{
17 return field_gt.ff_gt(a, b);
18}
19
32{
33 bool res = a > b;
34 const uint128_t abs_diff = res ? a - b - 1 : b - a;
35 const uint8_t num_bits_bound = static_cast<uint8_t>(static_cast<uint256_t>(abs_diff).get_msb() + 1);
36 const uint8_t num_bits_bound_16 =
37 static_cast<uint8_t>(((num_bits_bound - 1) / 16 + 1) * 16); // round up to multiple of 16
38 range_check.assert_range(abs_diff, num_bits_bound_16);
39 events.emit({
40 .a = a,
41 .b = b,
42 .result = res,
43 });
44 return res;
45}
46
59{
60 FF a_ff = a.as_ff();
61 FF b_ff = b.as_ff();
62 if (a.get_tag() == ValueTag::FF) {
63 return gt(a_ff, b_ff);
64 }
65 // It is a precondition that the memory value is <= 128 bits.
66 BB_ASSERT(a.get_tag() != MemoryTag::FF);
67 BB_ASSERT(b.get_tag() != MemoryTag::FF);
68 return gt(static_cast<uint128_t>(a_ff), static_cast<uint128_t>(b_ff));
69}
70
71} // namespace bb::avm2::simulation
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
virtual bool ff_gt(const FF &a, const FF &b)=0
EventEmitterInterface< GreaterThanEvent > & events
Definition gt.hpp:31
bool gt(const FF &a, const FF &b) override
Computes whether a > b for field elements, delegating to the ff_gt gadget.
Definition gt.cpp:15
FieldGreaterThanInterface & field_gt
Definition gt.hpp:29
FF a
FF b
AVM range check gadget for witness generation.
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr T get_msb(const T in)
Definition get_msb.hpp:49
unsigned __int128 uint128_t
Definition serialize.hpp:45