Skip to content

Commit

Permalink
Revert "Rename 'getBlocksBytes' to 'getPaddedBytes64'"
Browse files Browse the repository at this point in the history
This reverts commit 15cf649.
  • Loading branch information
nazarhussain committed Mar 4, 2025
1 parent 15cf649 commit 62e9a13
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/ssz/src/type/arrayComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function tree_deserializeFromBytesArrayComposite<ElementType extends Comp
}
}

export function value_getPaddedBytes64ArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(
export function value_getBlocksBytesArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(
elementType: ElementType,
length: number,
value: ValueOf<ElementType>[],
Expand Down
6 changes: 3 additions & 3 deletions packages/ssz/src/type/bitArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CompositeType, LENGTH_GINDEX} from "./composite.js";
import {BitArray} from "../value/bitArray.js";
import {BitArrayTreeView} from "../view/bitArray.js";
import {BitArrayTreeViewDU} from "../viewDU/bitArray.js";
import {getPaddedBytes64} from "./byteArray.js";
import {getBlocksBytes} from "./byteArray.js";

/* eslint-disable @typescript-eslint/member-ordering */

Expand Down Expand Up @@ -40,13 +40,13 @@ export abstract class BitArrayType extends CompositeType<BitArray, BitArrayTreeV

// Merkleization

protected getPaddedBytes64(value: BitArray): Uint8Array {
protected getBlocksBytes(value: BitArray): Uint8Array {
// reallocate this.blocksBuffer if needed
if (value.uint8Array.length > this.blocksBuffer.length) {
const chunkCount = Math.ceil(value.bitLen / 8 / 32);
this.blocksBuffer = new Uint8Array(Math.ceil(chunkCount / 2) * 64);
}
return getPaddedBytes64(value.uint8Array, this.blocksBuffer);
return getBlocksBytes(value.uint8Array, this.blocksBuffer);
}

// Proofs
Expand Down
6 changes: 3 additions & 3 deletions packages/ssz/src/type/byteArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ export abstract class ByteArrayType extends CompositeType<ByteArray, ByteArray,

// Merkleization

protected getPaddedBytes64(value: ByteArray): Uint8Array {
protected getBlocksBytes(value: ByteArray): Uint8Array {
// reallocate this.blocksBuffer if needed
if (value.length > this.blocksBuffer.length) {
const chunkCount = Math.ceil(value.length / 32);
this.blocksBuffer = new Uint8Array(Math.ceil(chunkCount / 2) * 64);
}
return getPaddedBytes64(value, this.blocksBuffer);
return getBlocksBytes(value, this.blocksBuffer);
}

// Proofs
Expand Down Expand Up @@ -160,7 +160,7 @@ export abstract class ByteArrayType extends CompositeType<ByteArray, ByteArray,
protected abstract assertValidSize(size: number): void;
}

export function getPaddedBytes64(value: Uint8Array, blocksBuffer: Uint8Array): Uint8Array {
export function getBlocksBytes(value: Uint8Array, blocksBuffer: Uint8Array): Uint8Array {
if (value.length > blocksBuffer.length) {
throw new Error(`data length ${value.length} exceeds blocksBuffer length ${blocksBuffer.length}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ssz/src/type/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export abstract class CompositeType<V, TV, TVDU> extends Type<V> {
}
}

const blocksBuffer = this.getPaddedBytes64(value);
const blocksBuffer = this.getBlocksBytes(value);
merkleizeBlocksBytes(blocksBuffer, this.maxChunkCount, output, offset);
if (this.cachePermanentRootStruct) {
cacheRoot(value as ValueWithCachedPermanentRoot, output, offset, safeCache);
Expand All @@ -261,7 +261,7 @@ export abstract class CompositeType<V, TV, TVDU> extends Type<V> {
* Get multiple SHA256 blocks, each is 64 bytes long.
* If chunk count is not even, need to append zeroHash(0)
*/
protected abstract getPaddedBytes64(value: V): Uint8Array;
protected abstract getBlocksBytes(value: V): Uint8Array;

// Proofs API

Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class ContainerType<Fields extends Record<string, Type<unknown>>> extends

// Merkleization

protected getPaddedBytes64(struct: ValueOfFields<Fields>): Uint8Array {
protected getBlocksBytes(struct: ValueOfFields<Fields>): Uint8Array {
for (let i = 0; i < this.fieldsEntries.length; i++) {
const {fieldName, fieldType} = this.fieldsEntries[i];
fieldType.hashTreeRootInto(struct[fieldName], this.blocksBuffer, i * 32);
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/listBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class ListBasicType<ElementType extends BasicType<unknown>>
}
}

protected getPaddedBytes64(value: ValueOf<ElementType>[]): Uint8Array {
protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array {
const byteLen = this.value_serializedSize(value);
const blockByteLen = Math.ceil(byteLen / 64) * 64;
// reallocate this.blocksBuffer if needed
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/listComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class ListCompositeType<
}
}

protected getPaddedBytes64(): Uint8Array {
protected getBlocksBytes(): Uint8Array {
// we use merkleizeBlockArray for hashTreeRoot() computation
throw Error("getBlockBytes should not be called for ListCompositeType");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset);
}

protected getPaddedBytes64(value: ValueOfType<ElementType>): Uint8Array {
protected getBlocksBytes(value: ValueOfType<ElementType>): Uint8Array {
if (value === null) {
this.blocksBuffer.fill(0);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/ssz/src/type/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
}
}

const blocksBytes = this.getPaddedBytes64(value);
const blocksBytes = this.getBlocksBytes(value);
merkleizeBlocksBytes(blocksBytes, this.maxChunkCount, this.tempRoot, 0);
mixInActiveFields(this.tempRoot, this.activeFields, output, offset);

Expand All @@ -391,7 +391,7 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
}
}

protected getPaddedBytes64(struct: ValueOfFields<Fields>): Uint8Array {
protected getBlocksBytes(struct: ValueOfFields<Fields>): Uint8Array {
this.blocksBuffer.fill(0);
for (let i = 0; i < this.fieldsEntries.length; i++) {
const {fieldName, fieldType, chunkIndex, optional} = this.fieldsEntries[i];
Expand Down
6 changes: 3 additions & 3 deletions packages/ssz/src/type/stableContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class StableContainerType<Fields extends Record<string, Type<unknown>>> e
}
}

const blockBytes = this.getPaddedBytes64(value);
const blockBytes = this.getBlocksBytes(value);
merkleizeBlocksBytes(blockBytes, this.maxChunkCount, this.tempRoot, 0);
// compute active field bitvector
const activeFields = BitArray.fromBoolArray([
Expand All @@ -369,7 +369,7 @@ export class StableContainerType<Fields extends Record<string, Type<unknown>>> e
}
}

protected getPaddedBytes64(struct: ValueOfFields<Fields>): Uint8Array {
protected getBlocksBytes(struct: ValueOfFields<Fields>): Uint8Array {
this.blocksBuffer.fill(0);
for (let i = 0; i < this.fieldsEntries.length; i++) {
const {fieldName, fieldType, optional} = this.fieldsEntries[i];
Expand Down Expand Up @@ -823,7 +823,7 @@ export function setActiveField(rootNode: Node, bitLen: number, fieldIndex: numbe
return new BranchNode(rootNode.left, newActiveFieldsNode);
}

// This is a global buffer to avoid creating a new one for each call to getPaddedBytes64
// This is a global buffer to avoid creating a new one for each call to getBlocksBytes
const mixInActiveFieldsBlockBytes = new Uint8Array(64);
const activeFieldsSingleChunk = mixInActiveFieldsBlockBytes.subarray(32);

Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class UnionType<Types extends Type<unknown>[]> extends CompositeType<
merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset);
}

protected getPaddedBytes64(value: ValueOfTypes<Types>): Uint8Array {
protected getBlocksBytes(value: ValueOfTypes<Types>): Uint8Array {
this.types[value.selector].hashTreeRootInto(value.value, this.blocksBuffer, 0);
return this.blocksBuffer;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/src/type/vectorBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class VectorBasicType<ElementType extends BasicType<unknown>>

// Merkleization

protected getPaddedBytes64(value: ValueOf<ElementType>[]): Uint8Array {
protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array {
const uint8Array = this.blocksBuffer.subarray(0, this.fixedSize);
const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength);
value_serializeToBytesArrayBasic(this.elementType, this.length, {uint8Array, dataView}, 0, value);
Expand Down
6 changes: 3 additions & 3 deletions packages/ssz/src/type/vectorComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
tree_serializeToBytesArrayComposite,
maxSizeArrayComposite,
minSizeArrayComposite,
value_getPaddedBytes64ArrayComposite,
value_getBlocksBytesArrayComposite,
} from "./arrayComposite.js";
import {ArrayCompositeType, ArrayCompositeTreeView} from "../view/arrayComposite.js";
import {ArrayCompositeTreeViewDU} from "../viewDU/arrayComposite.js";
Expand Down Expand Up @@ -154,8 +154,8 @@ export class VectorCompositeType<

// Merkleization

protected getPaddedBytes64(value: ValueOf<ElementType>[]): Uint8Array {
return value_getPaddedBytes64ArrayComposite(this.elementType, this.length, value, this.blocksBuffer);
protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array {
return value_getBlocksBytesArrayComposite(this.elementType, this.length, value, this.blocksBuffer);
}

// JSON: inherited from ArrayType
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/test/spec/runValidTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function runValidSszTest(type: Type<unknown>, testData: ValidTestCaseData
if (type.isBasic) {
console.log("Chunk Bytes Basic", toHexString(type.serialize(testDataValue)));
} else {
const blocksBytes = (type as CompositeType<unknown, unknown, unknown>)["getPaddedBytes64"](testDataValue);
const blocksBytes = (type as CompositeType<unknown, unknown, unknown>)["getBlocksBytes"](testDataValue);
console.log("Blocks Bytes Composite", toHexString(blocksBytes));
}
}
Expand Down

0 comments on commit 62e9a13

Please sign in to comment.