Skip to content

Commit

Permalink
minor update to test, challenge instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxia01 committed Oct 5, 2023
1 parent 6eaa1a3 commit 2e55921
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ template <typename FF> class BaseTranscript {
for (size_t i = 0; i < num_challenges; i++) {
auto next_challenge_buffer = get_next_challenge_buffer(); // get next challenge buffer
std::array<uint8_t, sizeof(FF)> field_element_buffer{};
std::copy_n(next_challenge_buffer.begin(), HASH_OUTPUT_SIZE, field_element_buffer.begin());
// set upper half to 0 to make challenge 128 bits
std::fill_n(field_element_buffer.begin(), HASH_OUTPUT_SIZE / 2, 0);
// copy half of the hash to lower 128 bits of challenge
std::copy_n(next_challenge_buffer.begin(),
HASH_OUTPUT_SIZE / 2,
field_element_buffer.begin() + HASH_OUTPUT_SIZE / 2);
challenges[i] = from_buffer<FF>(field_element_buffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,32 @@ TEST_F(UltraTranscriptTests, VerifierManifestConsistency)
}
}

/**
* @brief Check that multiple challenges can be generated and sanity check
* @details We generate 6 challenges that are each 128 bits, and check that they are not 0.
*
*/
TEST_F(UltraTranscriptTests, ChallengeGenerationTest)
{
// initialized with random value sent to verifier
auto transcript = ProverTranscript<FF>::init_empty();
// test a bunch of challenges
auto challenges = transcript.get_challenges("a", "b", "c", "d", "e", "f");
// print challenges and check they are not 0
for (size_t i = 0; i < challenges.size(); ++i) {
info("Challenge ", i, ": ", challenges[i]);
ASSERT_NE(challenges[i], 0) << "Challenge " << i << " is 0";
}
constexpr uint32_t random_val{ 17 }; // arbitrary
transcript.send_to_verifier("random val", random_val);
// test more challenges
auto [a, b, c] = transcript.get_challenges("a", "b", "c");
info("Challenge a: ", a);
info("Challenge b: ", b);
info("Challenge c: ", c);
ASSERT_NE(a, 0) << "Challenge a is 0";
ASSERT_NE(b, 0) << "Challenge a is 0";
ASSERT_NE(b, 0) << "Challenge a is 0";
}

TEST_F(UltraTranscriptTests, FoldingManifestTest)
Expand Down

0 comments on commit 2e55921

Please sign in to comment.