diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/barretenberg.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/barretenberg.hpp index 694b73d16e3..329f31bb1ca 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/barretenberg.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/barretenberg.hpp @@ -3,6 +3,7 @@ // External Barretenberg C++ API #include "common/container.hpp" #include "common/map.hpp" +#include "common/mem.hpp" #include "common/serialize.hpp" #include "common/streams.hpp" #include "common/throw_or_abort.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.cpp index c5c648ba9b6..d119eaf24a4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.cpp @@ -2,8 +2,6 @@ #include "./slab_allocator.hpp" #include "./wasm_export.hpp" -extern "C" { - WASM_EXPORT void* bbmalloc(size_t size) { return barretenberg::get_mem_slab_raw(size); @@ -13,4 +11,3 @@ WASM_EXPORT void bbfree(void* ptr) { barretenberg::free_mem_slab_raw(ptr); } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.hpp index 7fc94500f93..c42aa649a81 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/mem.hpp @@ -1,6 +1,7 @@ #pragma once #include "log.hpp" #include "memory.h" +#include "wasm_export.hpp" #include #include // #include @@ -72,4 +73,7 @@ inline void aligned_free(void* mem) // info("Total allocated space (uordblks): ", minfo.uordblks); // info("Total free space (fordblks): ", minfo.fordblks); // info("Top-most, releasable space (keepcost): ", minfo.keepcost); -// } \ No newline at end of file +// } + +WASM_EXPORT void* bbmalloc(size_t size); +WASM_EXPORT void bbfree(void* ptr); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/wasm_export.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/wasm_export.hpp index 7bbe9feb61e..f30c5946489 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/common/wasm_export.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/common/wasm_export.hpp @@ -1,3 +1,4 @@ +#pragma once #ifdef __clang__ #define WASM_EXPORT extern "C" __attribute__((visibility("default"))) __attribute__((annotate("wasm_export"))) #define ASYNC_WASM_EXPORT \ @@ -5,4 +6,4 @@ #else #define WASM_EXPORT extern "C" __attribute__((visibility("default"))) #define ASYNC_WASM_EXPORT extern "C" __attribute__((visibility("default"))) -#endif \ No newline at end of file +#endif diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.cpp index 5524915f7f6..dee106779f2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/aes128/c_bind.cpp @@ -1,8 +1,5 @@ #include "aes128.hpp" - -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { +#include "barretenberg/common/wasm_export.hpp" WASM_EXPORT void aes__encrypt_buffer_cbc(uint8_t* in, uint8_t* iv, const uint8_t* key, const size_t length, uint8_t* r) { @@ -19,4 +16,3 @@ WASM_EXPORT void aes__decrypt_buffer_cbc(uint8_t* in, uint8_t* iv, const uint8_t r[i] = in[i]; } } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/blake3s/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/blake3s/c_bind.cpp index f70e018391c..0b0e996d423 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/blake3s/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/blake3s/c_bind.cpp @@ -1,10 +1,7 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/common/wasm_export.hpp" #include "blake3s.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void blake3s_to_field(uint8_t const* data, size_t length, uint8_t* r) { std::vector inputv(data, data + length); @@ -12,4 +9,3 @@ WASM_EXPORT void blake3s_to_field(uint8_t const* data, size_t length, uint8_t* r auto result = barretenberg::fr::serialize_from_buffer(output.data()); barretenberg::fr::serialize_to_buffer(result, r); } -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp index dbd33004f19..f2dfcceb56c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp @@ -1,10 +1,6 @@ #include "ecdsa.hpp" #include -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void ecdsa__compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) { auto priv_key = from_buffer(private_key); @@ -67,4 +63,3 @@ WASM_EXPORT bool ecdsa__verify_signature(uint8_t const* message, return crypto::ecdsa::verify_signature( std::string((char*)message, msg_len), pubk, sig); } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.h b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.h index 897202a3727..1240b9aee7a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.h +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.h @@ -1,8 +1,5 @@ #include - -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { +#include "barretenberg/common/wasm_export.hpp" WASM_EXPORT void ecdsa__compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf); @@ -26,4 +23,3 @@ WASM_EXPORT bool ecdsa__verify_signature(uint8_t const* message, uint8_t const* sig_r, uint8_t const* sig_s, uint8_t const* sig_v); -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index 4ee21ff4acf..1a174cb64fd 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -5,9 +5,6 @@ #include "barretenberg/common/timer.hpp" #include "pedersen.hpp" #include "pedersen_lookup.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { WASM_EXPORT void pedersen__init() { @@ -100,4 +97,3 @@ WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, u auto output = crypto::pedersen_commitment::compress_native(to_compress); write(r, output); } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index 571cd7936cf..26d5308df70 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -3,9 +3,6 @@ #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/streams.hpp" #include "barretenberg/common/timer.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { WASM_EXPORT void pedersen__init(); @@ -27,4 +24,3 @@ WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_b uint32_t hash_index); WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r); -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index 220887fa2eb..ce31a6928a0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -3,10 +3,6 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) { auto priv_key = from_buffer(private_key); @@ -137,4 +133,3 @@ WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message, return false; } } -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp index ae2c62aeffe..c13acaca124 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp @@ -1,8 +1,5 @@ #include "sha256.hpp" - -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { +#include "barretenberg/common/wasm_export.hpp" WASM_EXPORT void sha256__hash(uint8_t* in, const size_t length, uint8_t* r) { @@ -16,4 +13,3 @@ WASM_EXPORT void sha256__hash(uint8_t* in, const size_t length, uint8_t* r) r[i] = output[i]; } } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp index 73ece155fb7..0fed15bdbc8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp @@ -1,9 +1,6 @@ // TODO: Delete this cbind once funcs working in root cbind of ecc module. #include "grumpkin.hpp" - -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { +#include "barretenberg/common/wasm_export.hpp" WASM_EXPORT void ecc_grumpkin__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) { @@ -50,4 +47,3 @@ WASM_EXPORT void ecc_grumpkin__reduce512_buffer_mod_circuit_modulus(uint8_t* inp uint512_t target_output = bigint_input % barretenberg_modulus; write(result, target_output.lo); } -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp index 8f6d60f897d..8c4e612d847 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp @@ -1,9 +1,5 @@ #include "secp256k1.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) { using serialize::write; @@ -28,4 +24,3 @@ WASM_EXPORT void ecc_secp256k1__reduce512_buffer_mod_circuit_modulus(uint8_t* in uint512_t target_output = bigint_input % barretenberg_modulus; write(result, target_output.lo); } -} \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp index b1b19832393..7b5024ab0e8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.hpp @@ -1,12 +1,7 @@ #include "secp256k1.hpp" -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result); WASM_EXPORT void ecc_secp256k1__get_random_scalar_mod_circuit_modulus(uint8_t* result); WASM_EXPORT void ecc_secp256k1__reduce512_buffer_mod_circuit_modulus(uint8_t* input, uint8_t* result); -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp index b58734e7836..fcddcbfdb94 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp @@ -16,10 +16,6 @@ using namespace barretenberg; using namespace join_split_example::proofs::join_split; -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT void join_split__init_proving_key(bool mock) { init_proving_key(barretenberg::srs::get_crs_factory(), mock); @@ -100,4 +96,3 @@ WASM_EXPORT bool join_split__verify_proof(uint8_t* proof, uint32_t length) plonk::proof pp = { std::vector(proof, proof + length) }; return verify_proof(pp); } -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h b/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h index d952c2af6c2..cd7390b1dad 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h @@ -1,9 +1,3 @@ #include -#define WASM_EXPORT __attribute__((visibility("default"))) - -extern "C" { - WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output); - -} diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp index 6d050a8d79d..18808d3a016 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp @@ -1,7 +1,5 @@ #include "prover.hpp" -#define WASM_EXPORT extern "C" __attribute__((visibility("default"))) - using namespace barretenberg; /** diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/serialize/cbind_fwd.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/serialize/cbind_fwd.hpp index ef5eee9204a..9c218cafff8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/serialize/cbind_fwd.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/serialize/cbind_fwd.hpp @@ -1,9 +1,9 @@ #pragma once #include #include +#include "barretenberg/common/wasm_export.hpp" // CBIND forward declarations for msgback default bind format (encode as tuple of args and return value as msgpack // string) -#define WASM_EXPORT extern "C" __attribute__((visibility("default"))) #define CBIND_DECL(cname) \ WASM_EXPORT void cname( \ diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index 566acf88f84..36c618d3dd9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -77,14 +77,6 @@ template void rightfill_with_zeroleaves(std::vector } // namespace -// Note: We don't have a simple way of calling the barretenberg c-bind. -// Mimic bbmalloc behaviour. -static void* bbmalloc(size_t size) -{ - auto* ptr = aligned_alloc(64, size); - return ptr; -} - /** Copy this string to a bbmalloc'd buffer */ static const char* bbmalloc_copy_string(const char* data, size_t len) {