Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Friends | List of all members
gadgetlib2::R1P_Elem Class Reference

#include <variable.hpp>

Inheritance diagram for gadgetlib2::R1P_Elem:
Inheritance graph
[legend]
Collaboration diagram for gadgetlib2::R1P_Elem:
Collaboration graph
[legend]

Public Member Functions

 R1P_Elem (const Fp &elem)
 
virtual R1P_Elemoperator= (const FConst &src)
 
virtual R1P_Elemoperator= (const long n)
 
virtual ::std::string asString () const
 
virtual FieldType fieldType () const
 
virtual R1P_Elemoperator+= (const FElemInterface &other)
 
virtual R1P_Elemoperator-= (const FElemInterface &other)
 
virtual R1P_Elemoperator*= (const FElemInterface &other)
 
virtual bool operator== (const FElemInterface &other) const
 
virtual bool operator== (const FConst &other) const
 
virtual bool operator== (const long n) const
 
virtual FElemInterfacePtr clone () const
 
virtual FElemInterfacePtr inverse () const
 
long asLong () const
 
int getBit (unsigned int i) const
 
virtual FElemInterfacepower (long exponent)
 
- Public Member Functions inherited from gadgetlib2::FElemInterface
virtual ~FElemInterface ()
 

Friends

class FElem
 
class GadgetLibAdapter
 

Detailed Description

Holds elements of a prime characteristic field. Currently implemented using the gmp (Linux) and mpir (Windows) libraries.

Definition at line 245 of file variable.hpp.

Constructor & Destructor Documentation

◆ R1P_Elem()

gadgetlib2::R1P_Elem::R1P_Elem ( const Fp elem)
inlineexplicit

Definition at line 251 of file variable.hpp.

251 : elem_(elem) {}
Here is the caller graph for this function:

Member Function Documentation

◆ asLong()

long gadgetlib2::R1P_Elem::asLong ( ) const
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 253 of file variable.cpp.

254 {
255  // GADGETLIB_ASSERT(elem_.as_ulong() <= LONG_MAX, "long overflow occured.");
256  return long(elem_.as_ulong());
257 }
Here is the caller graph for this function:

◆ asString()

virtual ::std::string gadgetlib2::R1P_Elem::asString ( ) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 262 of file variable.hpp.

263  {
264  return GADGETLIB2_FMT("%u", elem_.as_ulong());
265  }
Here is the call graph for this function:

◆ clone()

virtual FElemInterfacePtr gadgetlib2::R1P_Elem::clone ( ) const
inlinevirtual
Returns
a unique_ptr to a new copy of the element

Implements gadgetlib2::FElemInterface.

Definition at line 277 of file variable.hpp.

278  {
279  return FElemInterfacePtr(new R1P_Elem(*this));
280  }
Here is the call graph for this function:

◆ fieldType()

virtual FieldType gadgetlib2::R1P_Elem::fieldType ( ) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 266 of file variable.hpp.

266 { return R1P; }

◆ getBit()

int gadgetlib2::R1P_Elem::getBit ( unsigned int  i) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 285 of file variable.hpp.

285 { return elem_.as_bigint().test_bit(i); }

◆ inverse()

FElemInterfacePtr gadgetlib2::R1P_Elem::inverse ( ) const
virtual
Returns
a unique_ptr to a new copy of the element's multiplicative inverse

Implements gadgetlib2::FElemInterface.

Definition at line 248 of file variable.cpp.

249 {
250  return FElemInterfacePtr(new R1P_Elem(elem_.inverse()));
251 }
Here is the call graph for this function:

◆ operator*=()

R1P_Elem & gadgetlib2::R1P_Elem::operator*= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 223 of file variable.cpp.

224 {
225  if (other.fieldType() == R1P) {
226  elem_ *= dynamic_cast<const R1P_Elem &>(other).elem_;
227  } else if (other.fieldType() == AGNOSTIC) {
228  elem_ *= dynamic_cast<const FConst &>(other).asLong();
229  } else {
230  GADGETLIB_FATAL("Attempted to add incompatible type to R1P_Elem.");
231  }
232  return *this;
233 }
Here is the call graph for this function:

◆ operator+=()

R1P_Elem & gadgetlib2::R1P_Elem::operator+= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 199 of file variable.cpp.

