Skip to content

Commit

Permalink
chore: update persistent-merkle-tree 0.6.1 (#5969)
Browse files Browse the repository at this point in the history
* feat: migrate @chainsafe/persistent-merkle-tree to 0.6.1

* fix: setHasher first

* chore: move setHasher to applyPreset.ts

* chore: fix applyPreset import

---------

Co-authored-by: Cayman <caymannava@gmail.com>
  • Loading branch information
twoeths and wemeetagain authored Oct 13, 2023
1 parent 48f9a08 commit c6291ad
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"check-readme": "typescript-docs-verifier"
},
"dependencies": {
"@chainsafe/persistent-merkle-tree": "^0.5.0",
"@chainsafe/persistent-merkle-tree": "^0.6.1",
"@chainsafe/ssz": "^0.13.0",
"@lodestar/config": "^1.11.3",
"@lodestar/params": "^1.11.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@chainsafe/discv5": "^5.1.0",
"@chainsafe/libp2p-gossipsub": "^10.1.0",
"@chainsafe/libp2p-noise": "^13.0.0",
"@chainsafe/persistent-merkle-tree": "^0.5.0",
"@chainsafe/persistent-merkle-tree": "^0.6.1",
"@chainsafe/prometheus-gc-stats": "^1.0.0",
"@chainsafe/ssz": "^0.13.0",
"@chainsafe/threads": "^1.11.1",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@chainsafe/discv5": "^5.1.0",
"@chainsafe/ssz": "^0.13.0",
"@chainsafe/threads": "^1.11.1",
"@chainsafe/persistent-merkle-tree": "^0.6.1",
"@libp2p/crypto": "^2.0.2",
"@libp2p/peer-id": "^3.0.1",
"@libp2p/peer-id-factory": "^3.0.2",
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/applyPreset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// MUST import this file first before anything and not import any Lodestar code.

// eslint-disable-next-line no-restricted-imports, import/no-extraneous-dependencies
import {hasher} from "@chainsafe/persistent-merkle-tree/lib/hasher/as-sha256.js";
// eslint-disable-next-line no-restricted-imports, import/no-extraneous-dependencies
import {setHasher} from "@chainsafe/persistent-merkle-tree/lib/hasher/index.js";

// without setting this first, persistent-merkle-tree will use noble instead
setHasher(hasher);

//
// ## Rationale
//
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

// MUST import first to apply preset from args
// MUST import first to apply preset from args and set ssz hasher
import "./applyPreset.js";
import {YargsError} from "./util/index.js";
import {getLodestarCli, yarg} from "./cli.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/light-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"@chainsafe/bls": "7.1.1",
"@chainsafe/persistent-merkle-tree": "^0.5.0",
"@chainsafe/persistent-merkle-tree": "^0.6.1",
"@chainsafe/ssz": "^0.13.0",
"@lodestar/api": "^1.11.3",
"@lodestar/config": "^1.11.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/light-client/src/utils/verifyMerkleBranch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {byteArrayEquals} from "@chainsafe/ssz";
import {hash} from "@chainsafe/persistent-merkle-tree";
import {hasher} from "@chainsafe/persistent-merkle-tree";

export const SYNC_COMMITTEES_DEPTH = 4;
export const SYNC_COMMITTEES_INDEX = 11;
Expand All @@ -20,9 +20,9 @@ export function isValidMerkleBranch(
let value = leaf;
for (let i = 0; i < depth; i++) {
if (Math.floor(index / 2 ** i) % 2) {
value = hash(proof[i], value);
value = hasher.digest64(proof[i], value);
} else {
value = hash(value, proof[i]);
value = hasher.digest64(value, proof[i]);
}
}
return byteArrayEquals(value, root);
Expand Down
6 changes: 3 additions & 3 deletions packages/light-client/test/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bls from "@chainsafe/bls/switchable";
import {PointFormat, PublicKey, SecretKey} from "@chainsafe/bls/types";
import {hash, Tree} from "@chainsafe/persistent-merkle-tree";
import {hasher, Tree} from "@chainsafe/persistent-merkle-tree";
import {BitArray, fromHexString} from "@chainsafe/ssz";
import {BeaconConfig} from "@lodestar/config";
import {
Expand Down Expand Up @@ -235,9 +235,9 @@ export function computeMerkleBranch(
for (let i = 0; i < depth; i++) {
proof[i] = Buffer.alloc(32, i);
if (Math.floor(index / 2 ** i) % 2) {
value = hash(proof[i], value);
value = hasher.digest64(proof[i], value);
} else {
value = hash(value, proof[i]);
value = hasher.digest64(value, proof[i]);
}
}
return {root: value, proof};
Expand Down
9 changes: 9 additions & 0 deletions packages/prover/src/cli/applyPreset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// MUST import this file first before anything and not import any Lodestar code.

// eslint-disable-next-line no-restricted-imports, import/no-extraneous-dependencies
import {hasher} from "@chainsafe/persistent-merkle-tree/lib/hasher/as-sha256.js";
// eslint-disable-next-line no-restricted-imports, import/no-extraneous-dependencies
import {setHasher} from "@chainsafe/persistent-merkle-tree/lib/hasher/index.js";

// without setting this first, persistent-merkle-tree will use noble instead
setHasher(hasher);

//
// ## Rationale
//
Expand Down
2 changes: 1 addition & 1 deletion packages/prover/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

// MUST import first to apply preset from args
// MUST import first to apply preset from args and set ssz hasher
import "./applyPreset.js";
import {YargsError} from "../utils/errors.js";
import {getLodestarProverCli, yarg} from "./cli.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dependencies": {
"@chainsafe/as-sha256": "^0.3.1",
"@chainsafe/bls": "7.1.1",
"@chainsafe/persistent-merkle-tree": "^0.5.0",
"@chainsafe/persistent-merkle-tree": "^0.6.1",
"@chainsafe/persistent-ts": "^0.19.1",
"@chainsafe/ssz": "^0.13.0",
"@lodestar/config": "^1.11.3",
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,6 @@
dependencies:
"@chainsafe/is-ip" "^2.0.1"

"@chainsafe/persistent-merkle-tree@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.5.0.tgz#2b4a62c9489a5739dedd197250d8d2f5427e9f63"
integrity sha512-l0V1b5clxA3iwQLXP40zYjyZYospQLZXzBVIhhr9kDg/1qHZfzzHw0jj4VPBijfYCArZDlPkRi1wZaV2POKeuw==
dependencies:
"@chainsafe/as-sha256" "^0.3.1"

"@chainsafe/persistent-merkle-tree@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.6.1.tgz#37bde25cf6cbe1660ad84311aa73157dc86ec7f2"
Expand Down

0 comments on commit c6291ad

Please sign in to comment.