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 plookup pedersen methods from c_bind namespace #3033

Merged
merged 6 commits into from
Oct 25, 2023
Merged
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 @@ -12,22 +12,14 @@ WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* r
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;
Expand All @@ -38,12 +30,6 @@ WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer
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,22 +38,6 @@ 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)
{
Expand Down
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,10 @@
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);
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ WASM_EXPORT void pedersen___compress_fields(fr::in_buf left, fr::in_buf right, f
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;
Expand All @@ -29,11 +25,6 @@ WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf o
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)
Expand All @@ -55,23 +46,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 @@ -9,20 +9,14 @@ 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);
}
84 changes: 18 additions & 66 deletions barretenberg/exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@
],
"isAsync": false
},
{
"functionName": "pedersen___plookup_compress_fields",
"inArgs": [
{
"name": "left",
"type": "fr::in_buf"
},
{
"name": "right",
"type": "fr::in_buf"
}
],
"outArgs": [
{
"name": "result",
"type": "fr::out_buf"
}
],
"isAsync": false
},
{
"functionName": "pedersen___compress",
"inArgs": [
Expand All @@ -62,11 +42,15 @@
"isAsync": false
},
{
"functionName": "pedersen___plookup_compress",
"functionName": "pedersen___compress_with_hash_index",
"inArgs": [
{
"name": "inputs_buffer",
"type": "fr::vec_in_buf"
},
{
"name": "hash_index",
"type": "const uint32_t *"
}
],
"outArgs": [
Expand All @@ -78,15 +62,11 @@
"isAsync": false
},
{
"functionName": "pedersen___compress_with_hash_index",
"functionName": "pedersen___commit",
"inArgs": [
{
"name": "inputs_buffer",
"type": "fr::vec_in_buf"
},
{
"name": "hash_index",
"type": "const uint32_t *"
}
],
"outArgs": [
Expand All @@ -98,23 +78,29 @@
"isAsync": false
},
{
"functionName": "pedersen___commit",
"functionName": "pedersen___buffer_to_field",
"inArgs": [
{
"name": "inputs_buffer",
"type": "fr::vec_in_buf"
"name": "data",
"type": "const uint8_t *"
}
],
"outArgs": [
{
"name": "output",
"name": "r",
"type": "fr::out_buf"
}
],
"isAsync": false
},
{
"functionName": "pedersen___plookup_commit",
"functionName": "pedersen_hash_init",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "pedersen_hash",
"inArgs": [
{
"name": "inputs_buffer",
Expand All @@ -130,7 +116,7 @@
"isAsync": false
},
{
"functionName": "pedersen___plookup_commit_with_hash_index",
"functionName": "pedersen_hash_with_hash_index",
"inArgs": [
{
"name": "inputs_buffer",
Expand All @@ -149,28 +135,6 @@
],
"isAsync": false
},
{
"functionName": "pedersen___buffer_to_field",
"inArgs": [
{
"name": "data",
"type": "const uint8_t *"
}
],
"outArgs": [
{
"name": "r",
"type": "fr::out_buf"
}
],
"isAsync": false
},
{
"functionName": "pedersen_hash_init",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "pedersen_hash_pair",
"inArgs": [
Expand Down Expand Up @@ -532,18 +496,6 @@
],
"isAsync": false
},
{
"functionName": "test_thread_abort",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "test_abort",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "common_init_slab_allocator",
"inArgs": [
Expand Down
44 changes: 10 additions & 34 deletions barretenberg/ts/src/barretenberg_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,11 @@ export class BarretenbergApi {
return result[0];
}

async pedersenPlookupCompressFields(left: Fr, right: Fr): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen___compress_fields', [left, right], [Fr]);
return result[0];
}

async pedersenCompress(inputsBuffer: Fr[]): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]);
return result[0];
}

async pedersenPlookupCompress(inputsBuffer: Fr[]): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]);
return result[0];
}

async pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
const result = await this.binder.callWasmExport(
'pedersen___compress_with_hash_index',
Expand All @@ -56,20 +46,6 @@ export class BarretenbergApi {
return result[0];
}

async pedersenPlookupCommit(inputsBuffer: Fr[]): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Fr]);
return result[0];
}

async pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
const result = await this.binder.callWasmExport(
'pedersen___plookup_commit_with_hash_index',
[inputsBuffer, hashIndex],
[Fr],
);
return result[0];
}

async pedersenBufferToField(data: Uint8Array): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen___buffer_to_field', [data], [Fr]);
return result[0];
Expand All @@ -80,6 +56,16 @@ export class BarretenbergApi {
return;
}

async pedersenHash(inputsBuffer: Fr[]): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen_hash', [inputsBuffer], [Fr]);
return result[0];
}

async pedersenHashWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen_hash_with_hash_index', [inputsBuffer, hashIndex], [Fr]);
return result[0];
}

async pedersenHashPair(left: Fr, right: Fr): Promise<Fr> {
const result = await this.binder.callWasmExport('pedersen_hash_pair', [left, right], [Fr]);
return result[0];
Expand Down Expand Up @@ -217,16 +203,6 @@ export class BarretenbergApi {
return result[0];
}

async testThreadAbort(): Promise<void> {
const result = await this.binder.callWasmExport('test_thread_abort', [], []);
return;
}

async testAbort(): Promise<void> {
const result = await this.binder.callWasmExport('test_abort', [], []);
return;
}

async commonInitSlabAllocator(circuitSize: number): Promise<void> {
const result = await this.binder.callWasmExport('common_init_slab_allocator', [circuitSize], []);
return;
Expand Down
Loading