IntersectMBO / IntersectMBO/plutus

Decide: require explicit size-measure wrappers for `Value` in builtin denotations

Open
#7,934 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.6k
Forks
508
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Costing now has three size measures for `Value`: `ValueTotalSize`, `ValueOuterSize` and `ValueMaxDepth` (in `PlutusCore.Evaluation.Machine.ExMemoryUsage`), plus a bare `instance ExMemoryUsage Value` that silently defaults to `ValueTotalSize`. Some denotations use the wrappers, but `assetCount`, `keepPolicies` and `dropPolicies` take bare `Value`, so the size measure of an argument is not visible at the use site, and a wrapper mismatch between a denotation and its budgeting benchmark produces a silently wrong cost model (see Note [ValueMaxDepth]).

Proposal: always wrap `Value` arguments in denotations with an explicit size-measure newtype, and make relying on the default hard or impossible. Options:

- Convention only: no bare `Value` in denotations, enforced in review.
- Make the bare instance call `error`, so accidental use of the default fails in tests. Caveat: the instance is required by ``uni `Everywhere` ExMemoryUsage`` and reachable from `ExMemoryUsage (Some (ValueOf uni))` (e.g. via the CEK machine's `ExMemoryUsage CekValue`), so the error can also fire outside denotations, in counting/tallying budget modes and tests.
- Compile-time ban via [ban-instance](https://hackage.haskell.org/package/ban-instance): probably won't typecheck for the same reason, since the universe machinery demands a usable instance for every type in `DefaultUni`.

Prompted by a discussion while costing the CIP-0168 builtins (#7921, #7926). Worth a slot in a technical meeting before anyone implements it.

Contributor guide

Open the contributing guide

Research direction

Start with PlutusCore.Evaluation.Machine.ExMemoryUsage and inspect the ValueTotalSize, ValueOuterSize, and ValueMaxDepth wrappers and the bare Value instance. Trace assetCount, keepPolicies, dropPolicies, DefaultUni, and CekValue to understand where the instance is required. Done means reaching and documenting an agreed policy for explicit wrappers without breaking counting, tallying, or related tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.