Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
circuit_wrapper.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZETH_CIRCUITS_CIRCUIT_WRAPPER_HPP__
6 #define __ZETH_CIRCUITS_CIRCUIT_WRAPPER_HPP__
7 
11 #include "libzeth/core/note.hpp"
13 
14 namespace libzeth
15 {
16 
19 template<
20  typename HashT,
21  typename HashTreeT,
22  typename ppT,
23  typename snarkT,
24  size_t NumInputs,
25  size_t NumOutputs,
26  size_t TreeDepth>
28 {
29 public:
30  using Field = libff::Fr<ppT>;
31  // Both `joinsplit` and `joinsplit_gadget` are already used in the
32  // namespace.
33  using joinsplit_type = joinsplit_gadget<
34  Field,
35  HashT,
36  HashTreeT,
37  NumInputs,
38  NumOutputs,
39  TreeDepth>;
41 
43  circuit_wrapper(const circuit_wrapper &) = delete;
44  circuit_wrapper &operator=(const circuit_wrapper &) = delete;
45 
46  // Generate the trusted setup
47  typename snarkT::keypair generate_trusted_setup() const;
48 
49  // Retrieve the constraint system (intended for debugging purposes).
50  const libsnark::r1cs_constraint_system<Field> &get_constraint_system()
51  const;
52 
53  // Generate a proof and returns an extended proof
55  const Field &root,
56  const std::array<joinsplit_input<Field, TreeDepth>, NumInputs> &inputs,
57  const std::array<zeth_note, NumOutputs> &outputs,
58  const bits64 &vpub_in,
59  const bits64 &vpub_out,
60  const bits256 &h_sig_in,
61  const bits256 &phi_in,
62  const typename snarkT::proving_key &proving_key,
63  std::vector<Field> &out_public_data) const;
64 
65  const std::vector<Field> &get_last_assignment() const;
66 
67 private:
68  libsnark::protoboard<Field> pb;
69  libsnark::pb_variable<Field> public_data_hash;
70  libsnark::pb_variable_array<Field> public_data;
71  std::shared_ptr<joinsplit_type> joinsplit;
72  std::shared_ptr<input_hasher_type> input_hasher;
73 };
74 
75 } // namespace libzeth
76 
78 
79 #endif // __ZETH_CIRCUITS_CIRCUIT_WRAPPER_HPP__
libzeth::circuit_wrapper
Definition: circuit_wrapper.hpp:27
libzeth::HashTreeT
mimc_compression_function_gadget< FieldT > HashTreeT
Definition: circuit_types.hpp:28
libzeth::extended_proof
Definition: extended_proof.hpp:17
libzeth::circuit_wrapper::get_constraint_system
const libsnark::r1cs_constraint_system< Field > & get_constraint_system() const
libzeth::circuit_wrapper::Field
libff::Fr< ppT > Field
Definition: circuit_wrapper.hpp:30
libzeth
Definition: binary_operation.hpp:15
libzeth::circuit_wrapper::joinsplit_type
joinsplit_gadget< Field, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth > joinsplit_type
Definition: circuit_wrapper.hpp:39
libzeth::bits< 64 >
note.hpp
libzeth::circuit_wrapper::circuit_wrapper
circuit_wrapper()
extended_proof.hpp
mimc_input_hasher.hpp
libzeth::circuit_wrapper::operator=
circuit_wrapper & operator=(const circuit_wrapper &)=delete
circuit_wrapper.tcc
zeth_constants.hpp
libzeth::joinsplit_input
Definition: joinsplit_input.hpp:21
libzeth::circuit_wrapper::prove
extended_proof< ppT, snarkT > prove(const Field &root, const std::array< joinsplit_input< Field, TreeDepth >, NumInputs > &inputs, const std::array< zeth_note, NumOutputs > &outputs, const bits64 &vpub_in, const bits64 &vpub_out, const bits256 &h_sig_in, const bits256 &phi_in, const typename snarkT::proving_key &proving_key, std::vector< Field > &out_public_data) const
joinsplit.tcc
libzeth::mimc_input_hasher
Definition: mimc_input_hasher.hpp:17
libzeth::circuit_wrapper::get_last_assignment
const std::vector< Field > & get_last_assignment() const
libzeth::HashT
BLAKE2s_256< FieldT > HashT
Definition: circuit_types.hpp:24
libzeth::circuit_wrapper::generate_trusted_setup
snarkT::keypair generate_trusted_setup() const