Skip to content

Commit

Permalink
chore!: remove plookup pedersen methods from c_bind namespace (#3033)
Browse files Browse the repository at this point in the history
These methods do the exact same thing as the methods without the plookup
namespace.

This is here because previously there was a difference between plookup
pedersen and non plookup pedersen.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
kevaundray authored Oct 25, 2023
1 parent 51248b5 commit a8ea391
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 247 deletions.
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

0 comments on commit a8ea391

Please sign in to comment.