Skip to content

Commit

Permalink
Improvements to verifier; still broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Jan 19, 2023
1 parent b673a7c commit 1b3e172
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 32 deletions.
19 changes: 10 additions & 9 deletions cpp/src/aztec/honk/composer/composer_helper/composer_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ std::shared_ptr<waffle::verification_key> ComposerHelper<CircuitConstructor>::co
* @return The verifier.
* */
template <typename CircuitConstructor>
waffle::Verifier ComposerHelper<CircuitConstructor>::create_verifier(CircuitConstructor& circuit_constructor)
StandardVerifier ComposerHelper<CircuitConstructor>::create_verifier(CircuitConstructor& circuit_constructor)
{
compute_verification_key(circuit_constructor);
// TODO figure out types, actuallt
auto verification_key = compute_verification_key(circuit_constructor);
// TODO figure out types, actually
// circuit_verification_key->composer_type = type;

// TODO: initialize verifier according to manifest and key
// Verifier output_state(circuit_verification_key, create_manifest(public_inputs.size()));
waffle::Verifier output_state;
StandardVerifier output_state;
// TODO: Do we need a commitment scheme defined here?
// std::unique_ptr<KateCommitmentScheme<standard_settings>> kate_commitment_scheme =
// std::make_unique<KateCommitmentScheme<standard_settings>>();
Expand All @@ -289,14 +289,15 @@ waffle::Verifier ComposerHelper<CircuitConstructor>::create_verifier(CircuitCons
}

template <typename CircuitConstructor>
waffle::UnrolledVerifier ComposerHelper<CircuitConstructor>::create_unrolled_verifier(
StandardUnrolledVerifier ComposerHelper<CircuitConstructor>::create_unrolled_verifier(
CircuitConstructor& circuit_constructor)
{
compute_verification_key(circuit_constructor);
// UnrolledVerifier output_state(circuit_verification_key,
// create_unrolled_manifest(circuit_constructor.n,
// circuit_constructor.public_inputs.size()));
waffle::UnrolledVerifier output_state;
StandardUnrolledVerifier output_state(
circuit_verification_key,
honk::StandardHonk::create_unrolled_manifest(circuit_constructor.public_inputs.size(),
numeric::get_msb(circuit_verification_key->n)));
// StandardUnrolledVerifier output_state;

// TODO: Deal with commitments
// std::unique_ptr<KateCommitmentScheme<unrolled_standard_settings>> kate_commitment_scheme =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ template <typename CircuitConstructor> class ComposerHelper {
{
compute_witness_base<program_width>(circuit_constructor);
}
waffle::Verifier create_verifier(CircuitConstructor& circuit_constructor);

StandardVerifier create_verifier(CircuitConstructor& circuit_constructor);
/**
* Preprocess the circuit. Delegates to create_prover.
*
Expand All @@ -53,7 +54,7 @@ template <typename CircuitConstructor> class ComposerHelper {
StandardProver preprocess(CircuitConstructor& circuit_constructor) { return create_prover(circuit_constructor); };
StandardProver create_prover(CircuitConstructor& circuit_constructor);

waffle::UnrolledVerifier create_unrolled_verifier(CircuitConstructor& circuit_constructor);
StandardUnrolledVerifier create_unrolled_verifier(CircuitConstructor& circuit_constructor);

template <typename Flavor> StandardUnrolledProver create_unrolled_prover(CircuitConstructor& circuit_constructor);

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/aztec/honk/composer/standard_honk_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class StandardHonkComposer {
}
void compute_witness() { composer_helper.compute_witness(circuit_constructor); };
// TODO(Cody): This will not be needed, but maybe something is required for ComposerHelper to be generic?
waffle::Verifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); }
StandardVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); }
/**
* Preprocess the circuit. Delegates to create_prover.
*
Expand All @@ -174,7 +174,7 @@ class StandardHonkComposer {
*/
StandardProver preprocess() { return composer_helper.create_prover(circuit_constructor); };
StandardProver create_prover() { return composer_helper.create_prover(circuit_constructor); };
waffle::UnrolledVerifier create_unrolled_verifier()
StandardUnrolledVerifier create_unrolled_verifier()
{
return composer_helper.create_unrolled_verifier(circuit_constructor);
}
Expand Down
9 changes: 4 additions & 5 deletions cpp/src/aztec/honk/composer/standard_honk_composer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,11 @@ TEST(StandarHonkComposer, BaseCase)
composer.circuit_constructor.add_public_variable(a);

auto prover = composer.create_unrolled_prover();
// waffle::Verifier verifier = composer.create_verifier();
auto multivariates = honk::sumcheck::Multivariates<fr, waffle::STANDARD_HONK_MANIFEST_SIZE>(prover.proving_key);
(void)multivariates;
auto verifier = composer.create_unrolled_verifier();

waffle::plonk_proof proof = prover.construct_proof();

// bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2);
// EXPECT_EQ(result, true);
bool result = verifier.verify_proof(proof);
EXPECT_EQ(result, true);
}
} // namespace test_standard_honk_composer
38 changes: 32 additions & 6 deletions cpp/src/aztec/honk/proof_system/verifier.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#include <cmath>
#include <common/throw_or_abort.hpp>
#include <cstddef>
#include <memory>
#include <plonk/proof_system/constants.hpp>
#include "./verifier.hpp"
#include "../../plonk/proof_system/public_inputs/public_inputs.hpp"
#include "ecc/curves/bn254/fr.hpp"
#include "numeric/bitop/get_msb.hpp"
#include "proof_system/polynomial_cache/polynomial_cache.hpp"
#include <ecc/curves/bn254/fq12.hpp>
#include <ecc/curves/bn254/pairing.hpp>
#include <ecc/curves/bn254/scalar_multiplication/scalar_multiplication.hpp>
#include <polynomials/polynomial_arithmetic.hpp>
#include <honk/composer/composer_helper/permutation_helper.hpp>
#include <math.h>
#include <string>
#include <honk/utils/power_polynomial.hpp>

#pragma GCC diagnostic ignored "-Wunused-variable"

Expand Down Expand Up @@ -76,6 +84,8 @@ template <typename program_settings> bool Verifier<program_settings>::verify_pro

key->program_width = program_settings::program_width;

size_t log_n(numeric::get_msb(key->n));

// Add the proof data to the transcript, according to the manifest. Also initialise the transcript's hash type
// and challenge bytes.
auto transcript = transcript::StandardTranscript(
Expand All @@ -99,21 +109,37 @@ template <typename program_settings> bool Verifier<program_settings>::verify_pro
transcript.apply_fiat_shamir("eta");
transcript.apply_fiat_shamir("beta");
transcript.apply_fiat_shamir("alpha");

// TODO(Cody): Compute some basic public polys like id(X), pow(X), and any required Lagrange polys
for (size_t idx = 0; idx < log_n; idx++) {
transcript.apply_fiat_shamir("u_" + std::to_string(log_n - idx));
}

// TODO(Cody): Compute some basic public polys like id(X), ~~pow(X)~~, and any required Lagrange polys
std::vector<barretenberg::fr> u_vector_challenge;
u_vector_challenge.resize(log_n);
for (size_t idx = 1; idx <= log_n; idx++) {
const auto u_value =
barretenberg::fr::serialize_from_buffer(transcript.get_challenge("u_" + std::to_string(idx)).begin());
u_vector_challenge.emplace_back(u_value);
};

auto zeta_challenge = barretenberg::fr::serialize_from_buffer(transcript.get_challenge("alpha").begin());
zeta_challenge = zeta_challenge * zeta_challenge; // zeta = alpha^2
honk::power_polynomial::evaluate<barretenberg::fr>(zeta_challenge, u_vector_challenge);

// Execute Sumcheck Verifier
auto sumcheck = Sumcheck<Multivariates, Transcript, ArithmeticRelation>(transcript);
sumcheck.execute_verifier(); // Need to mock prover in tests for this to run
bool result = sumcheck.execute_verifier(); // Need to mock prover in tests for this to run

// Execute Gemini/Shplonk verification:
// Gemini (reduce_verify()): Compute [Fold_{r}^(0)]_1, [Fold_{-r}^(0)]_1, Fold_{r}^(0)(r)
// Shplonk (reduce_verify()): Compute simulated [Q_z]_1

// TODO: Do final pairing check
barretenberg::fq12 result = barretenberg::fq12::one();
// TODO(Cody): Do final pairing check
// barretenberg::fq12 result = barretenberg::fq12::one();

// return (result == barretenberg::fq12::one());

return (result == barretenberg::fq12::one());
return result;
}

template class Verifier<honk::standard_verifier_settings>;
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/aztec/honk/proof_system/verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include "../sumcheck/polynomials/multivariates.hpp"
#include "../sumcheck/sumcheck.hpp"
#include "../sumcheck/relations/arithmetic_relation.hpp"
#include "proof_system/flavor/flavor.hpp"

namespace honk {
template <typename program_settings> class Verifier {

public:
Verifier(std::shared_ptr<waffle::verification_key> verifier_key = nullptr,
const transcript::Manifest& manifest = transcript::Manifest());
const transcript::Manifest& manifest = honk::StandardHonk::create_unrolled_manifest(0));
Verifier(Verifier&& other);
Verifier(const Verifier& other) = delete;
Verifier& operator=(const Verifier& other) = delete;
Expand All @@ -32,5 +33,6 @@ template <typename program_settings> class Verifier {
extern template class Verifier<waffle::standard_verifier_settings>;

typedef Verifier<honk::standard_verifier_settings> StandardVerifier;
typedef Verifier<honk::standard_verifier_settings> StandardUnrolledVerifier;

} // namespace honk
6 changes: 5 additions & 1 deletion cpp/src/aztec/honk/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ template <class Multivariates, class Transcript, template <class> class... Relat
&transcript.get_element("univariate_" + std::to_string(multivariates.multivariate_d - round_idx))[0]);

verified = verified && round.check_sum(round_univariate);
FF round_challenge = transcript.get_mock_challenge(); // TODO(real challenge)
FF round_challenge = FF::serialize_from_buffer(
transcript.get_challenge("u_" + std::to_string(multivariates.multivariate_d - round_idx))
.begin()); // TODO(real challenge)
round.compute_next_target_sum(round_univariate, round_challenge);
}

