Skip to content

Commit 62e9a13

Browse files
committed
Revert "Rename 'getBlocksBytes' to 'getPaddedBytes64'"
This reverts commit 15cf649.
1 parent 15cf649 commit 62e9a13

14 files changed

+24
-24
lines changed

packages/ssz/src/type/arrayComposite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function tree_deserializeFromBytesArrayComposite<ElementType extends Comp
211211
}
212212
}
213213

214-
export function value_getPaddedBytes64ArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(
214+
export function value_getBlocksBytesArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(
215215
elementType: ElementType,
216216
length: number,
217217
value: ValueOf<ElementType>[],

packages/ssz/src/type/bitArray.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {CompositeType, LENGTH_GINDEX} from "./composite.js";
44
import {BitArray} from "../value/bitArray.js";
55
import {BitArrayTreeView} from "../view/bitArray.js";
66
import {BitArrayTreeViewDU} from "../viewDU/bitArray.js";
7-
import {getPaddedBytes64} from "./byteArray.js";
7+
import {getBlocksBytes} from "./byteArray.js";
88

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

@@ -40,13 +40,13 @@ export abstract class BitArrayType extends CompositeType<BitArray, BitArrayTreeV
4040

4141
// Merkleization
4242

43-
protected getPaddedBytes64(value: BitArray): Uint8Array {
43+
protected getBlocksBytes(value: BitArray): Uint8Array {
4444
// reallocate this.blocksBuffer if needed
4545
if (value.uint8Array.length > this.blocksBuffer.length) {
4646
const chunkCount = Math.ceil(value.bitLen / 8 / 32);
4747
this.blocksBuffer = new Uint8Array(Math.ceil(chunkCount / 2) * 64);
4848
}
49-
return getPaddedBytes64(value.uint8Array, this.blocksBuffer);
49+
return getBlocksBytes(value.uint8Array, this.blocksBuffer);
5050
}
5151

5252
// Proofs

packages/ssz/src/type/byteArray.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export abstract class ByteArrayType extends CompositeType<ByteArray, ByteArray,
8989

9090
// Merkleization
9191

92-
protected getPaddedBytes64(value: ByteArray): Uint8Array {
92+
protected getBlocksBytes(value: ByteArray): Uint8Array {
9393
// reallocate this.blocksBuffer if needed
9494
if (value.length > this.blocksBuffer.length) {
9595
const chunkCount = Math.ceil(value.length / 32);
9696
this.blocksBuffer = new Uint8Array(Math.ceil(chunkCount / 2) * 64);
9797
}
98-
return getPaddedBytes64(value, this.blocksBuffer);
98+
return getBlocksBytes(value, this.blocksBuffer);
9999
}
100100

101101
// Proofs
@@ -160,7 +160,7 @@ export abstract class ByteArrayType extends CompositeType<ByteArray, ByteArray,
160160
protected abstract assertValidSize(size: number): void;
161161
}
162162

163-
export function getPaddedBytes64(value: Uint8Array, blocksBuffer: Uint8Array): Uint8Array {
163+
export function getBlocksBytes(value: Uint8Array, blocksBuffer: Uint8Array): Uint8Array {
164164
if (value.length > blocksBuffer.length) {
165165
throw new Error(`data length ${value.length} exceeds blocksBuffer length ${blocksBuffer.length}`);
166166
}

packages/ssz/src/type/composite.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export abstract class CompositeType<V, TV, TVDU> extends Type<V> {
238238
}
239239
}
240240

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

266266
// Proofs API
267267

packages/ssz/src/type/container.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class ContainerType<Fields extends Record<string, Type<unknown>>> extends
274274

275275
// Merkleization
276276

277-
protected getPaddedBytes64(struct: ValueOfFields<Fields>): Uint8Array {
277+
protected getBlocksBytes(struct: ValueOfFields<Fields>): Uint8Array {
278278
for (let i = 0; i < this.fieldsEntries.length; i++) {
279279
const {fieldName, fieldType} = this.fieldsEntries[i];
280280
fieldType.hashTreeRootInto(struct[fieldName], this.blocksBuffer, i * 32);

packages/ssz/src/type/listBasic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class ListBasicType<ElementType extends BasicType<unknown>>
210210
}
211211
}
212212

213-
protected getPaddedBytes64(value: ValueOf<ElementType>[]): Uint8Array {
213+
protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array {
214214
const byteLen = this.value_serializedSize(value);
215215
const blockByteLen = Math.ceil(byteLen / 64) * 64;
216216
// reallocate this.blocksBuffer if needed

packages/ssz/src/type/listComposite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class ListCompositeType<
250250
}
251251
}
252252

253-
protected getPaddedBytes64(): Uint8Array {
253+
protected getBlocksBytes(): Uint8Array {
254254
// we use merkleizeBlockArray for hashTreeRoot() computation
255255
throw Error("getBlockBytes should not be called for ListCompositeType");
256256
}

packages/ssz/src/type/optional.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
194194
merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset);
195195
}
196196

197-
protected getPaddedBytes64(value: ValueOfType<ElementType>): Uint8Array {
197+
protected getBlocksBytes(value: ValueOfType<ElementType>): Uint8Array {
198198
if (value === null) {
199199
this.blocksBuffer.fill(0);
200200
} else {

packages/ssz/src/type/profile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
382382
}
383383
}
384384

385-
const blocksBytes = this.getPaddedBytes64(value);
385+
const blocksBytes = this.getBlocksBytes(value);
386386
merkleizeBlocksBytes(blocksBytes, this.maxChunkCount, this.tempRoot, 0);
387387
mixInActiveFields(this.tempRoot, this.activeFields, output, offset);
388388

@@ -391,7 +391,7 @@ export class ProfileType<Fields extends Record<string, Type<unknown>>> extends C
391391
}
392392
}
393393

394-
protected getPaddedBytes64(struct: ValueOfFields<Fields>): Uint8Array {
394+
protected getBlocksBytes(struct: ValueOfFields<Fields>): Uint8Array {
395395
this.blocksBuffer.fill(0);
396396
for (let i = 0; i < this.fieldsEntries.length; i++) {
397397
const {fieldName, fieldType, chunkIndex, optional} = this.fieldsEntries[i];

packages/ssz/src/type/stableContainer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export class StableContainerType<Fields extends Record<string, Type<unknown>>> e
355355
}
356356
}
357357

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

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

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

packages/ssz/src/type/union.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class UnionType<Types extends Type<unknown>[]> extends CompositeType<
191191
merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset);
192192
}
193193

194-
protected getPaddedBytes64(value: ValueOfTypes<Types>): Uint8Array {
194+
protected getBlocksBytes(value: ValueOfTypes<Types>): Uint8Array {
195195
this.types[value.selector].hashTreeRootInto(value.value, this.blocksBuffer, 0);
196196
return this.blocksBuffer;
197197
}

packages/ssz/src/type/vectorBasic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class VectorBasicType<ElementType extends BasicType<unknown>>
147147

148148
// Merkleization
149149

150-
protected getPaddedBytes64(value: ValueOf<ElementType>[]): Uint8Array {
150+
protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array {
151151
const uint8Array = this.blocksBuffer.subarray(0, this.fixedSize);
152152
const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength);
153153
value_serializeToBytesArrayBasic(this.elementType, this.length, {uint8Array, dataView}, 0, value);

packages/ssz/src/type/vectorComposite.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
tree_serializeToBytesArrayComposite,
1414
maxSizeArrayComposite,
1515
minSizeArrayComposite,
16-
value_getPaddedBytes64ArrayComposite,
16+
value_getBlocksBytesArrayComposite,
1717
} from "./arrayComposite.js";
1818
import {ArrayCompositeType, ArrayCompositeTreeView} from "../view/arrayComposite.js";
1919
import {ArrayCompositeTreeViewDU} from "../viewDU/arrayComposite.js";
@@ -154,8 +154,8 @@ export class VectorCompositeType<
154154

155155
// Merkleization
156156

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

161161
// JSON: inherited from ArrayType

packages/ssz/test/spec/runValidTest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function runValidSszTest(type: Type<unknown>, testData: ValidTestCaseData
103103
if (type.isBasic) {
104104
console.log("Chunk Bytes Basic", toHexString(type.serialize(testDataValue)));
105105
} else {
106-
const blocksBytes = (type as CompositeType<unknown, unknown, unknown>)["getPaddedBytes64"](testDataValue);
106+
const blocksBytes = (type as CompositeType<unknown, unknown, unknown>)["getBlocksBytes"](testDataValue);
107107
console.log("Blocks Bytes Composite", toHexString(blocksBytes));
108108
}
109109
}

0 commit comments

Comments
 (0)