Skip to content

Commit 6ef5f6d

Browse files
Unisayclaude
andcommitted
feat: replace placeholder costing with parameter-driven implementation
Replace unimplementedCostingFun with proper parameter-based costing: - Wire Value builtin cost parameters into evaluation machinery - Update all cost model configurations (A, B, C) with generated parameters - Enable accurate gas cost estimation for Value operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 37b6d64 commit 6ef5f6d

File tree

6 files changed

+161
-4
lines changed

6 files changed

+161
-4
lines changed

plutus-core/cost-model/data/builtinCostModelA.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,5 +1205,54 @@
12051205
"arguments": 4,
12061206
"type": "constant_cost"
12071207
}
1208+
},
1209+
"lookupCoin": {
1210+
"cpu": {
1211+
"arguments": {
1212+
"intercept": 284421,
1213+
"slope": 1
1214+
},
1215+
"type": "linear_in_z"
1216+
},
1217+
"memory": {
1218+
"arguments": 1,
1219+
"type": "constant_cost"
1220+
}
1221+
},
1222+
"valueContains": {
1223+
"cpu": {
1224+
"arguments": {
1225+
"intercept": 42125119,
1226+
"slope": 30
1227+
},
1228+
"type": "added_sizes"
1229+
},
1230+
"memory": {
1231+
"arguments": 1,
1232+
"type": "constant_cost"
1233+
}
1234+
},
1235+
"valueData": {
1236+
"cpu": {
1237+
"arguments": 164963,
1238+
"type": "constant_cost"
1239+
},
1240+
"memory": {
1241+
"arguments": 1,
1242+
"type": "constant_cost"
1243+
}
1244+
},
1245+
"unValueData": {
1246+
"cpu": {
1247+
"arguments": {
1248+
"intercept": 10532326261,
1249+
"slope": 431
1250+
},
1251+
"type": "linear_in_x"
1252+
},
1253+
"memory": {
1254+
"arguments": 1,
1255+
"type": "constant_cost"
1256+
}
12081257
}
12091258
}

plutus-core/cost-model/data/builtinCostModelB.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,5 +1205,54 @@
12051205
"arguments": 4,
12061206
"type": "constant_cost"
12071207
}
1208+
},
1209+
"lookupCoin": {
1210+
"cpu": {
1211+
"arguments": {
1212+
"intercept": 284421,
1213+
"slope": 1
1214+
},
1215+
"type": "linear_in_z"
1216+
},
1217+
"memory": {
1218+
"arguments": 1,
1219+
"type": "constant_cost"
1220+
}
1221+
},
1222+
"valueContains": {
1223+
"cpu": {
1224+
"arguments": {
1225+
"intercept": 42125119,
1226+
"slope": 30
1227+
},
1228+
"type": "added_sizes"
1229+
},
1230+
"memory": {
1231+
"arguments": 1,
1232+
"type": "constant_cost"
1233+
}
1234+
},
1235+
"valueData": {
1236+
"cpu": {
1237+
"arguments": 164963,
1238+
"type": "constant_cost"
1239+
},
1240+
"memory": {
1241+
"arguments": 1,
1242+
"type": "constant_cost"
1243+
}
1244+
},
1245+
"unValueData": {
1246+
"cpu": {
1247+
"arguments": {
1248+
"intercept": 10532326261,
1249+
"slope": 431
1250+
},
1251+
"type": "linear_in_x"
1252+
},
1253+
"memory": {
1254+
"arguments": 1,
1255+
"type": "constant_cost"
1256+
}
12081257
}
12091258
}

