input-output-hk / input-output-hk/PlutusCoreBlaster
[Bug]: BLS12-381 G1/G2/MlResult memory-size cost constants use raw byte counts, not the word-based convention
- Dominant language
- Lean
- Stars
- 14
- Forks
- 6
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 2
Description
## Description
`constSize` in `PlutusCore/UPLC/CostModels.lean` returns 48/96 for `Bls12_381_G1_element`/`Bls12_381_G2_element`, matching each type's EIP-2537 compressed-serialization byte length. Every other branch of `constSize` (integers, bytestrings) returns a count of 8-byte machine words, matching the convention Haskell's `ExMemoryUsage.hs` uses: its BLS `memoryUsage` instances return `memSizeBytes / 8`, i.e. 18 words for `G1` (144 bytes / 8) and 36 words for `G2` (288 bytes / 8). `MlResult`'s existing value (576) is *also* wrong by the same unit mistake -- it's the byte size, not the word count (72).
## Steps to Reproduce
```lean
import PlutusCore.UPLC.CostModels
open PlutusCore.UPLC.CostModels
-- Any BLS12-381 G1 element; the point's specific coordinates don't matter here.
#eval constSize (.Bls12_381_G1_element (.infinity)) -- currently 48
#eval constSize (.Bls12_381_G2_element (.infinity)) -- currently 96
#eval constSize (.Bls12_381_MlResult (.infinity)) -- currently 576, should be 72
```
## Expected Behavior
`constSize` on a `Bls12_381_G1_element` should return `18` words, on a `Bls12_381_G2_element` should return `36` words, and on a `Bls12_381_MlResult` should return `72` words -- consistent with the word-based convention used everywhere else in `constSize` and with `ExMemoryUsage.hs` in the Haskell reference implementation.
## Actual Behavior
Returns `48` and `96` respectively for G1/G2 -- the EIP-2537 compressed-serialization byte lengths, not word counts. `MlResult` returns `576`, its raw byte size rather than the 72-word count. Currently this has no observable effect on any conformance test, since no cost formula for a BLS12-381 builtin actually reads `constSize`'s `G1`/`G2`/`MlResult` branches (they're all flat-cost, or depend on a different argument's size) -- but it's wrong by the stated convention and would matter if a BLS element were ever placed inside a size-costed generic container (e.g. passed through `MkCons`).
## Lean Version
v4.24.0
## Z3 Version
N/A (no SMT tactics involved)
Contributor guide
No contributing guide indexed for this repository
Research direction
Open PlutusCore/UPLC/CostModels.lean and inspect the constSize branches for Bls12_381_G1_element, Bls12_381_G2_element, and Bls12_381_MlResult. Compare their units with the word-based convention described from ExMemoryUsage.hs, then run the provided #eval examples; done means they return 18, 36, and 72 respectively.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100