From 4d5799ed21d74bd34a9cd5013f6f4da49a2d2d09 Mon Sep 17 00:00:00 2001 From: tuyennhv Date: Tue, 19 Sep 2023 13:40:55 +0700 Subject: [PATCH] chore: update to ssz 0.13.0 (#5959) * chore: update to ssz 0.13.0 * chore: use deserializeUint8ArrayBitListFromBytes util from ssz --- packages/api/package.json | 2 +- packages/beacon-node/package.json | 2 +- packages/beacon-node/src/util/sszBytes.ts | 38 +---------------------- packages/cli/package.json | 2 +- packages/config/package.json | 2 +- packages/db/package.json | 2 +- packages/fork-choice/package.json | 2 +- packages/light-client/package.json | 2 +- packages/state-transition/package.json | 2 +- packages/types/package.json | 2 +- packages/validator/package.json | 2 +- yarn.lock | 8 ++--- 12 files changed, 15 insertions(+), 51 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index d495732cbc62..f87de28f0882 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -70,7 +70,7 @@ }, "dependencies": { "@chainsafe/persistent-merkle-tree": "^0.5.0", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/config": "^1.11.1", "@lodestar/params": "^1.11.1", "@lodestar/types": "^1.11.1", diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index ec993ccc1e42..44759696641a 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -104,7 +104,7 @@ "@chainsafe/libp2p-noise": "^13.0.0", "@chainsafe/persistent-merkle-tree": "^0.5.0", "@chainsafe/prometheus-gc-stats": "^1.0.0", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@chainsafe/threads": "^1.11.1", "@ethersproject/abi": "^5.7.0", "@fastify/bearer-auth": "^9.0.0", diff --git a/packages/beacon-node/src/util/sszBytes.ts b/packages/beacon-node/src/util/sszBytes.ts index 46c28f7948fa..0c258df35041 100644 --- a/packages/beacon-node/src/util/sszBytes.ts +++ b/packages/beacon-node/src/util/sszBytes.ts @@ -1,4 +1,4 @@ -import {BitArray} from "@chainsafe/ssz"; +import {BitArray, deserializeUint8ArrayBitListFromBytes} from "@chainsafe/ssz"; import {BLSSignature, RootHex, Slot} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; @@ -210,39 +210,3 @@ function getSlotFromOffset(data: Uint8Array, offset: number): Slot { // Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis return dv.getUint32(offset, true); } - -type BitArrayDeserialized = {uint8Array: Uint8Array; bitLen: number}; - -/** - * This is copied from ssz bitList.ts - * TODO: export this util from there - */ -function deserializeUint8ArrayBitListFromBytes(data: Uint8Array, start: number, end: number): BitArrayDeserialized { - if (end > data.length) { - throw Error(`BitList attempting to read byte ${end} of data length ${data.length}`); - } - - const lastByte = data[end - 1]; - const size = end - start; - - if (lastByte === 0) { - throw new Error("Invalid deserialized bitlist, padding bit required"); - } - - if (lastByte === 1) { - // Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 - const uint8Array = Uint8Array.prototype.slice.call(data, start, end - 1); - const bitLen = (size - 1) * 8; - return {uint8Array, bitLen}; - } - - // the last byte is > 1, so a padding bit will exist in the last byte and need to be removed - // Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 - const uint8Array = Uint8Array.prototype.slice.call(data, start, end); - // mask lastChunkByte - const lastByteBitLength = lastByte.toString(2).length - 1; - const bitLen = (size - 1) * 8 + lastByteBitLength; - const mask = 0xff >> (8 - lastByteBitLength); - uint8Array[size - 1] &= mask; - return {uint8Array, bitLen}; -} diff --git a/packages/cli/package.json b/packages/cli/package.json index 3053484497bb..a4a387fc670b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -59,7 +59,7 @@ "@chainsafe/bls-keystore": "^2.0.0", "@chainsafe/blst": "^0.2.9", "@chainsafe/discv5": "^5.1.0", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@chainsafe/threads": "^1.11.1", "@libp2p/crypto": "^2.0.2", "@libp2p/peer-id": "^3.0.1", diff --git a/packages/config/package.json b/packages/config/package.json index 7113b053f9d3..8fd9bd835b5c 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -64,7 +64,7 @@ "blockchain" ], "dependencies": { - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/params": "^1.11.1", "@lodestar/types": "^1.11.1" } diff --git a/packages/db/package.json b/packages/db/package.json index ea9fecd69079..f9227668e829 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -37,7 +37,7 @@ "check-readme": "typescript-docs-verifier" }, "dependencies": { - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/config": "^1.11.1", "@lodestar/utils": "^1.11.1", "@types/levelup": "^4.3.3", diff --git a/packages/fork-choice/package.json b/packages/fork-choice/package.json index 8565da619c17..0e8de6bf52f5 100644 --- a/packages/fork-choice/package.json +++ b/packages/fork-choice/package.json @@ -38,7 +38,7 @@ "check-readme": "typescript-docs-verifier" }, "dependencies": { - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/config": "^1.11.1", "@lodestar/params": "^1.11.1", "@lodestar/state-transition": "^1.11.1", diff --git a/packages/light-client/package.json b/packages/light-client/package.json index 088a6f37909b..95bca9e36b29 100644 --- a/packages/light-client/package.json +++ b/packages/light-client/package.json @@ -66,7 +66,7 @@ "dependencies": { "@chainsafe/bls": "7.1.1", "@chainsafe/persistent-merkle-tree": "^0.5.0", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/api": "^1.11.1", "@lodestar/config": "^1.11.1", "@lodestar/params": "^1.11.1", diff --git a/packages/state-transition/package.json b/packages/state-transition/package.json index 0302f6f6eaaa..133e149188b7 100644 --- a/packages/state-transition/package.json +++ b/packages/state-transition/package.json @@ -61,7 +61,7 @@ "@chainsafe/bls": "7.1.1", "@chainsafe/persistent-merkle-tree": "^0.5.0", "@chainsafe/persistent-ts": "^0.19.1", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/config": "^1.11.1", "@lodestar/params": "^1.11.1", "@lodestar/types": "^1.11.1", diff --git a/packages/types/package.json b/packages/types/package.json index 5b7a730ef45d..45676cc616f0 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -67,7 +67,7 @@ }, "types": "lib/index.d.ts", "dependencies": { - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/params": "^1.11.1" }, "keywords": [ diff --git a/packages/validator/package.json b/packages/validator/package.json index f634989ac432..ed1433cf48c3 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -49,7 +49,7 @@ ], "dependencies": { "@chainsafe/bls": "7.1.1", - "@chainsafe/ssz": "^0.12.0", + "@chainsafe/ssz": "^0.13.0", "@lodestar/api": "^1.11.1", "@lodestar/config": "^1.11.1", "@lodestar/db": "^1.11.1", diff --git a/yarn.lock b/yarn.lock index 4290e224919a..8d6155b15fec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -644,10 +644,10 @@ "@chainsafe/as-sha256" "^0.4.1" "@chainsafe/persistent-merkle-tree" "^0.6.1" -"@chainsafe/ssz@^0.12.0": - version "0.12.0" - resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.12.0.tgz#60dbbd855d2d39d3bc032f44d18a094c364501ae" - integrity sha512-FZUvB7NsQBQc+/3+QSCaqHjKMAXs+M4NiFsskOcRVm1G2FN19u/Er+783YeIpX8Ld9mLplvn2qv33vQedcul0w== +"@chainsafe/ssz@^0.13.0": + version "0.13.0" + resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.13.0.tgz#0bd11af6abe023d4cc24067a46889dcabbe573e5" + integrity sha512-73PF5bFXE9juLD1+dkmYV/CMO/5ip0TmyzgYw87vAn8Cn+CbwCOp/HyNNdYCmdl104a2bqcORFJzirCvvc+nNw== dependencies: "@chainsafe/as-sha256" "^0.4.1" "@chainsafe/persistent-merkle-tree" "^0.6.1"