diff --git a/packages/ssz/src/type/arrayComposite.ts b/packages/ssz/src/type/arrayComposite.ts index d770c7a5..5a3907a5 100644 --- a/packages/ssz/src/type/arrayComposite.ts +++ b/packages/ssz/src/type/arrayComposite.ts @@ -211,7 +211,7 @@ export function tree_deserializeFromBytesArrayComposite>( +export function value_getBlocksBytesArrayComposite>( elementType: ElementType, length: number, value: ValueOf[], diff --git a/packages/ssz/src/type/bitArray.ts b/packages/ssz/src/type/bitArray.ts index 6027b3f8..0d8fd93b 100644 --- a/packages/ssz/src/type/bitArray.ts +++ b/packages/ssz/src/type/bitArray.ts @@ -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 */ @@ -40,13 +40,13 @@ export abstract class BitArrayType extends CompositeType 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 diff --git a/packages/ssz/src/type/byteArray.ts b/packages/ssz/src/type/byteArray.ts index e4aa8527..db79be48 100644 --- a/packages/ssz/src/type/byteArray.ts +++ b/packages/ssz/src/type/byteArray.ts @@ -89,13 +89,13 @@ export abstract class ByteArrayType extends CompositeType 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 @@ -160,7 +160,7 @@ export abstract class ByteArrayType extends CompositeType blocksBuffer.length) { throw new Error(`data length ${value.length} exceeds blocksBuffer length ${blocksBuffer.length}`); } diff --git a/packages/ssz/src/type/composite.ts b/packages/ssz/src/type/composite.ts index cdd6d96c..8db2fe84 100644 --- a/packages/ssz/src/type/composite.ts +++ b/packages/ssz/src/type/composite.ts @@ -238,7 +238,7 @@ export abstract class CompositeType extends Type { } } - 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); @@ -261,7 +261,7 @@ export abstract class CompositeType extends Type { * 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 diff --git a/packages/ssz/src/type/container.ts b/packages/ssz/src/type/container.ts index b53540be..e9ef58f7 100644 --- a/packages/ssz/src/type/container.ts +++ b/packages/ssz/src/type/container.ts @@ -274,7 +274,7 @@ export class ContainerType>> extends // Merkleization - protected getPaddedBytes64(struct: ValueOfFields): Uint8Array { + protected getBlocksBytes(struct: ValueOfFields): Uint8Array { for (let i = 0; i < this.fieldsEntries.length; i++) { const {fieldName, fieldType} = this.fieldsEntries[i]; fieldType.hashTreeRootInto(struct[fieldName], this.blocksBuffer, i * 32); diff --git a/packages/ssz/src/type/listBasic.ts b/packages/ssz/src/type/listBasic.ts index b776fa75..b31647cb 100644 --- a/packages/ssz/src/type/listBasic.ts +++ b/packages/ssz/src/type/listBasic.ts @@ -210,7 +210,7 @@ export class ListBasicType> } } - protected getPaddedBytes64(value: ValueOf[]): Uint8Array { + protected getBlocksBytes(value: ValueOf[]): Uint8Array { const byteLen = this.value_serializedSize(value); const blockByteLen = Math.ceil(byteLen / 64) * 64; // reallocate this.blocksBuffer if needed diff --git a/packages/ssz/src/type/listComposite.ts b/packages/ssz/src/type/listComposite.ts index 452168aa..2d3ee645 100644 --- a/packages/ssz/src/type/listComposite.ts +++ b/packages/ssz/src/type/listComposite.ts @@ -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"); } diff --git a/packages/ssz/src/type/optional.ts b/packages/ssz/src/type/optional.ts index 36591ba7..dddf74ce 100644 --- a/packages/ssz/src/type/optional.ts +++ b/packages/ssz/src/type/optional.ts @@ -194,7 +194,7 @@ export class OptionalType> extends CompositeTy merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset); } - protected getPaddedBytes64(value: ValueOfType): Uint8Array { + protected getBlocksBytes(value: ValueOfType): Uint8Array { if (value === null) { this.blocksBuffer.fill(0); } else { diff --git a/packages/ssz/src/type/profile.ts b/packages/ssz/src/type/profile.ts index 2df5a438..6d0cd1c9 100644 --- a/packages/ssz/src/type/profile.ts +++ b/packages/ssz/src/type/profile.ts @@ -382,7 +382,7 @@ export class ProfileType>> 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); @@ -391,7 +391,7 @@ export class ProfileType>> extends C } } - protected getPaddedBytes64(struct: ValueOfFields): Uint8Array { + protected getBlocksBytes(struct: ValueOfFields): Uint8Array { this.blocksBuffer.fill(0); for (let i = 0; i < this.fieldsEntries.length; i++) { const {fieldName, fieldType, chunkIndex, optional} = this.fieldsEntries[i]; diff --git a/packages/ssz/src/type/stableContainer.ts b/packages/ssz/src/type/stableContainer.ts index 1d8f8f45..7ffe912d 100644 --- a/packages/ssz/src/type/stableContainer.ts +++ b/packages/ssz/src/type/stableContainer.ts @@ -355,7 +355,7 @@ export class StableContainerType>> 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([ @@ -369,7 +369,7 @@ export class StableContainerType>> e } } - protected getPaddedBytes64(struct: ValueOfFields): Uint8Array { + protected getBlocksBytes(struct: ValueOfFields): Uint8Array { this.blocksBuffer.fill(0); for (let i = 0; i < this.fieldsEntries.length; i++) { const {fieldName, fieldType, optional} = this.fieldsEntries[i]; @@ -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); diff --git a/packages/ssz/src/type/union.ts b/packages/ssz/src/type/union.ts index d0d17417..a70dfa67 100644 --- a/packages/ssz/src/type/union.ts +++ b/packages/ssz/src/type/union.ts @@ -191,7 +191,7 @@ export class UnionType[]> extends CompositeType< merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset); } - protected getPaddedBytes64(value: ValueOfTypes): Uint8Array { + protected getBlocksBytes(value: ValueOfTypes): Uint8Array { this.types[value.selector].hashTreeRootInto(value.value, this.blocksBuffer, 0); return this.blocksBuffer; } diff --git a/packages/ssz/src/type/vectorBasic.ts b/packages/ssz/src/type/vectorBasic.ts index a8ce9249..0f52cf22 100644 --- a/packages/ssz/src/type/vectorBasic.ts +++ b/packages/ssz/src/type/vectorBasic.ts @@ -147,7 +147,7 @@ export class VectorBasicType> // Merkleization - protected getPaddedBytes64(value: ValueOf[]): Uint8Array { + protected getBlocksBytes(value: ValueOf[]): 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); diff --git a/packages/ssz/src/type/vectorComposite.ts b/packages/ssz/src/type/vectorComposite.ts index 75c12090..2c85b238 100644 --- a/packages/ssz/src/type/vectorComposite.ts +++ b/packages/ssz/src/type/vectorComposite.ts @@ -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"; @@ -154,8 +154,8 @@ export class VectorCompositeType< // Merkleization - protected getPaddedBytes64(value: ValueOf[]): Uint8Array { - return value_getPaddedBytes64ArrayComposite(this.elementType, this.length, value, this.blocksBuffer); + protected getBlocksBytes(value: ValueOf[]): Uint8Array { + return value_getBlocksBytesArrayComposite(this.elementType, this.length, value, this.blocksBuffer); } // JSON: inherited from ArrayType diff --git a/packages/ssz/test/spec/runValidTest.ts b/packages/ssz/test/spec/runValidTest.ts index a8e9e67c..d91006f5 100644 --- a/packages/ssz/test/spec/runValidTest.ts +++ b/packages/ssz/test/spec/runValidTest.ts @@ -103,7 +103,7 @@ export function runValidSszTest(type: Type, testData: ValidTestCaseData if (type.isBasic) { console.log("Chunk Bytes Basic", toHexString(type.serialize(testDataValue))); } else { - const blocksBytes = (type as CompositeType)["getPaddedBytes64"](testDataValue); + const blocksBytes = (type as CompositeType)["getBlocksBytes"](testDataValue); console.log("Blocks Bytes Composite", toHexString(blocksBytes)); } }