Skip to content

Commit

Permalink
plonk: created length and challenge arrays as const members of class …
Browse files Browse the repository at this point in the history
…bls12_381_test_vector_transcript_hasher initialized in the constructor. addresses #61 (comment) .
  • Loading branch information
Vesselin Velichkov committed Oct 13, 2022
1 parent 44724a6 commit 81390ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace libsnark

bls12_381_test_vector_transcript_hasher::
bls12_381_test_vector_transcript_hasher()
: length_array({288, 320, 416, 704, 896, 1120})
, challenge_array({"beta", "gamma", "alpha", "zeta", "nu", "u"})
{
plonk_example example;

Expand Down Expand Up @@ -107,19 +109,11 @@ libff::Fr<libff::bls12_381_pp> bls12_381_test_vector_transcript_hasher::
{
size_t buffer_len = this->buffer.size();

// vector of valid lengths (\attention specific to BLS12-381)
const std::vector<size_t> length{288, 320, 416, 704, 896, 1120};

// map the index length=0,1...5 to the challenge string=beta,
// gamma, ...; used to print explicitly the challenge string for debug
std::vector<std::string> challenge_str = {
"beta", "gamma", "alpha", "zeta", "nu", "u"};

// find the matching index
size_t i = 0;
while (buffer_len != length[i]) {
while (buffer_len != length_array[i]) {
++i;
if (i >= length.size()) {
if (i >= length_array.size()) {
// If we are here, then the hasher buffer has invalid length so
// throw an exception
throw std::logic_error(
Expand All @@ -132,7 +126,7 @@ libff::Fr<libff::bls12_381_pp> bls12_381_test_vector_transcript_hasher::
__FILE__,
__LINE__,
(int)buffer_len,
challenge_str[i].c_str());
challenge_array[i].c_str());

const libff::Fr<libff::bls12_381_pp> challenge = hash_values[i]; // beta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class bls12_381_test_vector_transcript_hasher
// array containing the hash values of the communication transcript
// i.e. the six challenges (in this order): beta, gamma, alpha, zeta, nu, u
std::array<libff::Fr<libff::bls12_381_pp>, 6> hash_values;
// vector of valid lengths (\attention specific to BLS12-381)
const std::array<size_t, 6> length_array;
// map the index length=0,1...5 to the challenge string=beta,
// gamma, ...; used to print explicitly the challenge string for debug
const std::array<std::string, 6> challenge_array;

public:
bls12_381_test_vector_transcript_hasher();
Expand All @@ -93,7 +98,7 @@ class bls12_381_test_vector_transcript_hasher
// hashing
void add_element(const libff::G2<libff::bls12_381_pp> &element);

// TODO: use next declaration to implement an actual hash function
// TODO: use following declaration to implement an actual hash function
// e.g. BLAKE (from Aztec barretenberg implementation):
// https://github.com/AztecProtocol/barretenberg/blob/master/barretenberg/src/aztec/plonk/transcript/transcript.cpp#L33
//
Expand Down

0 comments on commit 81390ff

Please sign in to comment.