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>(uint256_t::from_uint128(abs_diff).get_msb() + 1);
21 const uint8_t num_bits_bound_16 = ((num_bits_bound - 1) / 16 + 1) * 16; // round up to multiple of 16
22 range_check.assert_range(abs_diff, num_bits_bound_16);
23 events.emit({
24 .a = a,
25 .b = b,
26 .result = res,
27 });
28 return res;
29}
30
32{
33 FF a_ff = a.as_ff();
34 FF b_ff = b.as_ff();
35 if (a.get_tag() == ValueTag::FF) {
36 return gt(a_ff, b_ff);
37 }
38 // It is a precondition that the memory value is <= 128 bits.
39 BB_ASSERT(a.get_tag() != MemoryTag::FF);
40 BB_ASSERT(b.get_tag() != MemoryTag::FF);
41 return gt(static_cast<uint128_t>(a_ff), static_cast<uint128_t>(b_ff));
42}
43
44} // namespace bb::avm2::simulation
#define BB_ASSERT(expression,...)
Definition assert.hpp:67
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
static constexpr uint256_t from_uint128(const uint128_t a) noexcept
Definition uint256.hpp:94
constexpr uint64_t get_msb() const
FF a
FF b
AvmFlavorSettings::FF FF
Definition field.hpp:10
unsigned __int128 uint128_t
Definition serialize.hpp:44