diff --git a/cpp/src/barretenberg/crypto/pedersen_hash/pedersen_lookup.cpp b/cpp/src/barretenberg/crypto/pedersen_hash/pedersen_lookup.cpp index f455c684be..980b41a225 100644 --- a/cpp/src/barretenberg/crypto/pedersen_hash/pedersen_lookup.cpp +++ b/cpp/src/barretenberg/crypto/pedersen_hash/pedersen_lookup.cpp @@ -1,5 +1,7 @@ #include "./pedersen_lookup.hpp" +#include + #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" namespace crypto { @@ -10,6 +12,12 @@ std::array, NUM_PEDERSEN_TABLES> peder std::vector pedersen_iv_table; std::array 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) @@ -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 lock(init_mutex); +#endif + if (inited) { return; }