Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gt.cpp
Go to the documentation of this file.
2
8
9namespace bb::avm2::simulation {
10
11bool GreaterThan::gt(const FF& a, const FF& b)
12{
13 return field_gt.ff_gt(a, b);
14}
15
17{
18 bool res = a > b;
19 const uint128_t abs_diff = res ? a - b - 1 : b - a;
20 const uint8_t num_bits_bound = static_cast<uint8_t>(static_cast<uint256_t>(abs_diff).get_msb() + 1);
21 const uint8_t num_bits_bound_16 =
22 static_cast<uint8_t>(((num_bits_bound - 1) / 16 + 1) * 16); // round up to multiple of 16
23 range_check.assert_range(abs_diff, num_bits_bound_16);
24 events.emit({
25 .a = a,
26 .b = b,
27 .result = res,
28 });
29 return res;
30}
31
33{
34 FF a_ff = a.as_ff();
35 FF b_ff = b.as_ff();
36 if (a.get_tag() == ValueTag::FF) {
37 return gt(a_ff, b_ff);
38 }
39 // It is a precondition that the memory value is <= 128 bits.
40 BB_ASSERT(a.get_tag() != MemoryTag::FF);
41 BB_ASSERT(b.get_tag() != MemoryTag::FF);
42 return gt(static_cast<uint128_t>(a_ff), static_cast<uint128_t>(b_ff));
43}
44
45} // 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:32
bool gt(const FF &a, const FF &b) override
Definition gt.cpp:11
FieldGreaterThanInterface & field_gt
Definition gt.hpp:30
FF a
FF b
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