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 unused pedersen c_binds #3058

Merged
merged 31 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84c35f5
remove pedersen_buffer_to_field from cbinds
kevaundray Oct 25, 2023
d74eb76
regenerate bindings
kevaundray Oct 25, 2023
7586a6d
remove test
kevaundray Oct 25, 2023
53c65cd
use compressWIthHashIndex for redundant methods
kevaundray Oct 25, 2023
4954a42
remove pedersenGetHash
kevaundray Oct 25, 2023
3c16824
lint
kevaundray Oct 25, 2023
c3a54d0
add test to show that some methods are all the same
kevaundray Oct 25, 2023
6798941
Merge remote-tracking branch 'origin/master' into kw/pedersen-cleanup…
kevaundray Oct 25, 2023
c1ebc73
rename compress -> hash
kevaundray Oct 25, 2023
18a8e74
rename codebase to use hash
kevaundray Oct 25, 2023
1841760
lint
kevaundray Oct 25, 2023
1095911
fix typos
kevaundray Oct 25, 2023
245e44b
fix typo
kevaundray Oct 25, 2023
362f185
Empty commit
kevaundray Oct 25, 2023
ccd0c96
move output argument to last position to match c_bind_new and other c…
kevaundray Oct 26, 2023
ef27e71
modify calling code to:
kevaundray Oct 26, 2023
0a52d4f
optimize pedersenHash for wasm scratch space
kevaundray Oct 26, 2023
96d4ebd
lint
kevaundray Oct 26, 2023
8f7408a
Merge branch 'master' into kw/pedersen-cleanup-argument-ordering-fix
LeilaWang Oct 26, 2023
3deef57
charlie review: free the allocated input
kevaundray Oct 26, 2023
4a8f73b
Merge branch 'kw/pedersen-cleanup-argument-ordering-fix' into kw/pede…
kevaundray Oct 26, 2023
d8a6917
remove unused cbinds
kevaundray Oct 26, 2023
3aa048c
re-generate bindings
kevaundray Oct 26, 2023
e5c922e
update tests
kevaundray Oct 26, 2023
5a039cb
Merge remote-tracking branch 'origin/master' into kw/pedersen-cleanup…
kevaundray Oct 26, 2023
427d1d9
compress -> hash
kevaundray Oct 26, 2023
6723259
Merge branch 'master' into kw/pedersen-cleanup-remove-unused-cbinds
kevaundray Oct 26, 2023
55a7e87
make pedersen_hash look exactly like pedersen_compress
kevaundray Oct 26, 2023
8ce6c40
remove leftover function definitions from header
kevaundray Oct 26, 2023
36ffe57
Empty commit
kevaundray Oct 26, 2023
5e78f63
chore: remove pedersen getHashTree (#3069)
kevaundray Oct 26, 2023
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,31 +4,6 @@
#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__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__compress_with_hash_index(uint8_t const* inputs_buffer, uint32_t hash_index, uint8_t* output)
{
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__commit(uint8_t const* inputs_buffer, uint8_t* output)
{
Expand All @@ -37,11 +12,4 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress);

serialize::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);
auto output = crypto::pedersen_hash::hash_buffer(to_compress);
write(r, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@
#include "barretenberg/common/timer.hpp"

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, uint32_t hash_index, uint8_t* output);
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);
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +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___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___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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,5 @@ 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___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);
}
61 changes: 4 additions & 57 deletions barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,13 @@ extern "C" {

WASM_EXPORT void pedersen_hash__init() {}

WASM_EXPORT void pedersen__hash(uint8_t const* inputs_buffer, uint8_t* output)
WASM_EXPORT void pedersen__hash_with_hash_index(uint8_t const* inputs_buffer, uint32_t hash_index, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_hash::hash(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);
}
Comment on lines +10 to 18
Copy link
Contributor Author

@kevaundray kevaundray Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous pedersen__hash_with_hash_index was using uint32_t const* hash_index whereas the previous pedersen__compress_with_hash_index was using uint32_t const hash_index -- I set this to match the compress variant, though note its now different to the c_bind_new because they are using uint32_t const*


WASM_EXPORT void pedersen__hash_with_hash_index(uint8_t const* inputs_buffer,
uint32_t const* hash_index,
uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_hash::hash(to_compress, ntohl(*hash_index));
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.
* 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)
{
auto fields = from_buffer<std::vector<grumpkin::fq>>(data);
auto num_outputs = fields.size() * 2 - 1;
fields.reserve(num_outputs);

for (size_t i = 0; fields.size() < num_outputs; i += 2) {
fields.push_back(crypto::pedersen_hash::hash({ fields[i], fields[i + 1] }));
}

auto buf_size = 4 + num_outputs * sizeof(grumpkin::fq);
auto buf = (uint8_t*)aligned_alloc(64, buf_size);
auto dst = &buf[0];
write(dst, fields);

return buf;
}
}
18 changes: 0 additions & 18 deletions barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@ extern "C" {
using namespace barretenberg;

WASM_EXPORT void pedersen_hash_init();
WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, fr::out_buf output);
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.
* e.g.
* input: [1][2][3][4]
* output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]
*/
WASM_EXPORT void pedersen_hash_to_tree(fr::vec_in_buf data, fr::vec_out_buf out);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@

extern "C" {

WASM_EXPORT void pedersen_hash(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_hash_init() {}

Comment on lines +8 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved this to be above pedersen_hash_with_hash_index because thats how it is ordered in the header file

WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer,
uint32_t const* hash_index,
uint8_t* output)
Expand All @@ -21,47 +16,4 @@ WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer,
auto r = crypto::pedersen_hash::hash(to_compress, ntohl(*hash_index));
barretenberg::fr::serialize_to_buffer(r, output);
}

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.
* e.g.
* input: [1][2][3][4]
* output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)]
*
*/
WASM_EXPORT void pedersen_hash_to_tree(fr::vec_in_buf data, fr::vec_out_buf out)
{
auto fields = from_buffer<std::vector<grumpkin::fq>>(data);
auto num_outputs = fields.size() * 2 - 1;
fields.reserve(num_outputs);

for (size_t i = 0; fields.size() < num_outputs; i += 2) {
fields.push_back(crypto::pedersen_hash::hash({ fields[i], fields[i + 1] }));
}

*out = to_heap_buffer(fields);
}
}
Loading