IntersectMBO / IntersectMBO/evolution-sdk

UPLC: handle JS boolean in the Bool constant encoder

Offen
#398 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug external-review
Vorherrschende Sprache
TypeScript
Sterne
22
Forks
30
Ø Merge
5 Std. 29 Min.
Gemergte PRs (30 T.)
12

Beschreibung

## 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.