Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cycle_scalar.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
12
13namespace bb::stdlib {
14
15// Forward declaration
16template <typename Builder> class cycle_group;
17
34template <typename Builder> class cycle_scalar {
35 public:
37 using Curve = typename Builder::EmbeddedCurve;
40
41 static constexpr size_t NUM_BITS = ScalarField::modulus.get_msb() + 1;
42 static constexpr size_t LO_BITS = field_t::native::Params::MAX_BITS_PER_ENDOMORPHISM_SCALAR;
43 static constexpr size_t HI_BITS = NUM_BITS - LO_BITS;
44
47
48 private:
51 // if our scalar multiplier is a bn254 FF scalar (e.g. pedersen hash),
52 // we want to validate the cycle_scalar < bn254::fr::modulus *not* grumpkin::fr::modulus
54
55 public:
66 cycle_scalar(const ScalarField& _in = 0);
67 cycle_scalar(const field_t& _lo, const field_t& _hi);
68 cycle_scalar(const field_t& _in);
70 static cycle_scalar from_witness_bitstring(Builder* context, const uint256_t& bitstring, size_t num_bits);
72 [[nodiscard]] bool is_constant() const;
73 ScalarField get_value() const;
74 Builder* get_context() const { return lo.get_context() != nullptr ? lo.get_context() : hi.get_context(); }
75 [[nodiscard]] size_t num_bits() const { return _num_bits; }
76 [[nodiscard]] bool skip_primality_test() const { return _skip_primality_test; }
81 void validate_scalar_is_in_field() const;
82
95 void set_origin_tag(const OriginTag& tag) const
96 {
97 lo.set_origin_tag(tag);
98 hi.set_origin_tag(tag);
99 }
116};
117
118} // namespace bb::stdlib
cycle_scalar represents a member of the cycle curve SCALAR FIELD. This is NOT the native circuit fiel...
typename Builder::EmbeddedCurve Curve
typename Curve::ScalarField ScalarField
bool skip_primality_test() const
bool use_bn254_scalar_field_for_primality_test() const
stdlib::bigfield< Builder, typename ScalarField::Params > BigScalarField
static constexpr size_t NUM_BITS
static cycle_scalar create_from_bn254_scalar(const field_t &_in, bool skip_primality_test=false)
Use when we want to multiply a group element by a string of bits of known size. N....
ScalarField get_value() const
bool _use_bn254_scalar_field_for_primality_test
cycle_scalar(const field_t &_lo, const field_t &_hi, const size_t bits, const bool skip_primality_test, const bool use_bn254_scalar_field_for_primality_test)
static cycle_scalar from_witness(Builder *context, const ScalarField &value)
static cycle_scalar from_witness_bitstring(Builder *context, const uint256_t &bitstring, size_t num_bits)
Use when we want to multiply a group element by a string of bits of known size. N....
static constexpr size_t LO_BITS
void validate_scalar_is_in_field() const
Checks that a cycle_scalar value is smaller than a prime field modulus when evaluated over the INTEGE...
void unset_free_witness_tag()
Unset the free witness flag for the cycle scalar's tags.
Builder * get_context() const
void set_free_witness_tag()
Set the free witness flag for the cycle scalar's tags.
void set_origin_tag(const OriginTag &tag) const
Set the origin tag of lo and hi members of cycle scalar.
static constexpr size_t HI_BITS
OriginTag get_origin_tag() const
Get the origin tag of the cycle_scalar (a merge of the lo and hi tags)
void unset_free_witness_tag() const
Unset the free witness flag for the field element's tag.
Definition field.hpp:343
Builder * get_context() const
Definition field.hpp:389
OriginTag get_origin_tag() const
Definition field.hpp:333
void set_free_witness_tag()
Set the free witness flag for the field element's tag.
Definition field.hpp:338
void set_origin_tag(const OriginTag &new_tag) const
Definition field.hpp:332
StrictMock< MockContext > context
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...