IntersectMBO / IntersectMBO/evolution-sdk

UPLC: handle JS boolean in the Bool constant encoder

Abierto Apto para principiantes
#398 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug external-review
Lenguaje dominante
TypeScript
Estrellas
22
Forks
30
Merge medio
5 h 29 min
PR fusionados (30 d)
12

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza en packages/evolution/src/UPLC.ts, en el codificador de Bool alrededor de L954; después, lee las definiciones de ConstantValue y constantTerm alrededor de L194 y L1282, y el decodificador alrededor de L660. Añade la cobertura de regresión descrita en el issue y verifica que false y true produzcan bytes flat diferentes, y que false se decodifique como el índice 0.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
78/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.