Skip to content

Fix lookupCoin and valueContains memory models to match the committed JSON - #7941

Open
Unisay wants to merge 1 commit into
masterfrom
yura/issue-2415-memory-model-json-drift
Open

Fix lookupCoin and valueContains memory models to match the committed JSON#7941
Unisay wants to merge 1 commit into
masterfrom
yura/issue-2415-memory-model-json-drift

Conversation

@Unisay

@Unisay Unisay commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

BuiltinMemoryModels.hs declared ModelThreeArgumentsConstantCost 10 for lookupCoin and ModelTwoArgumentsConstantCost 32 for valueContains, while every builtinCostModel*.json carries 1. generate-cost-model copies memory models verbatim into the JSON, so the next full regeneration would have multiplied the memory cost of both builtins by 10x and 32x with nobody intending it.

1 is also the right value. valueContains returns a Bool, so it now uses the existing boolMemModel, and lookupCoin returns a quantity already held in the Value, so it allocates nothing. The 10 and 32 were copied from the lengthOfArray and indexArray entries directly above, which construct a fresh Integer and are not comparable.

Verified by building generate-cost-model with +with-inline-r and running it against the committed benching-conway.csv and models.R. With this change its memory output matches the committed memory model of all 104 builtins in variants C and E, where before it differed on these two. The committed JSON does not change, hence the No Changelog Required label.

Found while costing assetCount.

…tted JSON

`BuiltinMemoryModels.hs` declared `ModelThreeArgumentsConstantCost 10` for `lookupCoin` and `ModelTwoArgumentsConstantCost 32` for `valueContains`, while every `builtinCostModel*.json` carries 1. `generate-cost-model` copies memory models verbatim into the JSON, so the next full regeneration would have multiplied the on-chain memory cost of both builtins by 10x and 32x.

1 is the correct value: `valueContains` returns a `Bool` and now uses the existing `boolMemModel`, and `lookupCoin` returns a quantity already stored in the `Value`, so it allocates nothing. Regenerating with this change reproduces the committed memory models exactly. Found while costing `assetCount`.
@Unisay Unisay added the No Changelog Required Add this to skip the Changelog Check label Sep 9, 2026
@Unisay Unisay self-assigned this Sep 9, 2026
@Unisay
Unisay requested a review from kwxm September 9, 2026 09:46
@Unisay
Unisay marked this pull request as ready for review September 9, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Changelog Required Add this to skip the Changelog Check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant