Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 12, 2024
1 parent 20a0ede commit 409143f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';

import { MerkleTree } from './merkle_tree.js';

Expand All @@ -13,7 +12,7 @@ export class MerkleTreeCalculator {
constructor(
private height: number,
zeroLeaf = Buffer.alloc(32),
hasher = (left: Buffer, right: Buffer) => pedersenHash([Fr.fromBuffer(left), Fr.fromBuffer(right)]).toBuffer(),
hasher = (left: Buffer, right: Buffer) => pedersenHash([left, right]).toBuffer(),
) {
this.hasher = hasher;
this.zeroHashes = Array.from({ length: height }).reduce(
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/merkle/sibling_path.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';

/** Computes the expected root of a merkle tree given a leaf and its sibling path. */
export function computeRootFromSiblingPath(
leaf: Buffer,
siblingPath: Buffer[],
index: number,
hasher = (left: Buffer, right: Buffer) => pedersenHash([Fr.fromBuffer(left), Fr.fromBuffer(right)]).toBuffer(),
hasher = (left: Buffer, right: Buffer) => pedersenHash([left, right]).toBuffer(),
) {
let result = leaf;
for (const sibling of siblingPath) {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/crypto/pedersen/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ describe('pedersen', () => {
});

it('pedersen hash', () => {
const r = pedersenHash([1n, 1n]);
const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)]);
expect(r.toString()).toEqual('0x07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b');
});

it('pedersen hash with index', () => {
const r = pedersenHash([1n, 1n], 5);
const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5);
expect(r.toString()).toEqual('0x1c446df60816b897cda124524e6b03f36df0cec333fad87617aab70d7861daa6');
});

Expand Down

0 comments on commit 409143f

Please sign in to comment.