plutus-core/cost-model/data/builtinCostModelC.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,5 +1223,54 @@
12231223
"arguments": 4,
12241224
"type": "constant_cost"
12251225
}
1226+
},
1227+
"lookupCoin": {
1228+
"cpu": {
1229+
"arguments": {
1230+
"intercept": 284421,
1231+
"slope": 1
1232+
},
1233+
"type": "linear_in_z"
1234+
},
1235+
"memory": {
1236+
"arguments": 1,
1237+
"type": "constant_cost"
1238+
}
1239+
},
1240+
"valueContains": {
1241+
"cpu": {
1242+
"arguments": {
1243+
"intercept": 42125119,
1244+
"slope": 30
1245+
},
1246+
"type": "added_sizes"
1247+
},
1248+
"memory": {
1249+
"arguments": 1,
1250+
"type": "constant_cost"
1251+
}
1252+
},
1253+
"valueData": {
1254+
"cpu": {
1255+
"arguments": 164963,
1256+
"type": "constant_cost"
1257+
},
1258+
"memory": {
1259+
"arguments": 1,
1260+
"type": "constant_cost"
1261+
}
1262+
},
1263+
"unValueData": {
1264+
"cpu": {
1265+
"arguments": {
1266+
"intercept": 10532326261,
1267+
"slope": 431
1268+
},
1269+
"type": "linear_in_x"
1270+
},
1271+
"memory": {
1272+
"arguments": 1,
1273+
"type": "constant_cost"
1274+
}
12261275
}
12271276
}

plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
20602060
{-# INLINE lookupCoinDenotation #-}
20612061
in makeBuiltinMeaning
20622062
lookupCoinDenotation
2063-
(runCostingFunThreeArguments . unimplementedCostingFun)
2063+
(runCostingFunThreeArguments . paramLookupCoin)
20642064

20652065
toBuiltinMeaning _semvar UnionValue =
20662066
let unionValueDenotation :: Value -> Value -> Value
@@ -2076,23 +2076,23 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
20762076
{-# INLINE valueContainsDenotation #-}
20772077
in makeBuiltinMeaning
20782078
valueContainsDenotation
2079-
(runCostingFunTwoArguments . unimplementedCostingFun)
2079+
(runCostingFunTwoArguments . paramValueContains)
20802080

20812081
toBuiltinMeaning _semvar ValueData =
20822082
let valueDataDenotation :: Value -> Data
20832083
valueDataDenotation = Value.valueData
20842084
{-# INLINE valueDataDenotation #-}
20852085
in makeBuiltinMeaning
20862086
valueDataDenotation
2087-
(runCostingFunOneArgument . unimplementedCostingFun)
2087+
(runCostingFunOneArgument . paramValueData)
20882088

20892089
toBuiltinMeaning _semvar UnValueData =
20902090
let unValueDataDenotation :: Data -> BuiltinResult Value
20912091
unValueDataDenotation = Value.unValueData
20922092
{-# INLINE unValueDataDenotation #-}
20932093
in makeBuiltinMeaning
20942094
unValueDataDenotation
2095-
(runCostingFunOneArgument . unimplementedCostingFun)
2095+
(runCostingFunOneArgument . paramUnValueData)
20962096

20972097
-- See Note [Inlining meanings of builtins].
20982098
{-# INLINE toBuiltinMeaning #-}

plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ data BuiltinCostModelBase f =
193193
, paramLengthOfArray :: f ModelOneArgument
194194
, paramListToArray :: f ModelOneArgument
195195
, paramIndexArray :: f ModelTwoArguments
196+
-- Builtin values
197+
, paramLookupCoin :: f ModelThreeArguments
198+
, paramValueContains :: f ModelTwoArguments
199+
, paramValueData :: f ModelOneArgument
200+
, paramUnValueData :: f ModelOneArgument
196201
}
197202
deriving stock (Generic)
198203
deriving anyclass (FunctorB, TraversableB, ConstraintsB)

plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ unitCostBuiltinCostModel = BuiltinCostModelBase
355355
, paramLengthOfArray = unitCostOneArgument
356356
, paramListToArray = unitCostOneArgument
357357
, paramIndexArray = unitCostTwoArguments
358+
-- Builtin values
359+
, paramLookupCoin = unitCostThreeArguments
360+
, paramValueContains = unitCostTwoArguments
361+
, paramValueData = unitCostOneArgument
362+
, paramUnValueData = unitCostOneArgument
358363
}
359364

360365
unitCekParameters :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)

0 commit comments

Comments
 (0)