Skip to content

Commit

Permalink
Add Mutex to global initialisation of generators (AztecProtocol/barre…
Browse files Browse the repository at this point in the history
…tenberg#371)

* Mutex lock initialization call

* add comment on mutex

---------

Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
maxhora and kevaundray authored Apr 21, 2023
1 parent 7a664fb commit 379a7ce
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "./pedersen_lookup.hpp"

#include <mutex>

#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"

namespace crypto {
Expand All @@ -10,6 +12,12 @@ std::array<std::vector<grumpkin::g1::affine_element>, NUM_PEDERSEN_TABLES> peder
std::vector<grumpkin::g1::affine_element> pedersen_iv_table;
std::array<grumpkin::g1::affine_element, NUM_PEDERSEN_TABLES> generators;

// Mutex is not available in the WASM context.
// WASM runs in a single-thread so this is acceptable.
#if !defined(__wasm__)
std::mutex init_mutex;
#endif

static bool inited = false;

void init_single_lookup_table(const size_t index)
Expand Down Expand Up @@ -66,6 +74,11 @@ void init()
{
ASSERT(BITS_PER_TABLE < BITS_OF_BETA);
ASSERT(BITS_PER_TABLE + BITS_OF_BETA < BITS_ON_CURVE);

#if !defined(__wasm__)
const std::lock_guard<std::mutex> lock(init_mutex);
#endif

if (inited) {
return;
}
Expand Down

0 comments on commit 379a7ce

Please sign in to comment.