From 7287c90fe02c50917929e82619819f0d64ead3fd Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 26 Aug 2026 01:31:58 -0700 Subject: [PATCH] Use constant for output buffer size. --- src/assembly/index.ts | 8 ++++---- src/lib/verify.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/assembly/index.ts b/src/assembly/index.ts index ce0b288..89cfc55 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -12,7 +12,7 @@ export const SIGNATURE_BYTELENGTH: i32 = 64 export const MESSAGE_BUFFER_BYTELENGTH: i32 = BLOCKHASH_BYTELENGTH << 10 export const PRV_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH export const PUB_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH -export const OUTPUT_BUFFER_BYTELENGTH: i32 = 1 << 10 +export const OUTPUT_BUFFER_BYTELENGTH: i32 = 256 export const SIGNATURE_BUFFER_BYTELENGTH: i32 = SIGNATURE_BYTELENGTH // Static I/O buffers @@ -166,7 +166,7 @@ export function verify (mlen: i32): void { const verify_blocks_msg = new StaticArray(BLOCKHASH_BYTELENGTH) const verify_blocks_pub = new StaticArray(KEY_BYTELENGTH) const verify_blocks_sig = new StaticArray(SIGNATURE_BYTELENGTH) -const verify_blocks_out = new StaticArray(256) +const verify_blocks_out = new StaticArray(OUTPUT_BUFFER_BYTELENGTH) /** * Verify a 64-byte detached signature for a 32-byte Nano block hash against a * 32-byte public key. Input parameters are read as bytes from separate buffers. @@ -181,11 +181,11 @@ const verify_blocks_out = new StaticArray(256) * @param {i32} count Number of signatures to verify, up to 256 */ export function verify_blocks (count: i32): void { - if (count < 0 || count > 256) { + if (count < 1 || OUTPUT_BUFFER_BYTELENGTH < count) { PRV_BUFFER.fill(0) PUB_BUFFER.fill(0) MESSAGE_BUFFER.fill(0) - throw new Error('invalid message length') + throw new Error('invalid block count') } // Clear local buffers diff --git a/src/lib/verify.ts b/src/lib/verify.ts index fb51cf9..cc1984e 100644 --- a/src/lib/verify.ts +++ b/src/lib/verify.ts @@ -1,7 +1,7 @@ //! SPDX-FileCopyrightText: 2026 Chris Duncan //! SPDX-License-Identifier: GPL-3.0-or-later -import { BLK_LEN, KEY_LEN, MSG_BUF_LEN, MSG_PTR, OUT_PTR, PUB_PTR, SIG_LEN, SIG_PTR, clear, exports, normalize } from './wasm' +import { BLK_LEN, KEY_LEN, MSG_BUF_LEN, MSG_PTR, OUT_BUF_LEN, OUT_PTR, PUB_PTR, SIG_LEN, SIG_PTR, clear, exports, normalize } from './wasm' export function verify (sig: unknown, msg: unknown, pub: unknown): boolean { let buffer = new Uint8Array(exports.memory.buffer) @@ -33,7 +33,7 @@ export function verify_blocks (pub: unknown, data: unknown): boolean[] { if (count < 1) { throw new RangeError('Must pass at least one block', { cause: data }) } - if (256 < count) { + if (OUT_BUF_LEN < count) { throw new RangeError('Bulk Nano block verification must be no more than 256 blocks', { cause: data }) } const verified = new Uint8Array(count) -- 2.52.0