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: automatic c_binds for commit should return a point instead of an Fr element #3072

Merged
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 @@ -9,7 +9,7 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress);
grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_compress);

serialize::write(output, pedersen_hash);
serialize::write(output, pedersen_commitment);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "c_bind_new.hpp"
#include "../pedersen_hash/pedersen.hpp"
#include "barretenberg/common/serialize.hpp"
#include "c_bind.hpp"
#include "pedersen.hpp"

extern "C" {
Expand All @@ -9,12 +9,12 @@ using namespace barretenberg;

WASM_EXPORT void pedersen___init() {}

WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output)
WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress);
grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_compress);

serialize::write(output, pedersen_hash);
serialize::write(output, pedersen_commitment);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once
#include "barretenberg/common/wasm_export.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"

extern "C" {

using namespace barretenberg;
using affine_element = grumpkin::g1::affine_element;

WASM_EXPORT void pedersen___init();

WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output);
WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output);
}
2 changes: 1 addition & 1 deletion barretenberg/exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outArgs": [
{
"name": "output",
"type": "fr::out_buf"
"type": "affine_element::out_buf"
}
],
"isAsync": false
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/ts/src/barretenberg_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class BarretenbergApi {
return;
}

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

Expand Down
9 changes: 7 additions & 2 deletions barretenberg/ts/src/barretenberg_api/pedersen.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Barretenberg } from '../barretenberg/index.js';
import { Fr } from '../types/index.js';
import { Fr, Point } from '../types/index.js';

describe('pedersen', () => {
let api: Barretenberg;
Expand All @@ -20,6 +20,11 @@ describe('pedersen', () => {

it('pedersenCommit', async () => {
const result = await api.pedersenCommit([new Fr(4n), new Fr(8n), new Fr(12n)]);
expect(result).toEqual(new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n));
expect(result).toEqual(
new Point(
new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n),
new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n),
),
);
});
});