Skip to content

Commit

Permalink
libzeth: make joinsplit a bit more composable
Browse files Browse the repository at this point in the history
  • Loading branch information
dtebbs committed Jan 14, 2021
1 parent e6ca4d8 commit a94c795
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions libzeth/circuits/circuit_wrapper.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ circuit_wrapper<
NumOutputs,
TreeDepth>::circuit_wrapper()
{
// Joinsplit gadget internally allocates its public data first.
// TODO: joinsplit_gadget should be refactored to be properly composable.
joinsplit = std::make_shared<joinsplit_type>(pb);
const size_t num_public_elements = joinsplit->get_num_public_elements();
pb.set_input_sizes(num_public_elements);

// Generate constraints
joinsplit->generate_r1cs_constraints();
Expand Down
15 changes: 8 additions & 7 deletions libzeth/circuits/joinsplit.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ public:
// represented. The aggregation of these bits plus of value_pub_in,
// and value_pub_out take `nb_field_residual` field element(s) to be
// represented
const size_t nb_packed_inputs =
const size_t num_packed_public_elements =
2 * NumInputs + 1 + nb_field_residual;
const size_t nb_inputs = 1 + NumOutputs + nb_packed_inputs;
pb.set_input_sizes(nb_inputs);
const size_t num_public_elements =
1 + NumOutputs + num_packed_public_elements;
// ---------------------------------------------------------------

ZERO.allocate(pb, FMT(this->annotation_prefix, " ZERO"));
Expand Down Expand Up @@ -277,14 +277,15 @@ public:
// since we are packing all the inputs nullifiers + the h_is +
// + the h_sig + the residual bits
assert(packed_inputs.size() == NumInputs + 1 + NumInputs + 1);
assert(nb_packed_inputs == [this]() {
assert(num_packed_public_elements == [this]() {
size_t sum = 0;
for (const auto &i : packed_inputs) {
sum = sum + i.size();
}
return sum;
}());
assert(nb_inputs == get_inputs_field_element_size());
assert(num_public_elements == get_num_public_elements());
(void)num_public_elements;

// [SANITY CHECK] Total size of unpacked inputs
size_t total_size_unpacked_inputs = 0;
Expand Down Expand Up @@ -599,8 +600,8 @@ public:
return get_inputs_bit_size() - (1 + NumOutputs) * FieldT::capacity();
}

// Computes the number of field elements in the primary inputs
static size_t get_inputs_field_element_size()
// Computes the number of field elements in the public data
static size_t get_num_public_elements()
{
size_t nb_elements = 0;

Expand Down

0 comments on commit a94c795

Please sign in to comment.