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 unused pedersen c_binds #3058

Merged
merged 31 commits into from
Oct 26, 2023
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84c35f5
remove pedersen_buffer_to_field from cbinds
kevaundray Oct 25, 2023
d74eb76
regenerate bindings
kevaundray Oct 25, 2023
7586a6d
remove test
kevaundray Oct 25, 2023
53c65cd
use compressWIthHashIndex for redundant methods
kevaundray Oct 25, 2023
4954a42
remove pedersenGetHash
kevaundray Oct 25, 2023
3c16824
lint
kevaundray Oct 25, 2023
c3a54d0
add test to show that some methods are all the same
kevaundray Oct 25, 2023
6798941
Merge remote-tracking branch 'origin/master' into kw/pedersen-cleanup…
kevaundray Oct 25, 2023
c1ebc73
rename compress -> hash
kevaundray Oct 25, 2023
18a8e74
rename codebase to use hash
kevaundray Oct 25, 2023
1841760
lint
kevaundray Oct 25, 2023
1095911
fix typos
kevaundray Oct 25, 2023
245e44b
fix typo
kevaundray Oct 25, 2023
362f185
Empty commit
kevaundray Oct 25, 2023
ccd0c96
move output argument to last position to match c_bind_new and other c…
kevaundray Oct 26, 2023
ef27e71
modify calling code to:
kevaundray Oct 26, 2023
0a52d4f
optimize pedersenHash for wasm scratch space
kevaundray Oct 26, 2023
96d4ebd
lint
kevaundray Oct 26, 2023
8f7408a
Merge branch 'master' into kw/pedersen-cleanup-argument-ordering-fix
LeilaWang Oct 26, 2023
3deef57
charlie review: free the allocated input
kevaundray Oct 26, 2023
4a8f73b
Merge branch 'kw/pedersen-cleanup-argument-ordering-fix' into kw/pede…
kevaundray Oct 26, 2023
d8a6917
remove unused cbinds
kevaundray Oct 26, 2023
3aa048c
re-generate bindings
kevaundray Oct 26, 2023
e5c922e
update tests
kevaundray Oct 26, 2023
5a039cb
Merge remote-tracking branch 'origin/master' into kw/pedersen-cleanup…
kevaundray Oct 26, 2023
427d1d9
compress -> hash
kevaundray Oct 26, 2023
6723259
Merge branch 'master' into kw/pedersen-cleanup-remove-unused-cbinds
kevaundray Oct 26, 2023
55a7e87
make pedersen_hash look exactly like pedersen_compress
kevaundray Oct 26, 2023
8ce6c40
remove leftover function definitions from header
kevaundray Oct 26, 2023
36ffe57
Empty commit
kevaundray Oct 26, 2023
5e78f63
chore: remove pedersen getHashTree (#3069)
kevaundray Oct 26, 2023
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
Prev Previous commit
Next Next commit
rename compress -> hash
kevaundray committed Oct 25, 2023
commit c1ebc734a33b1bee57bd560ffa066a7098b2e3b8
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@ import { Buffer } from 'buffer';
import { deserializeArrayFromVector, deserializeField, serializeBufferArrayToVector } from '../../serialize.js';

/**
* Compresses two 32-byte hashes.
* Hashes two 32-byte hashes.
* @param wasm - The barretenberg module.
* @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 suitably-named functions for specific
* purposes.
*/
export function pedersenCompress(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array): Buffer {
return pedersenCompressWithHashIndex(wasm, [Buffer.from(lhs), Buffer.from(rhs)], 0);
export function pedersenHash(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array): Buffer {
return pedersenHashWithHashIndex(wasm, [Buffer.from(lhs), Buffer.from(rhs)], 0);
}

/**
@@ -27,31 +27,19 @@ export function pedersenCompress(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8A
* purposes.
*/
export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer {
return pedersenCompressWithHashIndex(wasm, inputs, 0);
return pedersenHashWithHashIndex(wasm, inputs, 0);
}

/**
* Compresses an array of buffers.
* Hashes an array of buffers.
* @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 suitably-named functions for specific
* purposes.
*/
export function pedersenCompressInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer {
return pedersenCompressWithHashIndex(wasm, inputs, 0);
}

/**
* Compresses an array of buffers.
* @param wasm - The barretenberg module.
* @param inputs - The array of buffers to compress.
* @param inputs - The array of buffers to hash.
* @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 suitably-named functions for specific
* purposes.
*/
export function pedersenCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
export function pedersenHashWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer {
// If not done already, precompute constants.
wasm.call('pedersen__init');
const inputVectors = serializeBufferArrayToVector(inputs);
@@ -66,7 +54,7 @@ export function pedersenCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[
*
* E.g.
* Input: [1][2][3][4]
* Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)].
* Output: [1][2][3][4][hash(1,2)][hash(3,4)][hash(5,6)].
*
* @param wasm - The barretenberg module.
* @param values - The 32 byte pedersen leaves.
8 changes: 4 additions & 4 deletions yarn-project/merkle-tree/src/pedersen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pedersenCompress, pedersenGetHashTree, pedersenHashInputs } from '@aztec/circuits.js/barretenberg';
import { pedersenHash, pedersenGetHashTree, pedersenHashInputs } from '@aztec/circuits.js/barretenberg';
import { IWasmModule } from '@aztec/foundation/wasm';
import { Hasher } from '@aztec/types';

@@ -14,15 +14,15 @@ export class Pedersen implements Hasher {
* @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);
public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer {
return pedersenHash(this.wasm, lhs, rhs);
}

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

16 changes: 8 additions & 8 deletions yarn-project/types/src/interfaces/hasher.ts
Original file line number Diff line number Diff line change
@@ -3,27 +3,27 @@
*/
export interface Hasher {
/**
* Compresses two 32-byte hashes.
* @param lhs - The first hash.
* @param rhs - The second hash.
* Hash two 32-byte hashes.
* @param lhs - The first 32-byte array.
* @param rhs - The second 32-byte array.
* @returns The new 32-byte hash.
*/
compress(lhs: Uint8Array, rhs: Uint8Array): Buffer;
hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;

/**
* Compresses an array of buffers.
* @param inputs - The array of buffers to compress.
* Hashes an array of buffers.
* @param inputs - The array of buffers to hash.
* @returns The resulting 32-byte hash.
*/
compressInputs(inputs: Buffer[]): Buffer;
hashInputs(inputs: Buffer[]): Buffer;

/**
* Given a buffer containing 32 byte leaves, return a new buffer containing the leaves and all pairs of
* nodes that define a merkle tree.
*
* E.g.
* Input: [1][2][3][4]
* Output: [1][2][3][4][compress(1,2)][compress(3,4)][compress(5,6)].
* Output: [1][2][3][4][hash(1,2)][hash(3,4)][hash(5,6)].
*
* @param leaves - The 32 byte leaves.
* @returns A tree represented by an array.