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 unecessary calls to pedersen__init #3079

Merged
merged 4 commits into from
Oct 27, 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 @@ -3,8 +3,6 @@
#include "barretenberg/common/serialize.hpp"
#include "pedersen.hpp"

WASM_EXPORT void pedersen__init() {}

WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_commit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
#include "barretenberg/common/streams.hpp"
#include "barretenberg/common/timer.hpp"

WASM_EXPORT void pedersen__init();
WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output);
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ extern "C" {

using namespace barretenberg;

WASM_EXPORT void pedersen___init() {}

WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output)
{
std::vector<grumpkin::fq> to_commit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ 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, affine_element::out_buf output);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

extern "C" {

WASM_EXPORT void pedersen_hash__init() {}

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_hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern "C" {

using namespace barretenberg;

WASM_EXPORT void pedersen_hash_init();
WASM_EXPORT void pedersen_hash_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

extern "C" {

WASM_EXPORT void pedersen_hash_init() {}

WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer,
uint32_t const* hash_index,
uint8_t* output)
Expand Down
12 changes: 0 additions & 12 deletions barretenberg/exports.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[
{
"functionName": "pedersen___init",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "pedersen___commit",
"inArgs": [
Expand All @@ -21,12 +15,6 @@
],
"isAsync": false
},
{
"functionName": "pedersen_hash_init",
"inArgs": [],
"outArgs": [],
"isAsync": false
},
{
"functionName": "pedersen_hash_with_hash_index",
"inArgs": [
Expand Down
10 changes: 0 additions & 10 deletions barretenberg/ts/src/barretenberg_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@ export class BarretenbergApi {
await this.binder.wasm.destroy();
}

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

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

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

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];
Expand Down
1 change: 0 additions & 1 deletion barretenberg/ts/src/barretenberg_api/pedersen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe('pedersen', () => {

beforeAll(async () => {
api = await Barretenberg.new(1);
await api.pedersenHashInit();
}, 30000);

afterAll(async () => {
Expand Down
1 change: 0 additions & 1 deletion barretenberg/ts/src/barretenberg_api/schnorr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('schnorr', () => {

beforeAll(async () => {
api = await Barretenberg.new(1);
await api.pedersenInit();
}, 30000);

afterAll(async () => {
Expand Down
22 changes: 0 additions & 22 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function inputBuffersToOutputBuffer(
* @returns The hash of the transaction request.
*/
export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer {
wasm.call('pedersen__init');
return wasmSyncCall(wasm, 'abis__hash_tx_request', txRequest, 32);
}

Expand Down Expand Up @@ -131,7 +130,6 @@ export function computeFunctionSelector(wasm: IWasmModule, funcSig: string): Buf
* @returns The hash of the verification key.
*/
export function hashVK(wasm: IWasmModule, vkBuf: Buffer) {
wasm.call('pedersen__init');
return wasmSyncCall(wasm, 'abis__hash_vk', vkBuf, 32);
}

Expand All @@ -142,7 +140,6 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) {
* @returns The function leaf.
*/
export function computeFunctionLeaf(wasm: IWasmModule, fnLeaf: FunctionLeafPreimage): Fr {
wasm.call('pedersen__init');
return Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_function_leaf', fnLeaf, 32));
}

Expand All @@ -154,7 +151,6 @@ export function computeFunctionLeaf(wasm: IWasmModule, fnLeaf: FunctionLeafPreim
*/
export function computeFunctionTreeRoot(wasm: IWasmModule, fnLeaves: Fr[]) {
const inputVector = serializeBufferArrayToVector(fnLeaves.map(fr => fr.toBuffer()));
wasm.call('pedersen__init');
const result = wasmSyncCall(wasm, 'abis__compute_function_tree_root', inputVector, 32);
return Fr.fromBuffer(result);
}
Expand All @@ -173,7 +169,6 @@ export function hashConstructor(
argsHash: Fr,
constructorVKHash: Buffer,
): Fr {
wasm.call('pedersen__init');
const result = inputBuffersToOutputBuffer(
wasm,
'abis__hash_constructor',
Expand All @@ -199,7 +194,6 @@ export function computeCompleteAddress(
fnTreeRoot: Fr,
constructorHash: Fr,
): CompleteAddress {
wasm.call('pedersen__init');
return abisComputeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, fnTreeRoot, constructorHash);
}

Expand All @@ -216,7 +210,6 @@ export function computeContractAddressFromPartial(
pubKey: PublicKey,
partialAddress: Fr,
): AztecAddress {
wasm.call('pedersen__init');
const result = inputBuffersToOutputBuffer(
wasm,
'abis__compute_contract_address_from_partial',
Expand All @@ -234,7 +227,6 @@ export function computeContractAddressFromPartial(
* @returns A commitment nonce.
*/
export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, commitmentIndex: number): Fr {
wasm.call('pedersen__init');
return abisComputeCommitmentNonce(wasm, nullifierZero, new Fr(commitmentIndex));
}

Expand All @@ -247,7 +239,6 @@ export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, com
* @returns A siloed commitment.
*/
export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerCommitment: Fr): Fr {
wasm.call('pedersen__init');
return abisSiloCommitment(wasm, contract, innerCommitment);
}

Expand All @@ -259,7 +250,6 @@ export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerC
* @returns A unique commitment.
*/
export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedCommitment: Fr): Fr {
wasm.call('pedersen__init');
return abisComputeUniqueCommitment(wasm, nonce, siloedCommitment);
}

Expand All @@ -272,7 +262,6 @@ export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedComm
* @returns A siloed nullifier.
*/
export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNullifier: Fr): Fr {
wasm.call('pedersen__init');
return abisSiloNullifier(wasm, contract, innerNullifier);
}

Expand All @@ -296,7 +285,6 @@ export function computeBlockHashWithGlobals(
l1ToL2DataTreeRoot: Fr,
publicDataTreeRoot: Fr,
): Fr {
wasm.call('pedersen__init');
return abisComputeBlockHashWithGlobals(
wasm,
globals,
Expand Down Expand Up @@ -328,7 +316,6 @@ export function computeBlockHash(
l1ToL2DataTreeRoot: Fr,
publicDataTreeRoot: Fr,
): Fr {
wasm.call('pedersen__init');
return abisComputeBlockHash(
wasm,
globalsHash,
Expand All @@ -347,7 +334,6 @@ export function computeBlockHash(
* @returns The globals hash.
*/
export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables): Fr {
wasm.call('pedersen__init');
return abisComputeGlobalsHash(wasm, globals);
}

Expand All @@ -359,7 +345,6 @@ export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables):

*/
export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr {
wasm.call('pedersen__init');
return abisComputePublicDataTreeValue(wasm, value);
}

Expand All @@ -372,7 +357,6 @@ export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr {

*/
export function computePublicDataTreeIndex(wasm: IWasmModule, contractAddress: AztecAddress, storageSlot: Fr): Fr {
wasm.call('pedersen__init');
return abisComputePublicDataTreeIndex(wasm, contractAddress, storageSlot);
}

Expand All @@ -389,7 +373,6 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise<Fr> {
if (args.length === 0) return Promise.resolve(Fr.ZERO);
if (args.length > ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT)
throw new Error(`Cannot hash more than ${ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT} arguments`);
wasm.call('pedersen__init');

const wasmComputeVarArgs = (args: Fr[]) =>
Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_var_args_hash', new Vector(args), 32));
Expand All @@ -415,7 +398,6 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise<Fr> {
* @returns The contract leaf.
*/
export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr {
wasm.call('pedersen__init');
const value = wasmSyncCall(wasm, 'abis__compute_contract_leaf', cd, 32);
return Fr.fromBuffer(value);
}
Expand All @@ -427,7 +409,6 @@ export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr
* @returns The transaction hash.
*/
export function computeTxHash(wasm: IWasmModule, txRequest: TxRequest): Fr {
wasm.call('pedersen__init');
const value = wasmSyncCall(wasm, 'abis__compute_transaction_hash', txRequest, 32);
return Fr.fromBuffer(value);
}
Expand Down Expand Up @@ -458,7 +439,6 @@ export function computeCallStackItemHash(
* @returns The call stack item hash.
*/
export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem: PrivateCallStackItem): Fr {
wasm.call('pedersen__init');
const value = wasmSyncCall(wasm, 'abis__compute_private_call_stack_item_hash', callStackItem, 32);
return Fr.fromBuffer(value);
}
Expand All @@ -470,7 +450,6 @@ export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem
* @returns The call stack item hash.
*/
export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: PublicCallStackItem): Fr {
wasm.call('pedersen__init');
const value = wasmSyncCall(wasm, 'abis__compute_public_call_stack_item_hash', callStackItem, 32);
return Fr.fromBuffer(value);
}
Expand All @@ -481,7 +460,6 @@ export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem:
* @returns
*/
export function computeSecretMessageHash(wasm: IWasmModule, secretMessage: Fr) {
wasm.call('pedersen__init');
const value = wasmSyncCall(wasm, 'abis__compute_message_secret_hash', secretMessage, 32);
return Fr.fromBuffer(value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer
* purposes.
*/
export function pedersenHashWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
// If not done already, precompute constants.
wasm.call('pedersen__init');

const data = serializeBufferArrayToVector(inputs);

// WASM gives us 1024 bytes of scratch space which we can use without
Expand Down
3 changes: 0 additions & 3 deletions yarn-project/circuits.js/src/kernel/private_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export { privateKernelSimOrdering, privateKernelSimInit, privateKernelSimInner }
* @returns All of a function tree's nodes.
*/
export function computeFunctionTree(wasm: CircuitsWasm, leaves: Fr[]): Fr[] {
// Init pedersen if needed
wasm.call('pedersen__init');

// Size of the tree is 2^height times size of each element,
// plus 4 for the size used in the std::vector serialization
const outputBufSize = 2 ** (FUNCTION_TREE_HEIGHT + 1) * Fr.SIZE_IN_BYTES + 4;
Expand Down