UintNumberType.serialize silently wraps out-of-range values (negative, NaN, overflow)

Aperta
#572 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kutluhaneth46 ci sta già lavorando.

Dal 26/11/2026.

  • #573 di @kutluhaneth46 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript

Direzione di ricerca

Start with the UintNumberType.serialize and value_serializeToBytes paths named in the issue, then compare their range handling with the deserialize guard from #564. Check the corresponding UintBigintType.serialize path as well. Done means out-of-range values are rejected as described; an open linked pull request, #573, is already addressing this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

UintNumberType.serialize / value_serializeToBytes writes through DataView setters with no range check. Out-of-range JS numbers are truncated or wrapped into valid-looking uint bytes instead of throwing.

#564 tightened the deserialize path for values above Number.MAX_SAFE_INTEGER. The serialize path still accepts negatives, non-integers, NaN, and values >= 2^(8*byteLength).

SSZ uintN is [0, 2^N - 1]. Silent wrap means hashTreeRoot / encoding can succeed with the wrong root when a caller passes a bad number.

Version

@chainsafe/[email protected]

Steps to reproduce
import { UintNumberType } from "@chainsafe/ssz";

const u8 = new UintNumberType(1);
const u64 = new UintNumberType(8);

console.log(Array.from(u8.serialize(-1)));   // [255]
console.log(Array.from(u8.serialize(256)));  // [0]
console.log(Array.from(u8.serialize(1.9)));  // [1]
console.log(Array.from(u8.serialize(NaN)));  // [0]
console.log(Array.from(u64.serialize(-1)));  // [255,255,255,255,0,0,0,0]

UintBigintType.serialize has the same wrap behavior for negatives and values past the bit width (for example new UintBigintType(1).serialize(256n) → [0]).

Expected behaviour

Serialize should reject values outside the uint domain (negative, non-integer, NaN, +/-Infinity unless clipInfinity, and >= 2^(8*byteLength)), similar in spirit to the deserialize guard from #564.

Actual behaviour

Serialize succeeds and emits wrapped / truncated bytes. Callers get a plausible encoding with no error.

Lingua principale
TypeScript
Stelle
62
Fork
30
Merge medio
4h 37m
PR unite (30g)
3

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ChainSafe/ssz

Tutte le issue di ChainSafe/ssz

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.