forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,474 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/rust_bind.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "rust_bind.hpp" | ||
#include "barretenberg/common/serialize.hpp" | ||
#include "pedersen.hpp" | ||
#include "pedersen_lookup.hpp" | ||
|
||
extern "C" { | ||
|
||
using namespace barretenberg; | ||
|
||
WASM_EXPORT const char* pedersen___init() | ||
{ | ||
try { | ||
crypto::generators::init_generator_data(); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result) | ||
{ | ||
try { | ||
auto lhs = barretenberg::fr::serialize_from_buffer(left); | ||
auto rhs = barretenberg::fr::serialize_from_buffer(right); | ||
auto r = crypto::pedersen_commitment::compress_native({ lhs, rhs }); | ||
barretenberg::fr::serialize_to_buffer(r, result); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result) | ||
{ | ||
try { | ||
auto lhs = barretenberg::fr::serialize_from_buffer(left); | ||
auto rhs = barretenberg::fr::serialize_from_buffer(right); | ||
auto r = crypto::pedersen_commitment::lookup::compress_native({ lhs, rhs }); | ||
barretenberg::fr::serialize_to_buffer(r, result); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
auto r = crypto::pedersen_commitment::compress_native(to_compress); | ||
barretenberg::fr::serialize_to_buffer(r, output); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
auto r = crypto::pedersen_commitment::lookup::compress_native(to_compress); | ||
barretenberg::fr::serialize_to_buffer(r, output); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer, | ||
uint32_t const* hash_index, | ||
fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
auto r = crypto::pedersen_commitment::compress_native(to_compress, *hash_index); | ||
barretenberg::fr::serialize_to_buffer(r, output); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress); | ||
|
||
serialize::write(output, pedersen_hash); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress); | ||
|
||
serialize::write(output, pedersen_hash); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer, | ||
uint32_t const* hash_index, | ||
fr::out_buf output) | ||
{ | ||
try { | ||
std::vector<grumpkin::fq> to_compress; | ||
read(inputs_buffer, to_compress); | ||
grumpkin::g1::affine_element pedersen_hash = | ||
crypto::pedersen_commitment::lookup::commit_native(to_compress, *hash_index); | ||
|
||
serialize::write(output, pedersen_hash); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
|
||
WASM_EXPORT const char* pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r) | ||
{ | ||
try { | ||
std::vector<uint8_t> to_compress; | ||
read(data, to_compress); | ||
auto output = crypto::pedersen_commitment::compress_native(to_compress); | ||
write(r, output); | ||
return nullptr; | ||
} catch (const std::exception& e) { | ||
return e.what(); // return the exception message | ||
} | ||
} | ||
} |
Oops, something went wrong.