|
purify
C++ Purify implementation with native circuit and BPP support
|
Field element modulo the backend scalar field used by this implementation. More...
#include <numeric.hpp>
Public Member Functions | |
| FieldElement () | |
| UInt256 | to_uint256 () const |
| Exports the field element as a canonical 256-bit unsigned integer. | |
| std::array< unsigned char, 32 > | to_bytes_be () const |
| Serializes the field element in big-endian form. | |
| std::array< unsigned char, 32 > | to_bytes_le () const |
| Serializes the field element in little-endian form. | |
| std::string | to_hex () const |
| Formats the field element as lowercase hexadecimal. | |
| std::string | to_decimal () const |
| Formats the field element as an unsigned decimal string. | |
| bool | is_zero () const |
| Returns true when the element is zero. | |
| bool | is_one () const |
| Returns true when the element is one. | |
| bool | is_odd () const |
| Returns true when the canonical representative is odd. | |
| bool | is_square () const |
| Returns true when the element is a quadratic residue in the field. | |
| FieldElement | negate () const |
| Returns the additive inverse modulo the field prime. | |
| void | conditional_assign (const FieldElement &other, bool flag) |
Conditionally assigns other into *this when flag is true. | |
| FieldElement | inverse_consttime () const |
| Returns the multiplicative inverse modulo the field prime in constant time. | |
| FieldElement | inverse () const |
| Returns the multiplicative inverse modulo the field prime using the faster variable-time backend. | |
| std::optional< FieldElement > | sqrt () const |
Computes a square root when one exists, otherwise returns std::nullopt. | |
| FieldElement | pow (const UInt256 &exponent) const |
| Raises the element to an unsigned exponent via square-and-multiply. | |
Static Public Member Functions | |
| static FieldElement | zero () |
| Returns the additive identity of the scalar field. | |
| static FieldElement | one () |
| Returns the multiplicative identity of the scalar field. | |
| static FieldElement | from_u64 (std::uint64_t value) |
| Constructs a field element from an unsigned 64-bit integer. | |
| static FieldElement | from_int (std::int64_t value) |
| Constructs a field element from a signed integer, reducing negatives modulo the field. | |
| static Result< FieldElement > | try_from_bytes32 (const std::array< unsigned char, 32 > &bytes) |
| Decodes a canonical 32-byte big-endian field element. | |
| static FieldElement | from_bytes32 (const std::array< unsigned char, 32 > &bytes) |
| Decodes a 32-byte big-endian field element. | |
| static Result< FieldElement > | try_from_uint256 (const UInt256 &value) |
| Converts a canonical 256-bit unsigned integer into the scalar field representation. | |
| static FieldElement | from_uint256 (const UInt256 &value) |
| Converts a 256-bit unsigned integer into the scalar field representation. | |
Friends | |
| struct | detail::FieldElementAccess |
| bool | operator== (const FieldElement &lhs, const FieldElement &rhs) |
| Compares two field elements for exact equality. | |
| bool | operator!= (const FieldElement &lhs, const FieldElement &rhs) |
| Compares two field elements for inequality. | |
| FieldElement | operator+ (const FieldElement &lhs, const FieldElement &rhs) |
| Adds two field elements modulo the field prime. | |
| FieldElement | operator- (const FieldElement &lhs, const FieldElement &rhs) |
| Subtracts two field elements modulo the field prime. | |
| FieldElement | operator* (const FieldElement &lhs, const FieldElement &rhs) |
| Multiplies two field elements modulo the field prime. | |
The implementation delegates arithmetic to secp256k1-zkp scalar routines through a thin C bridge so the C++ layer stays header-only.
Definition at line 815 of file numeric.hpp.
| purify::FieldElement::FieldElement | ( | ) |
Definition at line 28 of file numeric.cpp.
References purify_scalar_set_int().
Referenced by zero().
| void purify::FieldElement::conditional_assign | ( | const FieldElement & | other, |
| bool | flag | ||
| ) |
Definition at line 127 of file numeric.cpp.
References purify_scalar_cmov().
|
static |
Precondition: the input is canonical and strictly below the field modulus.
Definition at line 63 of file numeric.cpp.
References purify::Expected< T, E >::has_value(), and try_from_bytes32().
|
static |
Definition at line 46 of file numeric.cpp.
References from_u64(), and negate().
Referenced by purify::ExprBuilder::add(), purify::ExprBuilder::add_scaled(), purify::ExprBuilder::add_scaled(), purify::circuit_combine(), purify::circuit_main(), and purify::bppp::prove_experimental_circuit_zk_norm_arg_impl().
|
static |
Definition at line 40 of file numeric.cpp.
References purify_scalar_set_u64().
Referenced by from_int(), and one().
|
static |
Precondition: the integer is strictly below the field modulus.
Definition at line 73 of file numeric.cpp.
References purify::Expected< T, E >::has_value(), and try_from_uint256().
| FieldElement purify::FieldElement::inverse | ( | ) | const |
Definition at line 137 of file numeric.cpp.
References purify_scalar_inverse_var().
| FieldElement purify::FieldElement::inverse_consttime | ( | ) | const |
Definition at line 131 of file numeric.cpp.
References purify_scalar_inverse().
| bool purify::FieldElement::is_odd | ( | ) | const |
Definition at line 112 of file numeric.cpp.
References purify_scalar_is_even().
| bool purify::FieldElement::is_one | ( | ) | const |
Definition at line 108 of file numeric.cpp.
References purify_scalar_is_one().
Referenced by purify::ExprBuilder::add_scaled().
| bool purify::FieldElement::is_square | ( | ) | const |
Definition at line 116 of file numeric.cpp.
References purify_fe_is_square().
| bool purify::FieldElement::is_zero | ( | ) | const |
Definition at line 104 of file numeric.cpp.
References purify_scalar_is_zero().
Referenced by purify::ExprBuilder::add_scaled(), purify::ExprBuilder::add_term(), purify::bppp::prove_experimental_circuit_zk_norm_arg_impl(), purify::BulletproofTranscript::replace_and_insert(), purify::ExprBuilder::subtract(), and purify::Expr::to_string().
| FieldElement purify::FieldElement::negate | ( | ) | const |
Definition at line 121 of file numeric.cpp.
References purify_scalar_negate().
Referenced by purify::NativeBulletproofCircuit::PackedWithSlack::evaluate(), purify::NativeBulletproofCircuit::evaluate(), from_int(), and purify::ExprBuilder::subtract().
|
static |
Definition at line 36 of file numeric.cpp.
References from_u64().
Referenced by purify::BulletproofTranscript::replace_and_insert(), purify::Expr::to_string(), and purify::Expr::variable().
| FieldElement purify::FieldElement::pow | ( | const UInt256 & | exponent | ) | const |
Definition at line 152 of file numeric.cpp.
References purify::BigUInt< Words >::limbs, and purify_fe_pow().
| std::optional< FieldElement > purify::FieldElement::sqrt | ( | ) | const |
Definition at line 143 of file numeric.cpp.
References purify_fe_sqrt().
| std::array< unsigned char, 32 > purify::FieldElement::to_bytes_be | ( | ) | const |
Definition at line 84 of file numeric.cpp.
References purify_scalar_get_b32().
Referenced by purify::bppp::scalar_bytes(), to_bytes_le(), to_uint256(), and purify::capi_detail::write_field_element().
| std::array< unsigned char, 32 > purify::FieldElement::to_bytes_le | ( | ) | const |
Definition at line 90 of file numeric.cpp.
References to_bytes_be().
| std::string purify::FieldElement::to_decimal | ( | ) | const |
Definition at line 100 of file numeric.cpp.
References purify::BigUInt< Words >::to_decimal(), and to_uint256().
Referenced by purify::Expr::to_string().
| std::string purify::FieldElement::to_hex | ( | ) | const |
Definition at line 96 of file numeric.cpp.
References purify::BigUInt< Words >::to_hex(), and to_uint256().
| UInt256 purify::FieldElement::to_uint256 | ( | ) | const |
Definition at line 79 of file numeric.cpp.
References purify::BigUInt< 4 >::from_bytes_be(), and to_bytes_be().
Referenced by to_decimal(), and to_hex().
|
static |
Definition at line 53 of file numeric.cpp.
References purify_scalar_set_b32(), purify::RangeViolation, and purify::unexpected_error().
Referenced by purify::eval(), from_bytes32(), try_from_uint256(), and purify::bppp::verify_experimental_circuit_zk_norm_arg_impl().
|
static |
Definition at line 69 of file numeric.cpp.
References purify::BigUInt< Words >::to_bytes_be(), and try_from_bytes32().
Referenced by purify::BulletproofTranscript::add_pubkey_and_out(), purify::NativeBulletproofCircuitTemplate::final_evaluate(), from_uint256(), and purify::NativeBulletproofCircuitTemplate::instantiate_packed().
|
static |
Definition at line 32 of file numeric.cpp.
References FieldElement().
Referenced by purify::NativeBulletproofCircuit::PackedWithSlack::evaluate(), purify::NativeBulletproofCircuit::evaluate(), purify::NativeBulletproofCircuit::PackedWithSlack::from_circuit(), and purify::bppp::prove_experimental_circuit_zk_norm_arg_impl().
|
friend |
Definition at line 912 of file numeric.hpp.
|
friend |
Definition at line 163 of file numeric.cpp.
|
friend |
Definition at line 177 of file numeric.cpp.
|
friend |
Definition at line 167 of file numeric.cpp.
|
friend |
Definition at line 173 of file numeric.cpp.
|
friend |
Definition at line 159 of file numeric.cpp.