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 to ssz 0.13.0 #5959

Merged
merged 2 commits into from
Sep 19, 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 @@ -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",
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 @@ -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",
Expand Down
38 changes: 1 addition & 37 deletions packages/beacon-node/src/util/sszBytes.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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};
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/fork-choice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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",
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 @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down