Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove redundant methods and use hash instead of compress in the interface #3038

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,7 @@
#include "pedersen.hpp"

WASM_EXPORT void pedersen__init() {}
WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result)
{
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_hash::hash({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
}

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

WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_hash::hash(to_compress);
barretenberg::fr::serialize_to_buffer(r, output);
}
WASM_EXPORT void pedersen_plookup_compress(uint8_t const* inputs_buffer, uint8_t* output)
{
pedersen__compress(inputs_buffer, output);
}
WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
crypto::GeneratorContext<curve::Grumpkin> ctx; // todo fix
ctx.offset = static_cast<size_t>(hash_index);
auto r = crypto::pedersen_hash::hash(to_compress, ctx);
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen_plookup_compress_with_hash_index(uint8_t const* inputs_buffer,
uint8_t* output,
uint32_t hash_index)
{
pedersen__compress_with_hash_index(inputs_buffer, output, hash_index);
}
WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
Expand All @@ -52,26 +13,3 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)

serialize::write(output, pedersen_hash);
}
WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output)
{
pedersen__commit(inputs_buffer, output);
}

WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer,
uint8_t* output,
uint32_t hash_index)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
crypto::GeneratorContext<curve::Grumpkin> ctx;
ctx.offset = hash_index;
auto commitment = crypto::pedersen_commitment::commit_native(to_compress, ctx);
serialize::write(output, commitment);
}

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);
auto output = crypto::pedersen_hash::hash_buffer(to_compress);
write(r, output);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO(@zac-wiliamson #2341 delete this file and rename c_bind_new to c_bind once we have migrated to new hash standard

#pragma once
#include "barretenberg/common/mem.hpp"
#include "barretenberg/common/serialize.hpp"
Expand All @@ -9,20 +7,8 @@
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_plookup_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_plookup_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_plookup_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_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output);
WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer,
uint8_t* output,
uint32_t hash_index);

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r);
WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output);
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,6 @@ using namespace barretenberg;

WASM_EXPORT void pedersen___init() {}

WASM_EXPORT void pedersen___compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result)
{
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_hash::hash({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
}

WASM_EXPORT void pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result)
{
pedersen___compress_fields(left, right, result);
}
WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_hash::hash(to_compress);
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
pedersen___compress(inputs_buffer, output);
}

WASM_EXPORT void pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
const size_t generator_offset = ntohl(*hash_index);
crypto::GeneratorContext<curve::Grumpkin> ctx; // todo fix
ctx.offset = generator_offset;
auto r = crypto::pedersen_hash::hash(to_compress, ctx);
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
std::vector<grumpkin::fq> to_compress;
Expand All @@ -55,23 +17,6 @@ WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf out

serialize::write(output, pedersen_hash);
}
WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
pedersen___commit(inputs_buffer, output);
}

WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
const size_t generator_offset = ntohl(*hash_index);
crypto::GeneratorContext<curve::Grumpkin> ctx;
ctx.offset = generator_offset;
auto commitment = crypto::pedersen_commitment::commit_native(to_compress, ctx);
serialize::write(output, commitment);
}

WASM_EXPORT void pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,7 @@ using namespace barretenberg;

WASM_EXPORT void pedersen___init();

WASM_EXPORT void pedersen___compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result);
WASM_EXPORT void pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result);

WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output);
WASM_EXPORT void pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output);

WASM_EXPORT void pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output);

WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output);
WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output);
WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output);

WASM_EXPORT void pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r);
}
20 changes: 0 additions & 20 deletions barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ WASM_EXPORT void pedersen__hash_with_hash_index(uint8_t const* inputs_buffer,
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen__hash_pair(uint8_t const* left, uint8_t const* right, uint8_t* result)
{
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_hash::hash({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
}

WASM_EXPORT void pedersen__hash_multiple(uint8_t const* inputs_buffer, uint8_t* output)
{
pedersen__hash(inputs_buffer, output);
}

WASM_EXPORT void pedersen__hash_multiple_with_hash_index(uint8_t const* inputs_buffer,
uint32_t const* hash_index,
uint8_t* output)
{
pedersen__hash_with_hash_index(inputs_buffer, hash_index, output);
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ WASM_EXPORT void pedersen_hash_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output);

WASM_EXPORT void pedersen_hash_pair(fr::in_buf left, fr::in_buf right, fr::out_buf result);

WASM_EXPORT void pedersen_hash_multiple(fr::vec_in_buf inputs_buffer, fr::out_buf output);

WASM_EXPORT void pedersen_hash_multiple_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output);

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer,

WASM_EXPORT void pedersen_hash_init() {}

WASM_EXPORT void pedersen_hash_pair(uint8_t const* left, uint8_t const* right, uint8_t* result)
{
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_hash::hash({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
}

WASM_EXPORT void pedersen_hash_multiple(uint8_t const* inputs_buffer, uint8_t* output)
{
pedersen_hash(inputs_buffer, output);
}

WASM_EXPORT void pedersen_hash_multiple_with_hash_index(uint8_t const* inputs_buffer,
uint32_t const* hash_index,
uint8_t* output)
{
pedersen_hash_with_hash_index(inputs_buffer, hash_index, output);
}

/**
* 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.
Expand Down
Loading
Loading