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

Refactor libsnark helpers [depends on #200] #206

Merged
merged 39 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f6f8bd8
Removed libsnark_helpers and created serialization folder
AntoineRondelet Apr 22, 2020
8adcfbd
Refactored API helper functions and the util files
AntoineRondelet Apr 22, 2020
83ff07b
Fixed define directives and minor renamings
AntoineRondelet Apr 22, 2020
ad3fbae
Some fixes after rebasing
dtebbs Apr 23, 2020
e71e18d
libzeth: some fixes for rearranged code
dtebbs Apr 23, 2020
c734dd6
libzeth: removed unused function
dtebbs Apr 27, 2020
62f2c9b
WIP: libzeth: partial layout of generic and snark-specific code
dtebbs Apr 24, 2020
d79512f
WIP: libzeth: groth16snark implementation, updated libzeth and prover…
dtebbs Apr 27, 2020
031f2f9
WIP: libzeth: groth16api implementation. working prover_server
dtebbs Apr 27, 2020
1378fd0
WIP: changes for working mpc_tools
dtebbs Apr 27, 2020
3af26ff
libzeth: working prover test
dtebbs Apr 27, 2020
51c33e2
libzeth: remove declaration of non-existant function, and unused header
dtebbs Apr 27, 2020
9bd4ef1
libzeth: fix all other tests under new code structure
dtebbs Apr 27, 2020
787fa14
libzeth: working pghr13 implementation
dtebbs Apr 28, 2020
d470969
libzeth: remove duplicate header
dtebbs Apr 28, 2020
bc44361
libzeth: clean up snark selection, support snark use independently of…
dtebbs Apr 28, 2020
0f0d967
libzeth: remove duplicated functions
dtebbs Apr 28, 2020
61a75fb
libzeth: remove redundant type param
dtebbs Apr 28, 2020
ee49dcc
libzeth: move circuit-related includes into circuits directory
dtebbs Apr 28, 2020
ea54736
libzeth: remove some redundant includes and clean some default values
dtebbs Apr 28, 2020
226296c
libzeth: file name consistency fix
dtebbs Apr 28, 2020
bb8c7b0
formatting script update
dtebbs Apr 28, 2020
6f1a45d
ci: remove redundant pghr13 job
dtebbs Apr 28, 2020
7fc6829
libzeth: linux build fix
dtebbs Apr 28, 2020
ce3aa65
libzeth: move root files to correct subdirectory
dtebbs Apr 28, 2020
ff56a02
libzeth: move some general code out of mpc dir
dtebbs Apr 28, 2020
a6e1a39
libzeth: move mpc code into its own subdir
dtebbs Apr 28, 2020
7949561
libzeth: fix some type names in multi_exp
dtebbs Apr 28, 2020
c2487ce
libzeth: clean up includes and whitespace
dtebbs Apr 28, 2020
d5391cc
libzeth: small documentation fix
dtebbs Apr 28, 2020
2b59ff8
libzeth: consistent type and file names
dtebbs Apr 30, 2020
c01ec75
libzeth: rename core/joinsplit.hpp to core/joinsplit_input.hpp
dtebbs Apr 30, 2020
f11e584
libzeth: unused comment
dtebbs Apr 30, 2020
6a610e4
libzeth: fix some include guards
dtebbs Apr 30, 2020
e2dbc3b
libzeth: rename type params in multi_exp
dtebbs Apr 30, 2020
dc8253b
libzeth: directly use libff::alt_bn128_* types in powersoftau seriali…
dtebbs Apr 30, 2020
c6c9695
traditional include guards over #pragma once
dtebbs Apr 30, 2020
383d8fa
libzeth: split ff_utils into field_element_utils and group_element_utils
dtebbs Apr 30, 2020
4cfd73b
libzeth: move some constants into zeth_constants.hpp for now
dtebbs Apr 30, 2020
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
9 changes: 0 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,3 @@ jobs:
submodules: recursive
- name: Execute
run: CI_CHECK_FORMAT=1 CI_USE_DOCKER=1 CI_CONFIG=${{ matrix.config }} scripts/ci build

build-linux-release-pghr13:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
with:
submodules: recursive
- name: Execute
run: CI_USE_DOCKER=1 CI_CONFIG=Release CI_ZKSNARK=PGHR13 scripts/ci build
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ set(ZETH_VERSION_MINOR 3)
# Configure a header file to pass some of the CMake settings
# to the source code
configure_file(
"${PROJECT_SOURCE_DIR}/zethConfig.h.in"
"${PROJECT_BINARY_DIR}/zethConfig.h"
"${PROJECT_SOURCE_DIR}/zeth_config.h.in"
"${PROJECT_BINARY_DIR}/zeth_config.h"
)

# Flags and compilation options to chose the type of zksnark
Expand Down
2 changes: 1 addition & 1 deletion depends/libsnark
19 changes: 6 additions & 13 deletions libzeth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,14 @@ string(TOLOWER ${ZKSNARK} ZKSNARK_NAME)
file(
GLOB_RECURSE
ZETH_SOURCE
types/**.?pp types/**.tcc

core/**.?pp core/**.tcc
snarks/**.?pp snarks/**.tcc
serialization/**.?pp serialization/**.tcc
circuits/**.?pp circuits/**.tcc
circuit_wrapper.???
commitments/**.?pp commitments/**.tcc
libsnark_helpers/**.?pp libsnark_helpers/**.tcc
snarks/${ZKSNARK_NAME}/core/**.???
snarks/${ZKSNARK_NAME}/api/**.???
# We only implement the MPC for Groth16 for now
snarks/groth16/mpc/**.???
snarks_alias.hpp
include_libsnark.hpp
util.?pp util.tcc
util_api.?pp util_api.tcc
zeth.h
mpc/**.?pp mpc/**.tcc
)

add_library(
zeth

Expand Down
8 changes: 4 additions & 4 deletions libzeth/circuits/binary_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef __ZETH_CIRCUITS_BINARY_OPERATION_HPP__
#define __ZETH_CIRCUITS_BINARY_OPERATION_HPP__

#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "libzeth/circuits/circuit_utils.hpp"
#include "libzeth/core/bits.hpp"
#include "math.h"

#include <libsnark/gadgetlib1/gadget.hpp>
Expand Down Expand Up @@ -45,7 +45,6 @@ template<typename FieldT> class xor_gadget : public libsnark::gadget<FieldT>
template<typename FieldT>
class xor_constant_gadget : public libsnark::gadget<FieldT>
{

private:
const libsnark::pb_variable_array<FieldT> a;
const libsnark::pb_variable_array<FieldT> b;
Expand Down Expand Up @@ -119,6 +118,7 @@ class double_bit32_sum_eq_gadget : public libsnark::gadget<FieldT>
};

} // namespace libzeth

AntoineRondelet marked this conversation as resolved.
Show resolved Hide resolved
#include "libzeth/circuits/binary_operation.tcc"

#endif // __ZETH_CIRCUITS_BINARY_OPERATION_HPP__
#endif // __ZETH_CIRCUITS_BINARY_OPERATION_HPP__
30 changes: 15 additions & 15 deletions libzeth/circuits/binary_operation.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef __ZETH_CIRCUITS_BINARY_OPERATION_TCC__
#define __ZETH_CIRCUITS_BINARY_OPERATION_TCC__

#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "libzeth/circuits/circuit_utils.hpp"
#include "libzeth/core/bits.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand All @@ -25,7 +25,7 @@ xor_gadget<FieldT>::xor_gadget(
{
assert(a.size() == b.size());
assert(b.size() == res.size());
};
}

template<typename FieldT> void xor_gadget<FieldT>::generate_r1cs_constraints()
{
Expand All @@ -37,7 +37,7 @@ template<typename FieldT> void xor_gadget<FieldT>::generate_r1cs_constraints()
2 * a[i], b[i], a[i] + b[i] - res[i]),
FMT(this->annotation_prefix, " xored_bits_%zu", i));
}
};
}

template<typename FieldT> void xor_gadget<FieldT>::generate_r1cs_witness()
{
Expand All @@ -49,7 +49,7 @@ template<typename FieldT> void xor_gadget<FieldT>::generate_r1cs_witness()
this->pb.val(res[i]) = this->pb.val(a[i]) + this->pb.val(b[i]);
}
}
};
}

template<typename FieldT>
xor_constant_gadget<FieldT>::xor_constant_gadget(
Expand All @@ -68,7 +68,7 @@ xor_constant_gadget<FieldT>::xor_constant_gadget(
assert(a.size() == b.size());
assert(b.size() == c.size());
assert(c.size() == res.size());
};
}

template<typename FieldT>
void xor_constant_gadget<FieldT>::generate_r1cs_constraints()
Expand Down Expand Up @@ -97,7 +97,7 @@ void xor_constant_gadget<FieldT>::generate_r1cs_constraints()
b[i] * (FieldT("1") - FieldT("2") * c[i])),
FMT(this->annotation_prefix, " rotated_xored_bits_%zu", i));
}
};
}

template<typename FieldT>
void xor_constant_gadget<FieldT>::generate_r1cs_witness()
Expand All @@ -116,7 +116,7 @@ void xor_constant_gadget<FieldT>::generate_r1cs_witness()
this->pb.val(res[i]) = FieldT("1");
}
}
};
}

template<typename FieldT>
xor_rot_gadget<FieldT>::xor_rot_gadget(
Expand All @@ -134,7 +134,7 @@ xor_rot_gadget<FieldT>::xor_rot_gadget(
{
assert(a.size() == b.size());
assert(b.size() == res.size());
};
}

template<typename FieldT>
void xor_rot_gadget<FieldT>::generate_r1cs_constraints()
Expand All @@ -146,7 +146,7 @@ void xor_rot_gadget<FieldT>::generate_r1cs_constraints()
2 * a[i], b[i], a[i] + b[i] - res[(i + shift) % a.size()]),
FMT(this->annotation_prefix, " rotated_xored_bits_%zu", i));
}
};
}

template<typename FieldT> void xor_rot_gadget<FieldT>::generate_r1cs_witness()
{
Expand All @@ -160,7 +160,7 @@ template<typename FieldT> void xor_rot_gadget<FieldT>::generate_r1cs_witness()
this->pb.val(a[i]) + this->pb.val(b[i]);
}
}
};
}

template<typename FieldT>
double_bit32_sum_eq_gadget<FieldT>::double_bit32_sum_eq_gadget(
Expand All @@ -174,7 +174,7 @@ double_bit32_sum_eq_gadget<FieldT>::double_bit32_sum_eq_gadget(
assert(a.size() == 32);
assert(a.size() == b.size());
assert(a.size() == res.size());
};
}

template<typename FieldT>
void double_bit32_sum_eq_gadget<FieldT>::generate_r1cs_constraints(
Expand Down Expand Up @@ -246,7 +246,7 @@ void double_bit32_sum_eq_gadget<FieldT>::generate_r1cs_constraints(
(left_side - packed_addition(res) - pow(2, 32)),
0),
FMT(this->annotation_prefix, " sum_equal_sum_constraint"));
};
}

template<typename FieldT>
void double_bit32_sum_eq_gadget<FieldT>::generate_r1cs_witness()
Expand All @@ -260,8 +260,8 @@ void double_bit32_sum_eq_gadget<FieldT>::generate_r1cs_witness()

bits32 left_side_acc = binary_addition<32>(a_bits32, b_bits32, false);
res.fill_with_bits(this->pb, get_vector_from_bits32(left_side_acc));
};
}

} // namespace libzeth

#endif // __ZETH_CIRCUITS_BINARY_OPERATION_TCC__
#endif // __ZETH_CIRCUITS_BINARY_OPERATION_TCC__
7 changes: 4 additions & 3 deletions libzeth/circuits/blake2s/blake2s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "libzeth/circuits/binary_operation.hpp"
#include "libzeth/circuits/blake2s/blake2s_comp.hpp"
#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "libzeth/util.hpp"
#include "libzeth/circuits/circuit_utils.hpp"
#include "libzeth/core/bits.hpp"
#include "libzeth/core/utils.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand Down Expand Up @@ -165,6 +165,7 @@ template<typename FieldT> class BLAKE2s_256 : public libsnark::gadget<FieldT>
};

} // namespace libzeth

#include "libzeth/circuits/blake2s/blake2s.tcc"

#endif // __ZETH_CIRCUITS_BLAKE2S_HPP__
2 changes: 2 additions & 0 deletions libzeth/circuits/blake2s/blake2s.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace libzeth
{

static const size_t BYTE_LEN = 8;

/// This gadget implements the interface of the HashT template
template<typename FieldT>
BLAKE2s_256<FieldT>::BLAKE2s_256(
Expand Down
6 changes: 3 additions & 3 deletions libzeth/circuits/blake2s/blake2s_comp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "libzeth/circuits/binary_operation.hpp"
#include "libzeth/circuits/blake2s/g_primitive.hpp"
#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "libzeth/util.hpp"
#include "libzeth/circuits/circuit_utils.hpp"
#include "libzeth/core/bits.hpp"
#include "libzeth/core/utils.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand Down
7 changes: 4 additions & 3 deletions libzeth/circuits/blake2s/g_primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define __ZETH_CIRCUITS_G_PRIMITIVE_HPP__

#include "libzeth/circuits/binary_operation.hpp"
#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "libzeth/circuits/circuit_utils.hpp"
#include "libzeth/core/bits.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand Down Expand Up @@ -69,6 +69,7 @@ template<typename FieldT> class g_primitive : public libsnark::gadget<FieldT>
};

} // namespace libzeth

#include "libzeth/circuits/blake2s/g_primitive.tcc"

#endif // __ZETH_CIRCUITS_G_PRIMITIVE_HPP__
#endif // __ZETH_CIRCUITS_G_PRIMITIVE_HPP__
2 changes: 1 addition & 1 deletion libzeth/circuits/blake2s/g_primitive.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ template<typename FieldT> void g_primitive<FieldT>::generate_r1cs_witness()

} // namespace libzeth

#endif // __ZETH_CIRCUITS_G_PRIMITIVE_TCC__
#endif // __ZETH_CIRCUITS_G_PRIMITIVE_TCC__
11 changes: 6 additions & 5 deletions libzeth/circuit_types.hpp → libzeth/circuits/circuit_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
//
// SPDX-License-Identifier: LGPL-3.0+

#ifndef __ZETH_CIRCUIT_TYPES_HPP__
#define __ZETH_CIRCUIT_TYPES_HPP__
#ifndef __ZETH_CIRCUITS_CIRCUIT_TYPES_HPP__
#define __ZETH_CIRCUITS_CIRCUIT_TYPES_HPP__

#include "libzeth/circuit_wrapper.hpp"
#include "libzeth/circuits/blake2s/blake2s.hpp"
#include "libzeth/include_libsnark.hpp"
#include "libzeth/circuits/circuit_wrapper.hpp"
#include "libzeth/circuits/mimc/mimc_mp.hpp"
#include "libzeth/core/include_libsnark.hpp"

// Types that must be common across all executable, defined once here. Outside
// of tests, these should not be set anywhere else in the code. Do not include
Expand All @@ -30,4 +31,4 @@ using HashTreeT = MiMC_mp_gadget<FieldT>;

} // namespace libzeth

#endif // __ZETH_CIRCUIT_TYPES_HPP__
#endif // __ZETH_CIRCUITS_CIRCUIT_TYPES_HPP__
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: LGPL-3.0+

#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/circuits/circuit_utils.hpp"

namespace libzeth
{
Expand All @@ -25,4 +25,4 @@ std::vector<bool> convert_to_binary(size_t n)
return res;
}

} // namespace libzeth
} // namespace libzeth
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//
// SPDX-License-Identifier: LGPL-3.0+

#ifndef __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__
#define __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__
#ifndef __ZETH_CIRCUITS_CIRCUIT_UTILS_HPP__
#define __ZETH_CIRCUITS_CIRCUIT_UTILS_HPP__

#include "libzeth/types/bits.hpp"
#include "libzeth/core/bits.hpp"

#include <libsnark/gadgetlib1/pb_variable.hpp>

Expand All @@ -22,6 +22,7 @@ libsnark::pb_variable_array<FieldT> from_bits(
std::vector<bool> bits, const libsnark::pb_variable<FieldT> &ZERO);

} // namespace libzeth
#include "libzeth/circuits/circuits_utils.tcc"

#endif // __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__
#include "libzeth/circuits/circuit_utils.tcc"

#endif // __ZETH_CIRCUITS_CIRCUIT_UTILS_HPP__
File renamed without changes.
Loading