From 81390ff9e706f044118f80ee7a853e769058eadc Mon Sep 17 00:00:00 2001 From: Vesselin Velichkov Date: Tue, 13 Sep 2022 12:13:50 +0100 Subject: [PATCH] plonk: created length and challenge arrays as const members of class bls12_381_test_vector_transcript_hasher initialized in the constructor. addresses https://github.com/clearmatics/libsnark/pull/61#discussion_r968607447 . --- .../bls12_381_test_vector_transcript_hasher.cpp | 16 +++++----------- .../bls12_381_test_vector_transcript_hasher.hpp | 7 ++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.cpp b/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.cpp index 453e42be0..aed065d54 100644 --- a/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.cpp +++ b/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.cpp @@ -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; @@ -107,19 +109,11 @@ libff::Fr 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 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 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( @@ -132,7 +126,7 @@ libff::Fr bls12_381_test_vector_transcript_hasher:: __FILE__, __LINE__, (int)buffer_len, - challenge_str[i].c_str()); + challenge_array[i].c_str()); const libff::Fr challenge = hash_values[i]; // beta diff --git a/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.hpp b/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.hpp index fd9be7093..749bd7a49 100644 --- a/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.hpp +++ b/libsnark/zk_proof_systems/plonk/tests/bls12_381_test_vector_transcript_hasher.hpp @@ -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, 6> hash_values; + // vector of valid lengths (\attention specific to BLS12-381) + const std::array 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 challenge_array; public: bls12_381_test_vector_transcript_hasher(); @@ -93,7 +98,7 @@ class bls12_381_test_vector_transcript_hasher // hashing void add_element(const libff::G2 &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 //