Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Public Attributes | List of all members
libsnark::memory_masking_gadget< FieldT > Class Template Reference

#include <memory_masking_gadget.hpp>

Inheritance diagram for libsnark::memory_masking_gadget< FieldT >:
Inheritance graph
[legend]
Collaboration diagram for libsnark::memory_masking_gadget< FieldT >:
Collaboration graph
[legend]

Public Member Functions

 memory_masking_gadget (tinyram_protoboard< FieldT > &pb, const doubleword_variable_gadget< FieldT > &dw_contents_prev, const dual_variable_gadget< FieldT > &subaddress, const pb_linear_combination< FieldT > &subcontents, const pb_linear_combination< FieldT > &access_is_word, const pb_linear_combination< FieldT > &access_is_byte, const doubleword_variable_gadget< FieldT > &dw_contents_next, const std::string &annotation_prefix="")
 
void generate_r1cs_constraints ()
 
void generate_r1cs_witness ()
 
- Public Member Functions inherited from libsnark::tinyram_standard_gadget< FieldT >
 tinyram_standard_gadget (tinyram_protoboard< FieldT > &pb, const std::string &annotation_prefix="")
 
- Public Member Functions inherited from libsnark::tinyram_gadget< FieldT >
 tinyram_gadget (tinyram_protoboard< FieldT > &pb, const std::string &annotation_prefix="")
 
- Public Member Functions inherited from libsnark::gadget< FieldT >
 gadget (protoboard< FieldT > &pb, const std::string &annotation_prefix)
 

Public Attributes

doubleword_variable_gadget< FieldT > dw_contents_prev
 
dual_variable_gadget< FieldT > subaddress
 
pb_linear_combination< FieldT > subcontents
 
pb_linear_combination< FieldT > access_is_word
 
pb_linear_combination< FieldT > access_is_byte
 
doubleword_variable_gadget< FieldT > dw_contents_next
 

Additional Inherited Members

- Protected Attributes inherited from libsnark::tinyram_gadget< FieldT >
tinyram_protoboard< FieldT > & pb
 
- Protected Attributes inherited from libsnark::gadget< FieldT >
protoboard< FieldT > & pb
 
const std::string annotation_prefix
 

Detailed Description

template<typename FieldT>
class libsnark::memory_masking_gadget< FieldT >

The memory masking gadget checks if a specified part of a double word is correctly modified. In TinyRAM CPU checker we use this to implement byte addressing and word addressing for the memory that consists of double words.

More precisely, memory masking gadgets takes the following arguments:

dw_contents_prev, dw_contents_next – the contents of the memory

double word before and after the access

access_is_word – a boolean indicating if access is word

access_is_byte – a boolean indicating if access is byte

subaddress – an integer specifying which byte (if access_is_byte=1) or word (if access_is_byte=1) this access is operating on

subcontents – contents of the byte, resp., word to be operated on

Memory masking gadget enforces that dw_contents_prev is equal to dw_contents_next everywhere, except subaddres-th byte (if access_is_byte = 1), or MSB(subaddress)-th word (if access_is_word = 1). The corresponding byte, resp., word in dw_contents_next is required to equal subcontents.

Note that indexing MSB(subaddress)-th word is the same as indexing the word specified by subaddress expressed in bytes and aligned to the word boundary by rounding the subaddress down.

Requirements: The caller is required to perform bounds checks on subcontents. The caller is also required to ensure that exactly one of access_is_word and access_is_byte is set to 1.

Definition at line 58 of file memory_masking_gadget.hpp.

Constructor & Destructor Documentation

◆ memory_masking_gadget()

template<typename FieldT >
libsnark::memory_masking_gadget< FieldT >::memory_masking_gadget ( tinyram_protoboard< FieldT > &  pb,
const doubleword_variable_gadget< FieldT > &  dw_contents_prev,
const dual_variable_gadget< FieldT > &  subaddress,
const pb_linear_combination< FieldT > &  subcontents,
const pb_linear_combination< FieldT > &  access_is_word,
const pb_linear_combination< FieldT > &  access_is_byte,
const doubleword_variable_gadget< FieldT > &  dw_contents_next,
const std::string &  annotation_prefix = "" 
)

Member Function Documentation

◆ generate_r1cs_constraints()

template<typename FieldT >
void libsnark::memory_masking_gadget< FieldT >::generate_r1cs_constraints ( )
virtual

◆ generate_r1cs_witness()

template<typename FieldT >
void libsnark::memory_masking_gadget< FieldT >::generate_r1cs_witness ( )
virtual

Member Data Documentation

◆ access_is_byte

template<typename FieldT >
pb_linear_combination<FieldT> libsnark::memory_masking_gadget< FieldT >::access_is_byte

Definition at line 82 of file memory_masking_gadget.hpp.

◆ access_is_word

template<typename FieldT >
pb_linear_combination<FieldT> libsnark::memory_masking_gadget< FieldT >::access_is_word

Definition at line 81 of file memory_masking_gadget.hpp.

◆ dw_contents_next

template<typename FieldT >
doubleword_variable_gadget<FieldT> libsnark::memory_masking_gadget< FieldT >::dw_contents_next

Definition at line 83 of file memory_masking_gadget.hpp.

◆ dw_contents_prev

template<typename FieldT >
doubleword_variable_gadget<FieldT> libsnark::memory_masking_gadget< FieldT >::dw_contents_prev

Definition at line 78 of file memory_masking_gadget.hpp.

◆ subaddress

template<typename FieldT >
dual_variable_gadget<FieldT> libsnark::memory_masking_gadget< FieldT >::subaddress

Definition at line 79 of file memory_masking_gadget.hpp.

◆ subcontents

template<typename FieldT >
pb_linear_combination<FieldT> libsnark::memory_masking_gadget< FieldT >::subcontents

Definition at line 80 of file memory_masking_gadget.hpp.


The documentation for this class was generated from the following file: