From 16e70de8bf03398816d0bfd7a1cf692d0449fea3 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 13 May 2025 21:58:48 -0700 Subject: [PATCH] Allow up to 64 bit block number and timestamp Currently no example cases where these values exceed 32 bits but might as well. Currently limited to 64 bits as that is the largest size setter available to DataView. --- calculate.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/calculate.js b/calculate.js index 9870112..a0b57f7 100644 --- a/calculate.js +++ b/calculate.js @@ -12,8 +12,8 @@ function arr(hex) { // Number to Uint8Array (big-endian) function arrBE(n) { - const v = new DataView(new ArrayBuffer(4)); - v.setUint32(0, Number(n), false); + const v = new DataView(new ArrayBuffer(8)); + v.setBigUint64(0, BigInt(n), false); return new Uint8Array(v.buffer); } @@ -141,8 +141,8 @@ function calculateZkSync(block) { // Since each value is equal to or less than 32 bytes, abi.encode just gives each value a 32-byte slot (big-endian) const data = new Uint8Array(32 * 4); - data.set(arrBE(block.number), 32 - 4); - data.set(arrBE(block.timestamp), 32 * 2 - 4); + data.set(arrBE(block.number), 32 - 8); + data.set(arrBE(block.timestamp), 32 * 2 - 8); data.set(arr(block.parentHash), 32 * 2); // block.parentHash data.set(blockTxsRollingHash(block.transactions), 32 * 3); // blockTxsRollingHash -- 2.47.3