UPLC: handle JS boolean in the Bool constant encoder

Aperta Adatta ai principianti
#398 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia in packages/evolution/src/UPLC.ts, nell’encoder di Bool intorno a L954, poi leggi le definizioni di ConstantValue e constantTerm intorno a L194 e L1282 e il decoder intorno a L660. Aggiungi la copertura di regressione descritta nell’issue e verifica che false e true producano byte flat diversi, con false che viene decodificato nell’indice 0.

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

Descrizione

bug external-review

Summary

The flat encoder for a Bool constant reads value.index, but ConstantValue also permits a plain JS boolean. A JS false has no .index, so (false).index === 0n is false and the encoder emits the True bit. con bool false and con bool true then produce identical flat bytes, so a script built from a false boolean computes that constant as true. Narrow in practice (parameter application uses con data, never con bool), but the public type invites the call that triggers it.

Affected

packages/evolution/src/UPLC.ts Bool encoder (L954)
packages/evolution/src/UPLC.ts ConstantValue type (L194), constantTerm (L1282)
decoder representation: UPLC.ts (L660)

Fix

Handle the primitive form the type advertises in the encoder, e.g.
const bit = typeof value === "boolean" ? (value ? 1 : 0) : (value.index === 0n ? 0 : 1)
Or drop boolean from ConstantValue so { index } is the only representation and the footgun cannot typecheck.

Regression test

  • given: a program whose body is constantTerm("Bool", false)
  • before fix: flat(con bool false) === flat(con bool true), and decoding flat(con bool false) yields index 1 (True)
  • after fix: flat(con bool false) !== flat(con bool true), and decoding flat(con bool false) yields index 0 (False)

Must FAIL on main today and PASS after the fix.

Reference

Report 11

Lingua principale
TypeScript
Stelle
22
Fork
30
Merge medio
13h
PR unite (30g)
14

Guida per i contributori

Apri la 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 IntersectMBO/evolution-sdk

Tutte le issue di IntersectMBO/evolution-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.