Skip to content

Commit

Permalink
Refactor PRF_gadget to hand responsibility to PRF_addr_a_pk_gadget fo…
Browse files Browse the repository at this point in the history
…r creating the '0' argument to the PRF.
  • Loading branch information
ebfull committed May 23, 2016
1 parent 671b956 commit 1bcdec4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/zcash/circuit/prfs.tcc
Expand Up @@ -14,7 +14,7 @@ public:
bool c,
bool d,
pb_variable_array<FieldT> x,
boost::optional<pb_variable_array<FieldT>> y,
pb_variable_array<FieldT> y,
std::shared_ptr<digest_variable<FieldT>> result
) : gadget<FieldT>(pb), result(result) {

Expand All @@ -26,18 +26,10 @@ public:
discriminants.emplace_back(c ? ONE : ZERO);
discriminants.emplace_back(d ? ONE : ZERO);

if (!y) {
// Create y and pad it with zeroes.
y = pb_variable_array<FieldT>();
while (y->size() < 256) {
y->emplace_back(ZERO);
}
}

block.reset(new block_variable<FieldT>(pb, {
discriminants,
x,
*y
y
}, "PRF_block"));

hasher.reset(new sha256_compression_function_gadget<FieldT>(
Expand All @@ -57,6 +49,16 @@ public:
}
};

template<typename FieldT>
pb_variable_array<FieldT> gen256zeroes(pb_variable<FieldT>& ZERO) {
pb_variable_array<FieldT> ret;
while (ret.size() < 256) {
ret.emplace_back(ZERO);
}

return ret;
}

template<typename FieldT>
class PRF_addr_a_pk_gadget : public PRF_gadget<FieldT> {
public:
Expand All @@ -65,7 +67,7 @@ public:
pb_variable<FieldT>& ZERO,
pb_variable_array<FieldT>& a_sk,
std::shared_ptr<digest_variable<FieldT>> result
) : PRF_gadget<FieldT>(pb, ZERO, 1, 1, 0, 0, a_sk, boost::none, result) {}
) : PRF_gadget<FieldT>(pb, ZERO, 1, 1, 0, 0, a_sk, gen256zeroes(ZERO), result) {}
};

template<typename FieldT>
Expand Down

0 comments on commit 1bcdec4

Please sign in to comment.