Skip to content

Commit

Permalink
fix: Ensure barretenberg provides headers that Noir needs (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Mar 8, 2023
1 parent 86a42ed commit 9700900
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 6 deletions.
9 changes: 9 additions & 0 deletions barretenberg/cpp/src/aztec/crypto/blake2s/c_bind.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cstdint>
#include <cstddef>

#define WASM_EXPORT __attribute__((visibility("default")))

extern "C" {

WASM_EXPORT void blake2s_to_field(uint8_t const* data, size_t length, uint8_t* r);
}
12 changes: 11 additions & 1 deletion barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "c_bind.hpp"
#include "pedersen.hpp"
#include <common/serialize.hpp>
#include <common/timer.hpp>
Expand Down Expand Up @@ -36,6 +37,15 @@ WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen::commit_native(to_compress);

write(output, pedersen_hash);
}

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r)
{
std::vector<uint8_t> to_compress(data, data + length);
Expand Down Expand Up @@ -67,4 +77,4 @@ WASM_EXPORT uint8_t* pedersen__hash_to_tree(uint8_t const* data)

return buf;
}
}
}
29 changes: 29 additions & 0 deletions barretenberg/cpp/src/aztec/crypto/pedersen/c_bind.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <common/serialize.hpp>
#include <common/timer.hpp>
#include <common/mem.hpp>
#include <common/streams.hpp>
#define WASM_EXPORT __attribute__((visibility("default")))

extern "C" {

WASM_EXPORT void pedersen__init();

WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result);

WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output);

WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index);

WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output);

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r);

/**
* Given a buffer containing 32 byte pedersen leaves, return a new buffer containing the leaves and all pairs of
* nodes that define a merkle tree.
* e.g.
* input: [1][2][3][4]
* output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]
*/
WASM_EXPORT uint8_t* pedersen__hash_to_tree(uint8_t const* data);
}
39 changes: 39 additions & 0 deletions barretenberg/cpp/src/aztec/crypto/schnorr/c_bind.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <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);
WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output);

WASM_EXPORT void construct_signature(
uint8_t const* message, size_t msg_len, uint8_t const* private_key, uint8_t* s, uint8_t* e);

WASM_EXPORT bool verify_signature(
uint8_t const* message, size_t msg_len, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e);

WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf);

WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf,
uint8_t* combined_key_buf);

WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf,
uint8_t* round_one_private_output_buf);

WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message,
size_t msg_len,
uint8_t* private_key,
uint8_t* signer_round_one_private_buf,
uint8_t* signer_pubkeys_buf,
uint8_t* round_one_public_buf,
uint8_t* round_two_buf);

WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message,
size_t msg_len,
uint8_t* signer_pubkeys_buf,
uint8_t* round_one_buf,
uint8_t* round_two_buf,
uint8_t* s,
uint8_t* e);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "./scalar_multiplication.hpp"
#include "pippenger.hpp"
#include <common/mem.hpp>
#include <srs/io.hpp>
#include "common/mem.hpp"

using namespace barretenberg;

Expand All @@ -20,7 +18,7 @@ WASM_EXPORT void bbfree(void* ptr)
aligned_free(ptr);
}

WASM_EXPORT void* new_pippenger(g1::affine_element* points, size_t num_points)
WASM_EXPORT void* new_pippenger(uint8_t* points, size_t num_points)
{
auto ptr = new scalar_multiplication::Pippenger(points, num_points);
return ptr;
Expand All @@ -47,4 +45,4 @@ WASM_EXPORT void g1_sum(void* points_ptr, const size_t num_points, void* result_
result->self_set_infinity();
*result = std::accumulate(points, points + num_points, *result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <cstddef>
#include "../g1.hpp"

#define WASM_EXPORT __attribute__((visibility("default")))

extern "C" {

WASM_EXPORT void* bbmalloc(size_t size);

WASM_EXPORT void bbfree(void* ptr);

WASM_EXPORT void* new_pippenger(uint8_t* points, size_t num_points);

WASM_EXPORT void delete_pippenger(void* pippenger);

WASM_EXPORT void pippenger_unsafe(void* pippenger_ptr, void* scalars_ptr, size_t from, size_t range, void* result_ptr);
WASM_EXPORT void g1_sum(void* points_ptr, size_t num_points, void* result_ptr);
}

0 comments on commit 9700900

Please sign in to comment.