Skip to content

Commit 0d420fe

Browse files
committed
Add insertCoin and unionValue costing skeleton
1 parent 9e221dd commit 0d420fe

File tree

8 files changed

+83
-2
lines changed

8 files changed

+83
-2
lines changed

plutus-core/cost-model/create-cost-model/BuiltinMemoryModels.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,7 @@ builtinMemoryModels = BuiltinCostModelBase
181181
, paramValueContains = Id $ ModelTwoArgumentsConstantCost 1
182182
, paramValueData = Id $ ModelOneArgumentConstantCost 1
183183
, paramUnValueData = Id $ ModelOneArgumentConstantCost 1
184+
, paramInsertCoin = Id $ ModelFourArgumentsConstantCost 1
185+
, paramUnionValue = Id $ ModelTwoArgumentsConstantCost 1
184186
}
185187
where identityFunction = OneVariableLinearFunction 0 1

plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ builtinCostModelNames = BuiltinCostModelBase
136136
, paramValueContains = "valueContainsModel"
137137
, paramValueData = "valueDataModel"
138138
, paramUnValueData = "unValueDataModel"
139+
, paramInsertCoin = "insertCoinModel"
140+
, paramUnionValue = "unionValueModel"
139141
}
140142

141143

@@ -289,6 +291,9 @@ createBuiltinCostModel bmfile rfile = do
289291
paramValueContains <- getParams readCF2 paramValueContains
290292
paramValueData <- getParams readCF1 paramValueData
291293
paramUnValueData <- getParams readCF1 paramUnValueData
294+
-- Values
295+
paramInsertCoin <- getParams readCF4 paramInsertCoin
296+
paramUnionValue <- getParams readCF2 paramUnionValue
292297

293298
pure $ BuiltinCostModelBase {..}
294299

@@ -452,6 +457,13 @@ readCF3 e = do
452457
"exp_mod_cost" -> ModelThreeArgumentsExpModCost <$> readExpModCostingFunction "y_mem" "z_mem" e
453458
_ -> error $ "Unknown three-variable model type: " ++ ty
454459

460+
readCF4 :: MonadR m => SomeSEXP (Region m) -> m ModelFourArguments
461+
readCF4 e = do
462+
ty <- getType e
463+
case ty of
464+
"constant_cost" -> ModelFourArgumentsConstantCost <$> getConstant e
465+
_ -> error $ "Unknown four-variable model type: " ++ ty
466+
455467
readCF6 :: MonadR m => SomeSEXP (Region m) -> m ModelSixArguments
456468
readCF6 e = do
457469
ty <- getType e

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,4 +1255,24 @@
12551255
"type": "constant_cost"
12561256
}
12571257
}
1258+
, "insertCoin": {
1259+
"cpu": {
1260+
"arguments": 1000,
1261+
"type": "constant_cost"
1262+
},
1263+
"memory": {
1264+
"arguments": 10,
1265+
"type": "constant_cost"
1266+
}
1267+
}
1268+
, "unionValue": {
1269+
"cpu": {
1270+
"arguments": 1000,
1271+
"type": "constant_cost"
1272+
},
1273+
"memory": {
1274+
"arguments": 10,
1275+
"type": "constant_cost"
1276+
}
1277+
}
12581278
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,4 +1255,24 @@
12551255
"type": "constant_cost"
12561256
}
12571257
}
1258+
, "insertCoin": {
1259+
"cpu": {
1260+
"arguments": 1000,
1261+
"type": "constant_cost"
1262+
},
1263+
"memory": {
1264+
"arguments": 10,
1265+
"type": "constant_cost"
1266+
}
1267+
}
1268+
, "unionValue": {
1269+
"cpu": {
1270+
"arguments": 1000,
1271+
"type": "constant_cost"
1272+
},
1273+
"memory": {
1274+
"arguments": 10,
1275+
"type": "constant_cost"
1276+
}
1277+
}
12581278
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,4 +1273,24 @@
12731273
"type": "constant_cost"
12741274
}
12751275
}
1276+
, "insertCoin": {
1277+
"cpu": {
1278+
"arguments": 1000,
1279+
"type": "constant_cost"
1280+
},
1281+
"memory": {
1282+
"arguments": 10,
1283+
"type": "constant_cost"
1284+
}
1285+
}
1286+
, "unionValue": {
1287+
"cpu": {
1288+
"arguments": 1000,
1289+
"type": "constant_cost"
1290+
},
1291+
"memory": {
1292+
"arguments": 10,
1293+
"type": "constant_cost"
1294+
}
1295+
}
12761296
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
20522052
{-# INLINE insertCoinDenotation #-}
20532053
in makeBuiltinMeaning
20542054
insertCoinDenotation
2055-
(runCostingFunFourArguments . unimplementedCostingFun)
2055+
(runCostingFunFourArguments . paramInsertCoin)
20562056

20572057
toBuiltinMeaning _semvar LookupCoin =
20582058
let lookupCoinDenotation :: ByteString -> ByteString -> Value -> Integer
@@ -2068,7 +2068,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
20682068
{-# INLINE unionValueDenotation #-}
20692069
in makeBuiltinMeaning
20702070
unionValueDenotation
2071-
(runCostingFunTwoArguments . unimplementedCostingFun)
2071+
(runCostingFunTwoArguments . paramUnionValue)
20722072

20732073
toBuiltinMeaning _semvar ValueContains =
20742074
let valueContainsDenotation :: Value -> Value -> Bool

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ data BuiltinCostModelBase f =
198198
, paramValueContains :: f ModelTwoArguments
199199
, paramValueData :: f ModelOneArgument
200200
, paramUnValueData :: f ModelOneArgument
201+
, paramInsertCoin :: f ModelFourArguments
202+
, paramUnionValue :: f ModelTwoArguments
201203
}
202204
deriving stock (Generic)
203205
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
@@ -238,6 +238,9 @@ unitCostTwoArguments = CostingFun (ModelTwoArgumentsConstantCost 1) (ModelTwo
238238
unitCostThreeArguments :: CostingFun ModelThreeArguments
239239
unitCostThreeArguments = CostingFun (ModelThreeArgumentsConstantCost 1) (ModelThreeArgumentsConstantCost 0)
240240

241+
unitCostFourArguments :: CostingFun ModelFourArguments
242+
unitCostFourArguments = CostingFun (ModelFourArgumentsConstantCost 1) (ModelFourArgumentsConstantCost 0)
243+
241244
unitCostSixArguments :: CostingFun ModelSixArguments
242245
unitCostSixArguments = CostingFun (ModelSixArgumentsConstantCost 1) (ModelSixArgumentsConstantCost 0)
243246

@@ -360,6 +363,8 @@ unitCostBuiltinCostModel = BuiltinCostModelBase
360363
, paramValueContains = unitCostTwoArguments
361364
, paramValueData = unitCostOneArgument
362365
, paramUnValueData = unitCostOneArgument
366+
, paramInsertCoin = unitCostFourArguments
367+
, paramUnionValue = unitCostTwoArguments
363368
}
364369

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

0 commit comments

Comments
 (0)