Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export data from prover #368

Merged
merged 4 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libzeth/circuits/circuit_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class circuit_wrapper
const typename snarkT::proving_key &proving_key,
std::vector<Field> &out_public_data) const;

const std::vector<Field> &get_last_assignment() const;

private:
libsnark::protoboard<Field> pb;
libsnark::pb_variable<Field> public_data_hash;
Expand Down
20 changes: 20 additions & 0 deletions libzeth/circuits/circuit_wrapper.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ extended_proof<ppT, snarkT> circuit_wrapper<
snarkT::generate_proof(proving_key, pb), pb.primary_input());
}

template<
typename HashT,
typename HashTreeT,
typename ppT,
typename snarkT,
size_t NumInputs,
size_t NumOutputs,
size_t TreeDepth>
const std::vector<libff::Fr<ppT>> &circuit_wrapper<
HashT,
HashTreeT,
ppT,
snarkT,
NumInputs,
NumOutputs,
TreeDepth>::get_last_assignment() const
{
return pb.full_variable_assignment();
}

} // namespace libzeth

#endif // __ZETH_CIRCUITS_CIRCUIT_WRAPPER_TCC__
1 change: 1 addition & 0 deletions libzeth/core/extended_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ template<typename ppT, typename snarkT> class extended_proof
extended_proof(
typename snarkT::proof &&in_proof,
libsnark::r1cs_primary_input<libff::Fr<ppT>> &&in_primary_inputs);

const typename snarkT::proof &get_proof() const;

const libsnark::r1cs_primary_input<libff::Fr<ppT>> &get_primary_inputs()
Expand Down
20 changes: 15 additions & 5 deletions libzeth/tests/circuits/simple_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <boost/filesystem.hpp>
#include <gtest/gtest.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/curves/bls12_377/bls12_377_pp.hpp>

using namespace libsnark;
using namespace libzeth;
Expand All @@ -23,7 +24,8 @@ boost::filesystem::path g_output_dir = boost::filesystem::path("");
namespace
{

template<typename ppT, typename snarkT> void test_simple_circuit_proof()
template<typename ppT, typename snarkT>
void test_simple_circuit_proof(bool support_output = true)
{
using Field = libff::Fr<ppT>;

Expand All @@ -36,7 +38,7 @@ template<typename ppT, typename snarkT> void test_simple_circuit_proof()
pb.get_constraint_system();

// Write to file if output directory is given.
if (!g_output_dir.empty()) {
if (!g_output_dir.empty() && support_output) {

boost::filesystem::path outpath =
g_output_dir / ("simple_circuit_r1cs_" + pp_name<ppT>() + ".json");
Expand Down Expand Up @@ -69,7 +71,7 @@ template<typename ppT, typename snarkT> void test_simple_circuit_proof()

ASSERT_TRUE(snarkT::verify(primary, proof, keypair.vk));

if (!g_output_dir.empty()) {
if (!g_output_dir.empty() && support_output) {
{
boost::filesystem::path proving_key_path =
g_output_dir / ("simple_proving_key_" + snarkT::name + "_" +
Expand Down Expand Up @@ -107,18 +109,25 @@ template<typename ppT, typename snarkT> void test_simple_circuit_proof()
}
}

TEST(SimpleTests, SimpleCircuitProofGroth16)
TEST(SimpleTests, SimpleCircuitProofGroth16AltBN128)
{
test_simple_circuit_proof<
libff::alt_bn128_pp,
libzeth::groth16_snark<libff::alt_bn128_pp>>();
}

TEST(SimpleTests, SimpleCircuitProofGroth16BLS12_377)
{
test_simple_circuit_proof<
libff::bls12_377_pp,
libzeth::groth16_snark<libff::bls12_377_pp>>();
}

TEST(SimpleTests, SimpleCircuitProofPghr13)
{
test_simple_circuit_proof<
libff::alt_bn128_pp,
pghr13_snark<libff::alt_bn128_pp>>();
pghr13_snark<libff::alt_bn128_pp>>(false);
}

TEST(SimpleTests, SimpleCircuitProofPow2Domain)
Expand Down Expand Up @@ -149,6 +158,7 @@ int main(int argc, char **argv)
{
// WARNING: Do once for all tests. Do not forget to do this.
libff::alt_bn128_pp::init_public_params();
libff::bls12_377_pp::init_public_params();

// Remove stdout noise from libff
libff::inhibit_profiling_counters = true;
Expand Down
7 changes: 7 additions & 0 deletions libzeth/tests/prover/prover_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void TestValidJS2In2Case1(
keypair.pk,
public_data);
libff::leave_block("Generate proof", true);

std::vector<Field> primary_inputs = ext_proof.get_primary_inputs();
ASSERT_EQ(1, primary_inputs.size());
ASSERT_NE(Field::zero(), primary_inputs[0]);
Expand All @@ -166,6 +167,12 @@ void TestValidJS2In2Case1(
input_hasher_type<snarkT>::compute_hash(public_data),
primary_inputs[0]);

// The full assignment should be strictly larger than the public data, and
// begin with the primary input.
const std::vector<Field> &full_assignment = prover.get_last_assignment();
ASSERT_GT(full_assignment.size(), public_data.size());
ASSERT_EQ(primary_inputs[0], full_assignment[0]);

libff::enter_block("Verify proof", true);
// Get the verification key
typename snarkT::verification_key vk = keypair.vk;
Expand Down
Loading