200 {
201  if (other.fieldType() == R1P) {
202  elem_ += dynamic_cast<const R1P_Elem &>(other).elem_;
203  } else if (other.fieldType() == AGNOSTIC) {
204  elem_ += dynamic_cast<const FConst &>(other).asLong();
205  } else {
206  GADGETLIB_FATAL("Attempted to add incompatible type to R1P_Elem.");
207  }
208  return *this;
209 }
Here is the call graph for this function:

◆ operator-=()

R1P_Elem & gadgetlib2::R1P_Elem::operator-= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 211 of file variable.cpp.

212 {
213  if (other.fieldType() == R1P) {
214  elem_ -= dynamic_cast<const R1P_Elem &>(other).elem_;
215  } else if (other.fieldType() == AGNOSTIC) {
216  elem_ -= dynamic_cast<const FConst &>(other).asLong();
217  } else {
218  GADGETLIB_FATAL("Attempted to add incompatible type to R1P_Elem.");
219  }
220  return *this;
221 }
Here is the call graph for this function:

◆ operator=() [1/2]

virtual R1P_Elem& gadgetlib2::R1P_Elem::operator= ( const FConst src)
inlinevirtual

FConst will be field agnostic, allowing us to hold values such as 0 and 1 without knowing the underlying field. This assignment operator will convert to the correct field element.

Implements gadgetlib2::FElemInterface.

Definition at line 252 of file variable.hpp.

253  {
254  elem_ = src.asLong();
255  return *this;
256  }
Here is the call graph for this function:

◆ operator=() [2/2]

virtual R1P_Elem& gadgetlib2::R1P_Elem::operator= ( const long  n)
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 257 of file variable.hpp.

258  {
259  elem_ = Fp(n);
260  return *this;
261  }

◆ operator==() [1/3]

virtual bool gadgetlib2::R1P_Elem::operator== ( const FConst other) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 271 of file variable.hpp.

272  {
273  return elem_ == Fp(other.asLong());
274  }
Here is the call graph for this function:

◆ operator==() [2/3]

bool gadgetlib2::R1P_Elem::operator== ( const FElemInterface other) const
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 235 of file variable.cpp.

236 {
237  const R1P_Elem *pOther = dynamic_cast<const R1P_Elem *>(&other);
238  if (pOther) {
239  return elem_ == pOther->elem_;
240  }
241  const FConst *pConst = dynamic_cast<const FConst *>(&other);
242  if (pConst) {
243  return *this == *pConst;
244  }
245  GADGETLIB_FATAL("Attempted to Compare R1P_Elem with incompatible type.");
246 }

◆ operator==() [3/3]

virtual bool gadgetlib2::R1P_Elem::operator== ( const long  n) const
inlinevirtual

This operator is not always mathematically well defined. 'n' will be checked in runtime for fields in which integer values are not well defined.

Implements gadgetlib2::FElemInterface.

Definition at line 275 of file variable.hpp.

275 { return elem_ == Fp(n); }

◆ power()

virtual FElemInterface& gadgetlib2::R1P_Elem::power ( long  exponent)
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 286 of file variable.hpp.

287  {
288  elem_ ^= exponent;
289  return *this;
290  }

Friends And Related Function Documentation

◆ FElem

friend class FElem
friend

Definition at line 292 of file variable.hpp.

◆ GadgetLibAdapter

friend class GadgetLibAdapter
friend

Definition at line 293 of file variable.hpp.


The documentation for this class was generated from the following files:
gadgetlib2::R1P_Elem::asLong
long asLong() const
Definition: variable.cpp:253
gadgetlib2::GADGETLIB2_FMT
::std::string GADGETLIB2_FMT(const char *format,...)
Definition: infrastructure.cpp:49
gadgetlib2::AGNOSTIC
@ AGNOSTIC
Definition: variable.hpp:37
GADGETLIB_FATAL
#define GADGETLIB_FATAL(msg)
Definition: infrastructure.hpp:85
gadgetlib2::FElemInterfacePtr
::std::unique_ptr< FElemInterface > FElemInterfacePtr
Definition: variable.hpp:41
gadgetlib2::R1P_Elem::R1P_Elem
R1P_Elem(const Fp &elem)
Definition: variable.hpp:251
gadgetlib2::R1P
@ R1P
Definition: variable.hpp:37
gadgetlib2::Fp
libff::Fr< libff::default_ec_pp > Fp
Definition: pp.hpp:29