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