22template <
typename Fq_,
typename Fr_,
typename Params_>
class alignas(64)
affine_element {
50 static constexpr
affine_element one() noexcept {
return { Params::one_x, Params::one_y }; };
61 template <
typename BaseField =
Fq,
74 template <
typename BaseField =
Fq,
86 template <
typename BaseField =
Fq,
96 [[nodiscard]] constexpr
bool on_curve() const noexcept;
109 constexpr
bool operator==(const
affine_element& other) const noexcept;
128 if (
value.is_point_at_infinity()) {
131 memset(
buffer, 255,
sizeof(
Fq) * 2);
176 [[nodiscard]]
inline std::vector<uint8_t>
to_buffer()
const
199 os <<
"{ " <<
a.x <<
", " <<
a.y <<
" }";
206 template <
typename T>
230 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL
233 if constexpr (is_field2_v<Fq>) {
234 raw_element.x = { all_ones, all_ones };
235 raw_element.y = { all_ones, all_ones };
237 raw_element.x = all_ones;
238 raw_element.y = all_ones;
242 if constexpr (is_field2_v<Fq>) {
243 raw_element.x = {
x.c0,
x.c1 };
244 raw_element.y = {
y.c0,
y.c1 };
250 packer.pack(raw_element);
259 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL
263 if constexpr (is_field2_v<Fq>) {
264 is_infinity = (raw_element.
x[0] == all_ones && raw_element.
x[1] == all_ones &&
265 raw_element.
y[0] == all_ones && raw_element.
y[1] == all_ones);
267 is_infinity = (raw_element.
x == all_ones && raw_element.
y == all_ones);
274 if constexpr (is_field2_v<Fq>) {
275 x.c0 = raw_element.
x[0];
276 x.c1 = raw_element.
x[1];
277 y.c0 = raw_element.
y[0];
278 y.c1 = raw_element.
y[1];
288 if (packer.set_emitted(schema_name)) {
289 packer.pack(schema_name);
293 packer.pack(
"__typename");
294 packer.pack(schema_name);
296 packer.pack_schema(
x);
298 packer.pack_schema(
y);
302template <
typename B,
typename Fq_,
typename Fr_,
typename Params>
312template <
typename B,
typename Fq_,
typename Fr_,
typename Params>
#define BB_ASSERT(expression,...)
void msgpack_unpack(auto o)
friend std::ostream & operator<<(std::ostream &os, const affine_element &a)
static constexpr std::array< affine_element, 2 > from_compressed_unsafe(const uint256_t &compressed) noexcept
Reconstruct a point in affine coordinates from compressed form.
constexpr bool is_point_at_infinity() const noexcept
constexpr affine_element & operator=(const affine_element &other) noexcept=default
static constexpr affine_element hash_to_curve(const std::vector< uint8_t > &seed, uint8_t attempt_count=0) noexcept
Hash a seed buffer into a point.
static affine_element infinity()
static affine_element random_element(numeric::RNG *engine=nullptr) noexcept
Samples a random point on the curve.
std::vector< uint8_t > to_buffer() const
Serialize the point to a byte vector.
void msgpack_pack(auto &packer) const
const uint8_t * vec_in_buf
constexpr uint256_t compress() const noexcept
static affine_element serialize_from_buffer(const uint8_t *buffer, bool write_x_first=false)
Restore point from a buffer.
constexpr void self_set_infinity() noexcept
constexpr affine_element & operator=(affine_element &&other) noexcept=default
constexpr bool operator<(const affine_element &other) const noexcept
static affine_element reconstruct_from_public(const std::span< const bb::fr, PUBLIC_INPUTS_SIZE > &limbs)
constexpr affine_element operator+(const affine_element &other) const noexcept
static constexpr affine_element from_compressed(const uint256_t &compressed) noexcept
Reconstruct a point in affine coordinates from compressed form.
constexpr bool on_curve() const noexcept
affine_element() noexcept=default
static constexpr affine_element one() noexcept
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr std::optional< affine_element > derive_from_x_coordinate(const Fq &x, bool sign_bit) noexcept
static void serialize_to_buffer(const affine_element &value, uint8_t *buffer, bool write_x_first=false)
Serialize the point to the given buffer.
static constexpr bool is_field2_v
constexpr bool operator>(const affine_element &other) const noexcept
constexpr affine_element operator*(const Fr &exponent) const noexcept
void msgpack_schema(auto &packer) const
constexpr affine_element set_infinity() const noexcept
element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic....
uint8_t buffer[RANDOM_BUFFER_SIZE]
void read(B &it, group_elements::affine_element< Fq_, Fr_, Params > &element)
void write(B &it, group_elements::affine_element< Fq_, Fr_, Params > const &element)
std::string msgpack_schema_name(g1::affine_element const &)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr size_t PUBLIC_INPUTS_SIZE
static field reconstruct_from_public(const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &limbs)
std::conditional_t< is_field2_v< Fq >, std::array< uint256_t, 2 >, uint256_t > FieldType