-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plonk: added dummy transcript hasher specialized for all curves; adde…
…d unit tests for the simple quadratic residue circuit for all curves (addresses issue #103)
- Loading branch information
Vesselin Velichkov
committed
Jan 19, 2023
1 parent
f2a21f2
commit 3fbb2a0
Showing
3 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
libsnark/zk_proof_systems/plonk/tests/dummy_transcript_hasher.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** @file | ||
***************************************************************************** | ||
* @author This file is part of libff, developed by Clearmatics Ltd | ||
* (originally developed by SCIPR Lab) and contributors | ||
* (see AUTHORS). | ||
* @copyright MIT license (see LICENSE file) | ||
*****************************************************************************/ | ||
|
||
#ifndef LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_HPP_ | ||
#define LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_HPP_ | ||
|
||
#include "libsnark/zk_proof_systems/plonk/utils.hpp" | ||
|
||
#include <array> | ||
|
||
namespace libsnark | ||
{ | ||
|
||
/// Implementation of a dummy transcript hasher interface (see | ||
/// transcript_hasher.hpp). It returns the number of the elemnts in | ||
/// the hash buffer as an Fr element. Specialized over the curve | ||
/// field. See also class bls12_381_test_vector_transcript_hasher, | ||
/// which is specific to the BLS12_381 curve. | ||
template<typename ppT> class dummy_transcript_hasher | ||
{ | ||
private: | ||
// buffer accumulating data to be hashed | ||
std::vector<uint8_t> buffer; | ||
|
||
public: | ||
dummy_transcript_hasher(); | ||
|
||
// Add an Fr element to the transcript buffer for hashing. | ||
void add_element(const libff::Fr<ppT> &element); | ||
// Add the coordinates of a G1 curve point to the transcript buffer for | ||
// hashing. | ||
void add_element(const libff::G1<ppT> &element); | ||
// Add the coordinates of a G2 curve point to the transcript buffer for | ||
// hashing. | ||
void add_element(const libff::G2<ppT> &element); | ||
|
||
// Dummy implementation of get_hash that simply returns the number | ||
// of elements in the buffer as an Fr value for the purposes of | ||
// unit testing. TODO: to be replaced by a call to a proper hash | ||
// function e.g. SHA2, BLAKE, etc. | ||
libff::Fr<ppT> get_hash(); | ||
|
||
// clear the buffer (for now only for testing) | ||
void buffer_clear(); | ||
|
||
// get buffer size | ||
size_t buffer_size(); | ||
}; | ||
|
||
} // namespace libsnark | ||
|
||
#include "libsnark/zk_proof_systems/plonk/tests/dummy_transcript_hasher.tcc" | ||
|
||
#endif // LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_DUMMY_TRANSCRIPT_HASHER_HPP_ |
100 changes: 100 additions & 0 deletions
100
libsnark/zk_proof_systems/plonk/tests/dummy_transcript_hasher.tcc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** @file | ||
***************************************************************************** | ||
* @author This file is part of libff, developed by Clearmatics Ltd | ||
* (originally developed by SCIPR Lab) and contributors | ||
* (see AUTHORS). | ||
* @copyright MIT license (see LICENSE file) | ||
*****************************************************************************/ | ||
|
||
#ifndef LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_CPP_ | ||
#define LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_CPP_ | ||
|
||
#include "libsnark/zk_proof_systems/plonk/tests/dummy_transcript_hasher.hpp" | ||
|
||
// Implementation of the dummy transcript hasher interface. See | ||
// dummy_transcript_hasher.hpp. | ||
namespace libsnark | ||
{ | ||
|
||
template<typename ppT> dummy_transcript_hasher<ppT>::dummy_transcript_hasher() | ||
{ | ||
|
||
} | ||
|
||
template<typename ppT> void dummy_transcript_hasher<ppT>::buffer_clear() | ||
{ | ||
this->buffer.clear(); | ||
} | ||
|
||
template<typename ppT> size_t dummy_transcript_hasher<ppT>::buffer_size() | ||
{ | ||
return this->buffer.size(); | ||
} | ||
|
||
template<typename ppT> | ||
void dummy_transcript_hasher<ppT>::add_element(const libff::Fr<ppT> &element) | ||
{ | ||
// convert the Fr element into a string | ||
std::string str; | ||
{ | ||
std::ostringstream ss; | ||
libff::field_write<libff::encoding_binary, libff::form_plain>( | ||
element, ss); | ||
str = ss.str(); | ||
} | ||
// copy the string as a sequence of uint8_t elements at the end of | ||
// the buffer | ||
std::copy(str.begin(), str.end(), std::back_inserter(this->buffer)); | ||
} | ||
|
||
template<typename ppT> | ||
void dummy_transcript_hasher<ppT>::add_element(const libff::G1<ppT> &element) | ||
{ | ||
libff::G1<ppT> element_aff(element); | ||
element_aff.to_affine_coordinates(); | ||
|
||
// convert the affine coordinates of the curve point into a string | ||
std::string str; | ||
{ | ||
std::ostringstream ss; | ||
libff::group_write< | ||
libff::encoding_binary, | ||
libff::form_plain, | ||
libff::compression_off>(element_aff, ss); | ||
str = ss.str(); | ||
} | ||
// copy the string as a sequence of uint8_t elements at the end of | ||
// the buffer | ||
std::copy(str.begin(), str.end(), std::back_inserter(this->buffer)); | ||
} | ||
|
||
template<typename ppT> | ||
void dummy_transcript_hasher<ppT>::add_element(const libff::G2<ppT> &element) | ||
{ | ||
libff::G2<ppT> element_aff(element); | ||
element_aff.to_affine_coordinates(); | ||
|
||
// convert the affine coordinates of the curve point into a string | ||
std::string str; | ||
{ | ||
std::ostringstream ss; | ||
libff::group_write< | ||
libff::encoding_binary, | ||
libff::form_plain, | ||
libff::compression_off>(element_aff, ss); | ||
str = ss.str(); | ||
} | ||
// copy the string as a sequence of uint8_t elements at the end of | ||
// the buffer | ||
std::copy(str.begin(), str.end(), std::back_inserter(this->buffer)); | ||
} | ||
|
||
template<typename ppT> libff::Fr<ppT> dummy_transcript_hasher<ppT>::get_hash() | ||
{ | ||
libff::Fr<ppT> buffer_len = libff::Fr<ppT>(this->buffer.size()); | ||
return buffer_len; | ||
} | ||
|
||
} // namespace libsnark | ||
|
||
#endif // LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_CPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters