From b893323d6b8448377ac3371146eaf5dc72c81b43 Mon Sep 17 00:00:00 2001 From: Ana Pantilie Date: Tue, 16 Sep 2025 18:40:30 +0300 Subject: [PATCH] WIP: insertCoin and unionValue costing --- .../create-cost-model/BuiltinMemoryModels.hs | 1 + .../cost-model/data/builtinCostModelA.json | 20 +++++++++++++++++++ .../cost-model/data/builtinCostModelB.json | 20 +++++++++++++++++++ .../cost-model/data/builtinCostModelC.json | 20 +++++++++++++++++++ .../Evaluation/Machine/BuiltinCostModel.hs | 3 +++ .../Evaluation/Machine/ExBudgetingDefaults.hs | 6 ++++++ 6 files changed, 70 insertions(+) diff --git a/plutus-core/cost-model/create-cost-model/BuiltinMemoryModels.hs b/plutus-core/cost-model/create-cost-model/BuiltinMemoryModels.hs index 65e647d48f9..47ddd10fd9e 100644 --- a/plutus-core/cost-model/create-cost-model/BuiltinMemoryModels.hs +++ b/plutus-core/cost-model/create-cost-model/BuiltinMemoryModels.hs @@ -176,5 +176,6 @@ builtinMemoryModels = BuiltinCostModelBase , paramLengthOfArray = Id $ ModelOneArgumentConstantCost 10 , paramListToArray = Id $ ModelOneArgumentLinearInX $ OneVariableLinearFunction 7 1 , paramIndexArray = Id $ ModelTwoArgumentsConstantCost 32 + , paramInsertCoin = Id $ ModelFourArgumentsConstantCost 1 } where identityFunction = OneVariableLinearFunction 0 1 diff --git a/plutus-core/cost-model/data/builtinCostModelA.json b/plutus-core/cost-model/data/builtinCostModelA.json index d1c4baf684c..5aeaab2b6df 100644 --- a/plutus-core/cost-model/data/builtinCostModelA.json +++ b/plutus-core/cost-model/data/builtinCostModelA.json @@ -1206,4 +1206,24 @@ "type": "constant_cost" } } + , "insertCoin": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } + , "unionValue": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } } diff --git a/plutus-core/cost-model/data/builtinCostModelB.json b/plutus-core/cost-model/data/builtinCostModelB.json index 7b4350c3c10..7d335243fab 100644 --- a/plutus-core/cost-model/data/builtinCostModelB.json +++ b/plutus-core/cost-model/data/builtinCostModelB.json @@ -1206,4 +1206,24 @@ "type": "constant_cost" } } + , "insertCoin": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } + , "unionValue": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } } diff --git a/plutus-core/cost-model/data/builtinCostModelC.json b/plutus-core/cost-model/data/builtinCostModelC.json index f69154d323c..20a0d80e2f1 100644 --- a/plutus-core/cost-model/data/builtinCostModelC.json +++ b/plutus-core/cost-model/data/builtinCostModelC.json @@ -1224,4 +1224,24 @@ "type": "constant_cost" } } + , "insertCoin": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } + , "unionValue": { + "cpu": { + "arguments": 1000, + "type": "constant_cost" + }, + "memory": { + "arguments": 10, + "type": "constant_cost" + } + } } diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs index 9cb77e0bb64..d1e236ef2e6 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs @@ -193,6 +193,9 @@ data BuiltinCostModelBase f = , paramLengthOfArray :: f ModelOneArgument , paramListToArray :: f ModelOneArgument , paramIndexArray :: f ModelTwoArguments + -- Values + , paramInsertCoin :: f ModelFourArguments + , paramUnionValue :: f ModelTwoArguments } deriving stock (Generic) deriving anyclass (FunctorB, TraversableB, ConstraintsB) diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs index b70266cb250..a9594758935 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs @@ -238,6 +238,9 @@ unitCostTwoArguments = CostingFun (ModelTwoArgumentsConstantCost 1) (ModelTwo unitCostThreeArguments :: CostingFun ModelThreeArguments unitCostThreeArguments = CostingFun (ModelThreeArgumentsConstantCost 1) (ModelThreeArgumentsConstantCost 0) +unitCostFourArguments :: CostingFun ModelFourArguments +unitCostFourArguments = CostingFun (ModelFourArgumentsConstantCost 1) (ModelFourArgumentsConstantCost 0) + unitCostSixArguments :: CostingFun ModelSixArguments unitCostSixArguments = CostingFun (ModelSixArgumentsConstantCost 1) (ModelSixArgumentsConstantCost 0) @@ -355,6 +358,9 @@ unitCostBuiltinCostModel = BuiltinCostModelBase , paramLengthOfArray = unitCostOneArgument , paramListToArray = unitCostOneArgument , paramIndexArray = unitCostTwoArguments + -- Values + , paramInsertCoin = unitCostFourArguments + , paramUnionValue = unitCostTwoArguments } unitCekParameters :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)