Skip to content

Commit

Permalink
Phil's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 11, 2023
1 parent f446df1 commit 4b722a5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { deserializeArrayFromVector, deserializeField, serializeBufferArrayToVec
* @param lhs - The first hash.
* @param rhs - The second hash.
* @returns The new 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenCompress(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array): Buffer {
// If not done already, precompute constants.
Expand All @@ -30,7 +31,8 @@ export function pedersenCompress(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8A
* @param lhs - The first hash.
* @param rhs - The second hash.
* @returns The new 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer {
// If not done already, precompute constants.
Expand All @@ -46,7 +48,8 @@ export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer
* @param wasm - The barretenberg module.
* @param inputs - The array of buffers to compress.
* @returns The resulting 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenCompressInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer {
// If not done already, precompute constants.
Expand All @@ -62,7 +65,8 @@ export function pedersenCompressInputs(wasm: IWasmModule, inputs: Buffer[]): Buf
* @param wasm - The barretenberg module.
* @param inputs - The array of buffers to compress.
* @returns The resulting 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenPlookupCommitInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer {
// If not done already, precompute constants.
Expand All @@ -79,7 +83,8 @@ export function pedersenPlookupCommitInputs(wasm: IWasmModule, inputs: Buffer[])
* @param inputs - The array of buffers to compress.
* @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum).
* @returns The resulting 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenPlookupCommitWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
// If not done already, precompute constants.
Expand All @@ -96,7 +101,8 @@ export function pedersenPlookupCommitWithHashIndex(wasm: IWasmModule, inputs: Bu
* @param inputs - The array of buffers to compress.
* @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum).
* @returns The resulting 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
// If not done already, precompute constants.
Expand All @@ -113,7 +119,8 @@ export function pedersenCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[
* @param inputs - The array of buffers to compress.
* @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum).
* @returns The resulting 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenPlookupCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
// If not done already, precompute constants.
Expand All @@ -129,7 +136,8 @@ export function pedersenPlookupCompressWithHashIndex(wasm: IWasmModule, inputs:
* @param wasm - The barretenberg module.
* @param data - The data buffer.
* @returns The hash buffer.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenGetHash(wasm: IWasmModule, data: Buffer): Buffer {
// If not done already, precompute constants.
Expand All @@ -152,7 +160,8 @@ export function pedersenGetHash(wasm: IWasmModule, data: Buffer): Buffer {
* @param wasm - The barretenberg module.
* @param values - The 32 byte pedersen leaves.
* @returns A tree represented by an array.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export function pedersenGetHashTree(wasm: IWasmModule, values: Buffer[]) {
// If not done already, precompute constants.
Expand Down
15 changes: 10 additions & 5 deletions yarn-project/merkle-tree/src/pedersen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,39 @@ import { Hasher } from '@aztec/types';

/**
* A helper class encapsulating Pedersen hash functionality.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export class Pedersen implements Hasher {
constructor(private wasm: IWasmModule) {}

/*
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
public compress(lhs: Uint8Array, rhs: Uint8Array): Buffer {
return pedersenCompress(this.wasm, lhs, rhs);
}

/*
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
public compressInputs(inputs: Buffer[]): Buffer {
return pedersenHashInputs(this.wasm, inputs);
}

/*
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
public hashToField(data: Uint8Array): Buffer {
return pedersenGetHash(this.wasm, Buffer.from(data));
}

/*
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
public hashToTree(leaves: Buffer[]): Promise<Buffer[]> {
return Promise.resolve(pedersenGetHashTree(this.wasm, leaves));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Pedersen } from '../../index.js';

/**
* A test utility allowing us to count the number of times the compress function has been called.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
export class PedersenWithCounter extends Pedersen {
/**
Expand All @@ -15,7 +16,8 @@ export class PedersenWithCounter extends Pedersen {
* @param lhs - The first hash.
* @param rhs - The second hash.
* @returns The new 32-byte hash.
* @deprecated Don't call pedersen directly in production code. Instead, create specific nicely-called WASM functions.
* @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific
* purposes.
*/
public compress(lhs: Uint8Array, rhs: Uint8Array): Buffer {
this.compressCounter++;
Expand Down

0 comments on commit 4b722a5

Please sign in to comment.