11#ifndef _ONCHAINWITHDRAWALCIRCUIT_H_
22#define _ONCHAINWITHDRAWALCIRCUIT_H_
33
4+ #include " Circuit.h"
45#include " ../Utils/Constants.h"
56#include " ../Utils/Data.h"
67#include " ../Utils/Utils.h"
@@ -180,7 +181,7 @@ class OnchainWithdrawalGadget : public GadgetT
180181 }
181182};
182183
183- class OnchainWithdrawalCircuit : public GadgetT
184+ class OnchainWithdrawalCircuit : public Circuit
184185{
185186public:
186187
@@ -204,7 +205,7 @@ class OnchainWithdrawalCircuit : public GadgetT
204205 std::vector<sha256_many> hashers;
205206
206207 OnchainWithdrawalCircuit (ProtoboardT& pb, const std::string& prefix) :
207- GadgetT (pb, prefix),
208+ Circuit (pb, prefix),
208209
209210 publicData (pb, FMT(prefix, " .publicData" )),
210211 constants (pb, FMT(prefix, " .constants" )),
@@ -223,9 +224,9 @@ class OnchainWithdrawalCircuit : public GadgetT
223224
224225 }
225226
226- void generate_r1cs_constraints ( int numWithdrawals)
227+ void generateConstraints ( bool onchainDataAvailability, unsigned int blockSize) override
227228 {
228- this ->numWithdrawals = numWithdrawals ;
229+ this ->numWithdrawals = blockSize ;
229230
230231 constants.generate_r1cs_constraints ();
231232
@@ -299,9 +300,16 @@ class OnchainWithdrawalCircuit : public GadgetT
299300
300301 // Withdrawals
301302 assert (withdrawals.size () == hashers.size ());
303+ #ifdef MULTICORE
304+ #pragma omp parallel for
305+ #endif
302306 for (unsigned int i = 0 ; i < block.withdrawals .size (); i++)
303307 {
304308 withdrawals[i].generate_r1cs_witness (block.withdrawals [i]);
309+ }
310+ // Cannot be done in parallel
311+ for (unsigned int i = 0 ; i < block.withdrawals .size (); i++)
312+ {
305313 hashers[i].generate_r1cs_witness ();
306314 }
307315 // printBits("WithdrawBlockHash: 0x", hashers.back().result().bits.get_bits(pb));
@@ -312,7 +320,22 @@ class OnchainWithdrawalCircuit : public GadgetT
312320 return true ;
313321 }
314322
315- void printInfo ()
323+ bool generateWitness (const json& input) override
324+ {
325+ return generateWitness (input.get <Loopring::OnchainWithdrawalBlock>());
326+ }
327+
328+ BlockType getBlockType () override
329+ {
330+ return BlockType::OnchainWithdrawal;
331+ }
332+
333+ unsigned int getBlockSize () override
334+ {
335+ return numWithdrawals;
336+ }
337+
338+ void printInfo () override
316339 {
317340 std::cout << pb.num_constraints () << " constraints (" << (pb.num_constraints () / numWithdrawals) << " /onchain withdrawal)" << std::endl;
318341 }
0 commit comments