input-output-hk / input-output-hk/PlutusCoreBlaster

[Bug]: ConstrData does not enforce the Word64 index range under semantics variants D/E

Open
#33 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Lean
Stars
14
Forks
6
Avg merge
4d 8h
Merged PRs (30d)
2

Description

## Description

Since `BuiltinSemanticsVariant` D (introduced with Plutus V3 / Conway), the `ConstrData` builtin is specified to require its constructor-index argument to fit in an (unsigned) `Word64` -- i.e. be in `[0, 2^64 - 1]` -- and fail otherwise, matching the Haskell reference implementation's use of `Word64` for the on-chain `Data`'s `Constr` index. `constrData` in `PlutusCore/UPLC/BuiltinFunctions/Data.lean` previously accepted any `Integer` unconditionally, with no range check and no dependence on the semantics variant at all, so an out-of-range (negative, or `>= 2^64`) index was silently accepted rather than causing the builtin application to fail.

## Steps to Reproduce

```lean
import PlutusCore.UPLC.BuiltinFunctions.Data

open PlutusCore.UPLC.BuiltinFunctions.Data
open PlutusCore.UPLC.CekValue

-- index far outside the Word64 range
#eval constrData .defaultFunSemanticsVariantD
[CekValue.VCon (Const.ConstDataList []), CekValue.VCon (Const.Integer 99999999999999999999)]
```

## Expected Behavior

Under semantics variants D and E, `constrData` should return `none` (builtin failure) when the index is negative or `>= 2^64`. Under variants A/B/C it should keep accepting any `Integer`, matching the pre-Conway behavior.

## Actual Behavior

`constrData` accepted any `Integer` index unconditionally regardless of semantics variant, with no upper- or lower-bound check.

## Lean Version

v4.24.0

## Z3 Version

N/A (no SMT tactics involved)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in PlutusCore/UPLC/BuiltinFunctions/Data.lean at constrData and reproduce the out-of-range example from the issue across the listed semantics variants. Verify that variants D and E fail for negative or >= 2^64 indices while A, B, and C retain the existing behavior, and add or run focused coverage for those cases.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.