Expand All @@ -97,6 +99,8 @@ template <class Multivariates, class Transcript, template <class> class... Relat
FF relation_separator_challenge = transcript.get_mock_challenge();
FF full_honk_relation_purported_value =
round.compute_full_honk_relation_purported_value(purported_evaluations, relation_separator_challenge);
info("full_honk_relation_purported_value: ", full_honk_relation_purported_value);
info("round.target_total_sum: ", round.target_total_sum);
verified = verified && (full_honk_relation_purported_value == round.target_total_sum);
return verified;
};
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/aztec/transcript/transcript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,16 @@ std::vector<uint8_t> Transcript::export_transcript() const
ASSERT(manifest_element.num_bytes == element_data.size());
}
if (!manifest_element.derived_by_verifier) {
// printf("writing element %s ", manifest_element.name.c_str());
// for (size_t j = 0; j < element_data.size(); ++j) {
// printf("%x", element_data[j]);
// }
// printf("\n");
printf("writing element %s ", manifest_element.name.c_str());
for (size_t j = 0; j < element_data.size(); ++j) {
printf("%x", element_data[j]);
}
printf("\n");
buffer.insert(buffer.end(), element_data.begin(), element_data.end());
}
}
}
// printf("output buffer size = %lu \n", buffer.size());
printf("output buffer size = %lu \n", buffer.size());
return buffer;
}

Expand Down

0 comments on commit 1b3e172

Please sign in to comment.