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: update persistent-merkle-tree 0.6.1 #5969

Merged
merged 6 commits into from
Oct 13, 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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to set as-sha256 as default in the library? Consumers still have the option to use noble but it is then their responsibility and we don't have to make sure it is set correctly in Lodestar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's decided to use noble as default implementation, see ChainSafe/ssz#313


//
// ## 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
Loading