Skip to content
Open
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 biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// https://github.com/ChainSafe/ssz/pull/475#discussion_r1995814916
"useNumberNamespace": "off",
// TODO: There are two many usages, will fix in separate PR
"noParameterAssign": "off",
"noParameterAssign": "warn",
// We use to export types and object without differentiating
"useExportType": "off",
// We use to import types and object without differentiating
Expand Down
10 changes: 6 additions & 4 deletions packages/persistent-merkle-tree/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ export class LeafNode extends Node {
}
}

setUintBigint(uintBytes: number, offsetBytes: number, valueBN: bigint): void {
setUintBigint(uintBytes: number, offsetBytes: number, _valueBN: bigint): void {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see valueBN is been reassigned anywhere in this function. Also primitives as parameters is not an issue to be assigned anyway.

Copy link
Copy Markdown
Author

@ChefBingbong ChefBingbong Jun 18, 2025

Choose a reason for hiding this comment

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

Hi there @nazarhussain . thanks for your comment. Actually it is being reassigned here

https://github.com/ChefBingbong/ssz/blob/53591ed4ca031dee9f1305c775eab4096675568c/packages/persistent-merkle-tree/src/node.ts#L289

in the last else of the function.

also this pr tackles this issue. so this is the motivation behind these changes

ssz/biome.jsonc

Lines 19 to 20 in 1a34fe8

// TODO: There are two many usages, will fix in separate PR
"noParameterAssign": "off",

re-enabling this biome flag requires these locations (i.e this prs changes) to be fixed. however i made sure that the the changes are compatabile with the current test suiting and dont change expected code functionality

const hIndex = Math.floor(offsetBytes / 4);

// number has to be masked from an h value
if (uintBytes < 4) {
const value = Number(valueBN);
const value = Number(_valueBN);
const bitIndex = (offsetBytes % 4) * 8;
let h = getNodeH(this, hIndex);
if (uintBytes === 1) {
Expand All @@ -277,11 +277,12 @@ export class LeafNode extends Node {

// number equals the h value
else if (uintBytes === 4) {
setNodeH(this, hIndex, Number(valueBN));
setNodeH(this, hIndex, Number(_valueBN));
}

// number spans multiple h values
else {
let valueBN = _valueBN;
const hEnd = hIndex + Math.ceil(uintBytes / 4);
for (let i = hIndex; i < hEnd; i++) {
setNodeH(this, i, Number(valueBN & BigInt(0xffffffff)));
Expand All @@ -290,8 +291,9 @@ export class LeafNode extends Node {
}
}

bitwiseOrUint(uintBytes: number, offsetBytes: number, value: number): void {
bitwiseOrUint(uintBytes: number, offsetBytes: number, _value: number): void {
const hIndex = Math.floor(offsetBytes / 4);
let value = _value;

// number has to be masked from an h value
if (uintBytes < 4) {
Expand Down
4 changes: 3 additions & 1 deletion packages/persistent-merkle-tree/src/proof/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export function createSingleProof(rootNode: Node, index: Gindex): [Uint8Array, U
return [node.root, witnesses.reverse()];
}

export function createNodeFromSingleProof(gindex: Gindex, leaf: Uint8Array, witnesses: Uint8Array[]): Node {
export function createNodeFromSingleProof(_gindex: Gindex, leaf: Uint8Array, witnesses: Uint8Array[]): Node {
let node: Node = LeafNode.fromRoot(leaf);
const w = witnesses.slice().reverse();
let gindex: Gindex = _gindex;

while (gindex > 1) {
const sibling = LeafNode.fromRoot(w.pop() as Uint8Array);
if (gindex % BigInt(2) === BigInt(0)) {
Expand Down
4 changes: 3 additions & 1 deletion packages/persistent-merkle-tree/src/subtree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {HashComputationLevel, getHashComputations, levelAtIndex} from "./hashCom
import {BranchNode, Node} from "./node.ts";
import {zeroNode} from "./zeroNode.ts";

export function subtreeFillToDepth(bottom: Node, depth: number): Node {
export function subtreeFillToDepth(bottom: Node, _depth: number): Node {
let node = bottom;
let depth = _depth;

while (depth > 0) {
node = new BranchNode(node, node);
depth--;
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/type/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ export function tree_serializeToBytesArrayComposite<ElementType extends Composit
depth: number,
node: Node,
output: ByteViews,
offset: number,
_offset: number,
cachedNodes: Node[] | null = null
): number {
let offset = _offset;
const nodes = cachedNodes ?? getNodesAtDepth(node, depth, 0, length);

// Variable Length
Expand Down
6 changes: 4 additions & 2 deletions packages/ssz/src/type/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
return variableIndex;
}

value_deserializeFromBytes(data: ByteViews, start: number, end: number): ValueOfFields<Fields> {
value_deserializeFromBytes(data: ByteViews, _start: number, end: number): ValueOfFields<Fields> {
let start = _start;
const {optionalFields, fieldRanges} = this.getFieldRanges(data, start, end);
const value = {} as {[K in keyof Fields]: unknown};
const optionalFieldsLen = optionalFields.uint8Array.length;
Expand Down Expand Up @@ -349,7 +350,8 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
return variableIndex;
}

tree_deserializeFromBytes(data: ByteViews, start: number, end: number): Node {
tree_deserializeFromBytes(data: ByteViews, _start: number, end: number): Node {
let start = _start;
const {optionalFields, fieldRanges} = this.getFieldRanges(data, start, end);
const nodes = new Array<Node>(this.activeFields.bitLen).fill(zeroNode(0));
const optionalFieldsLen = optionalFields.uint8Array.length;
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/type/uint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ export class UintBigintType extends BasicType<bigint> {

// Serialization + deserialization

value_serializeToBytes({dataView}: ByteViews, offset: number, value: bigint): number {
value_serializeToBytes({dataView}: ByteViews, offset: number, _value: bigint): number {
let value = _value;
switch (this.byteLength) {
case 1:
dataView.setInt8(offset, Number(value));
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/util/byteArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function toHexString(bytes: Uint8Array | ByteVector): string {
return hex;
}

export function fromHexString(hex: string): Uint8Array {
export function fromHexString(_hex: string): Uint8Array {
let hex = _hex;
if (typeof hex !== "string") {
throw new Error(`hex argument type ${typeof hex} must be of type string`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ function isCompositeType(type: Type): type is CompositeType {
*
* @param bitstring Bitstring without the leading "1", since it's only used to compute horizontal indexes.
*/
export function treePostProcessFromProofNode(node: Node, type: CompositeType, bitstring = "", currentDepth = 0): Node {
export function treePostProcessFromProofNode(_node: Node, type: CompositeType, bitstring = "", currentDepth = 0): Node {
// Must run tree_fromProofNode on the first received node (i.e. Validator object)
let node: Node = _node;
if (currentDepth === 0) {
const nodePost = type.tree_fromProofNode(node);
if (nodePost.done) return nodePost.node;
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/view/arrayBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class ArrayBasicTreeView<ElementType extends BasicType<unknown>> extends
* Get all values of this array as Basic element type values, from index zero to `this.length - 1`
* @param values optional output parameter, if is provided it must be an array of the same length as this array
*/
getAll(values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
getAll(_values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
let values = _values;
if (values && values.length !== this.length) {
throw Error(`Expected ${this.length} values, got ${values.length}`);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/ssz/src/view/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export class ArrayCompositeTreeView<
* propagated upwards. To get linked element Views use `this.get()`
* @param views optional output parameter, if is provided it must be an array of the same length as this array
*/
getAllReadonly(views?: CompositeView<ElementType>[]): CompositeView<ElementType>[] {
getAllReadonly(_views?: CompositeView<ElementType>[]): CompositeView<ElementType>[] {
let views = _views;
if (views && views.length !== this.length) {
throw Error(`Expected ${this.length} views, got ${views.length}`);
}
Expand All @@ -99,7 +100,8 @@ export class ArrayCompositeTreeView<
* To get linked element Views use `this.get()`
* @param values optional output parameter, if is provided it must be an array of the same length as this array
*/
getAllReadonlyValues(values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
getAllReadonlyValues(_values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
let values = _values;
if (values && values.length !== this.length) {
throw Error(`Expected ${this.length} values, got ${values.length}`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/viewDU/arrayBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export class ArrayBasicTreeViewDU<ElementType extends BasicType<unknown>> extend
* Get all values of this array as Basic element type values, from index zero to `this.length - 1`
* @param values optional output parameter, if is provided it must be an array of the same length as this array
*/
getAll(values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
getAll(_values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
let values = _values;
if (values && values.length !== this._length) {
throw Error(`Expected ${this._length} values, got ${values.length}`);
}
Expand Down
9 changes: 6 additions & 3 deletions packages/ssz/src/viewDU/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export class ArrayCompositeTreeViewDU<
* No need to commit() before calling this function.
* @param views optional output parameter, if is provided it must be an array of the same length as this array
*/
getAllReadonly(views?: CompositeViewDU<ElementType>[]): CompositeViewDU<ElementType>[] {
getAllReadonly(_views?: CompositeViewDU<ElementType>[]): CompositeViewDU<ElementType>[] {
let views = _views;
if (views && views.length !== this._length) {
throw Error(`Expected ${this._length} views, got ${views.length}`);
}
Expand Down Expand Up @@ -179,7 +180,8 @@ export class ArrayCompositeTreeViewDU<
* WARNING: Returns all commited changes, if there are any pending changes commit them beforehand
* @param values optional output parameter, if is provided it must be an array of the same length as this array
*/
getAllReadonlyValues(values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
getAllReadonlyValues(_values?: ValueOf<ElementType>[]): ValueOf<ElementType>[] {
let values = _values;
if (values && values.length !== this._length) {
throw Error(`Expected ${this._length} values, got ${values.length}`);
}
Expand All @@ -206,7 +208,8 @@ export class ArrayCompositeTreeViewDU<
* Get by range of indexes. Returns an array of views of the Composite element type.
* This is similar to getAllReadonly() where we dont have to commit() before calling this function.
*/
getReadonlyByRange(startIndex: number, count: number): CompositeViewDU<ElementType>[] {
getReadonlyByRange(startIndex: number, _count: number): CompositeViewDU<ElementType>[] {
let count = _count;
if (startIndex < 0) {
throw Error(`Error getting by range, startIndex < 0: ${startIndex}`);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ssz/src/viewDU/listComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export class ListCompositeTreeViewDU<
* Note: If index === n, returns an empty list of length 0
*
*/
sliceFrom(index: number): this {
sliceFrom(_index: number): this {
let index = _index;
// Commit before getting rootNode to ensure all pending data is in the rootNode
this.commit();
// populate to `this.nodes` to ensure all nodes are loaded
Expand Down
6 changes: 4 additions & 2 deletions packages/ssz/test/lodestarTypes/phase0/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export class ValidatorNodeStructType extends ContainerNodeStructType<typeof Vali

value_serializeToBytes(
{uint8Array: output, dataView}: ByteViews,
offset: number,
_offset: number,
validator: ValueOfFields<typeof ValidatorType>
): number {
let offset = _offset;
output.set(validator.pubkey, offset);
offset += PUBKEY_SIZE;
output.set(validator.withdrawalCredentials, offset);
Expand Down Expand Up @@ -115,7 +116,8 @@ export function validatorToChunkBytes(
writeEpochInf(dataView, offset, withdrawableEpoch);
}

function writeEpochInf(dataView: DataView, offset: number, value: number): number {
function writeEpochInf(dataView: DataView, _offset: number, value: number): number {
let offset = _offset;
if (value === Infinity) {
dataView.setUint32(offset, 0xffffffff, true);
offset += UINT32_SIZE;
Expand Down
11 changes: 8 additions & 3 deletions packages/ssz/test/unit/byType/runTypeProofTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ function getJsonPathsFromValue(value: unknown, parentPath: JsonPath = [], jsonPa
/**
* Returns the end type of a JSON path
*/
function getJsonPathType(type: CompositeTypeAny, jsonPath: JsonPath): Type<unknown> {
function getJsonPathType(_type: CompositeTypeAny, jsonPath: JsonPath): Type<unknown> {
let type = _type;
for (const jsonProp of jsonPath) {
type = type.getPropertyType(jsonProp) as CompositeTypeAny;
}
Expand All @@ -114,7 +115,9 @@ function getJsonPathType(type: CompositeTypeAny, jsonPath: JsonPath): Type<unkno
* Requires the type to coerce jsonProp to a fieldName.
* JSON paths may be in JSON notation or fieldName notation
*/
function getJsonPathView(type: Type<unknown>, view: unknown, jsonPath: JsonPath): unknown {
function getJsonPathView(_type: Type<unknown>, _view: unknown, jsonPath: JsonPath): unknown {
let type = _type;
let view = _view;
for (const jsonProp of jsonPath) {
if (type instanceof OptionalType) {
type = type.elementType;
Expand Down Expand Up @@ -146,7 +149,9 @@ function getJsonPathView(type: Type<unknown>, view: unknown, jsonPath: JsonPath)
* Requires the type to coerce jsonProp to a fieldName.
* JSON paths may be in JSON notation or fieldName notation
*/
function getJsonPathValue(type: Type<unknown>, json: unknown, jsonPath: JsonPath): unknown {
function getJsonPathValue(_type: Type<unknown>, _json: unknown, jsonPath: JsonPath): unknown {
let type = _type;
let json = _json;
for (const jsonProp of jsonPath) {
if (type instanceof OptionalType) {
type = type.elementType;
Expand Down