diff --git a/packages/api/package.json b/packages/api/package.json index dc4854448c45..4cddda4b4033 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -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", diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 7af605f6f603..71dc7ec65dea 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -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", diff --git a/packages/cli/package.json b/packages/cli/package.json index ab9e09e39a3c..9cec49cbf419 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/src/applyPreset.ts b/packages/cli/src/applyPreset.ts index f0f784f8ae61..760c18dbbcd7 100644 --- a/packages/cli/src/applyPreset.ts +++ b/packages/cli/src/applyPreset.ts @@ -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 // diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index add49804c9be..5cdccbacfeec 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -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"; diff --git a/packages/light-client/package.json b/packages/light-client/package.json index 3f10ecd67aa4..8a33f2fa862c 100644 --- a/packages/light-client/package.json +++ b/packages/light-client/package.json @@ -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", diff --git a/packages/light-client/src/utils/verifyMerkleBranch.ts b/packages/light-client/src/utils/verifyMerkleBranch.ts index 7cdf673aaf87..87b1d660eb32 100644 --- a/packages/light-client/src/utils/verifyMerkleBranch.ts +++ b/packages/light-client/src/utils/verifyMerkleBranch.ts @@ -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; @@ -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); diff --git a/packages/light-client/test/utils/utils.ts b/packages/light-client/test/utils/utils.ts index c5f5b78afe42..df9bd4170dcc 100644 --- a/packages/light-client/test/utils/utils.ts +++ b/packages/light-client/test/utils/utils.ts @@ -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 { @@ -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}; diff --git a/packages/prover/src/cli/applyPreset.ts b/packages/prover/src/cli/applyPreset.ts index a6a3568c5f91..158e05243ec7 100644 --- a/packages/prover/src/cli/applyPreset.ts +++ b/packages/prover/src/cli/applyPreset.ts @@ -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 // diff --git a/packages/prover/src/cli/index.ts b/packages/prover/src/cli/index.ts index 53a32a02eb87..845831b32cb0 100644 --- a/packages/prover/src/cli/index.ts +++ b/packages/prover/src/cli/index.ts @@ -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"; diff --git a/packages/state-transition/package.json b/packages/state-transition/package.json index 269e8e129f48..ec2b7dfe0b31 100644 --- a/packages/state-transition/package.json +++ b/packages/state-transition/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 03c4f41a0ba9..845284ca8cc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"