-
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.
Merge pull request #107 from clearmatics/103-plonk-simple-circuit-all…
…-curves Test simple Plonk circuit on all curves
- Loading branch information
Showing
5 changed files
with
210 additions
and
53 deletions.
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
/** @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 bytes 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 | ||
// bytes 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 reset(); | ||
}; | ||
|
||
} // namespace libsnark | ||
|
||
#include "libsnark/zk_proof_systems/plonk/tests/dummy_transcript_hasher.tcc" | ||
|
||
#endif // LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_DUMMY_TRANSCRIPT_HASHER_HPP_ |
94 changes: 94 additions & 0 deletions
94
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,94 @@ | ||
/** @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_TCC_ | ||
#define LIBSNARK_ZK_PROOF_SYSTEMS_PLONK_TESTS_DUMMY_TRANSCRIPT_HASHER_TCC_ | ||
|
||
#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>::reset() | ||
{ | ||
this->buffer.clear(); | ||
} | ||
|
||
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_TCC_ |
Oops, something went wrong.