From 1bcdec40a46eb99cb5cbb1e499f10a3ebf9c53b5 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Mon, 23 May 2016 10:43:25 -0600 Subject: [PATCH] Refactor PRF_gadget to hand responsibility to PRF_addr_a_pk_gadget for creating the '0' argument to the PRF. --- src/zcash/circuit/prfs.tcc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/zcash/circuit/prfs.tcc b/src/zcash/circuit/prfs.tcc index 169653749..3f50ac9e5 100644 --- a/src/zcash/circuit/prfs.tcc +++ b/src/zcash/circuit/prfs.tcc @@ -14,7 +14,7 @@ public: bool c, bool d, pb_variable_array x, - boost::optional> y, + pb_variable_array y, std::shared_ptr> result ) : gadget(pb), result(result) { @@ -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(); - while (y->size() < 256) { - y->emplace_back(ZERO); - } - } - block.reset(new block_variable(pb, { discriminants, x, - *y + y }, "PRF_block")); hasher.reset(new sha256_compression_function_gadget( @@ -57,6 +49,16 @@ public: } }; +template +pb_variable_array gen256zeroes(pb_variable& ZERO) { + pb_variable_array ret; + while (ret.size() < 256) { + ret.emplace_back(ZERO); + } + + return ret; +} + template class PRF_addr_a_pk_gadget : public PRF_gadget { public: @@ -65,7 +67,7 @@ public: pb_variable& ZERO, pb_variable_array& a_sk, std::shared_ptr> result - ) : PRF_gadget(pb, ZERO, 1, 1, 0, 0, a_sk, boost::none, result) {} + ) : PRF_gadget(pb, ZERO, 1, 1, 0, 0, a_sk, gen256zeroes(ZERO), result) {} }; template