Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 254005
({cpu: 145034
| mem: 412})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1073645
({cpu: 528790
| mem: 416})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1893317
({cpu: 912578
| mem: 420})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1483477
({cpu: 720680
| mem: 418})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1073645
({cpu: 528790
| mem: 416})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1344460
({cpu: 599949
| mem: 640})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1073645
({cpu: 528790
| mem: 416})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 247704
({cpu: 49100
| mem: 402})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 326126
({cpu: 125418
| mem: 446})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 326126
({cpu: 125418
| mem: 446})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 286915
({cpu: 87259
| mem: 424})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 1344460
({cpu: 599949
| mem: 640})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 286915
({cpu: 87259
| mem: 424})
4 changes: 3 additions & 1 deletion plutus-core/cost-model/budgeting-bench/Benchmarks/Values.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ unValueDataBenchmark gen =
DataNodeCount
UnValueData
[]
(Value.valueData <$> generateTestValues gen)
((unsafeFromBuiltinResult . Value.valueData) <$> generateTestValues gen)

-- FIXME: account properly for out-of-range errors when test values are too big.

----------------------------------------------------------------------------------------------------
-- InsertCoin --------------------------------------------------------------------------------------
Expand Down
463 changes: 261 additions & 202 deletions plutus-core/cost-model/data/benching-conway.csv

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions plutus-core/cost-model/data/builtinCostModelA.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,30 +1240,30 @@
}
},
"valueData": {
"cpu": {
"arguments": {
"intercept": 199604,
"slope": 39211
},
"type": "linear_in_x"
},
"memory": {
"arguments": {
"intercept": 2,
"slope": 22
},
"type": "linear_in_x"
}
"cpu": {
"arguments": {
"intercept": 1000,
"slope": 38159
},
"type": "linear_in_x"
},
"memory": {
"arguments": {
"intercept": 2,
"slope": 22
},
"type": "linear_in_x"
}
},
"unValueData": {
"cpu": {
"arguments": {
"c0": 1000,
"c1": 204904,
"c2": 1
},
"type": "quadratic_in_x"
},
"cpu": {
"arguments": {
"c0": 1000,
"c1": 95933,
"c2": 1
},
"type": "quadratic_in_x"
},
"memory": {
"arguments": {
"intercept": 11,
Expand Down
6 changes: 3 additions & 3 deletions plutus-core/cost-model/data/builtinCostModelB.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,8 @@
"valueData": {
"cpu": {
"arguments": {
"intercept": 199604,
"slope": 39211
"intercept": 1000,
"slope": 38159
},
"type": "linear_in_x"
},
Expand All @@ -1259,7 +1259,7 @@
"cpu": {
"arguments": {
"c0": 1000,
"c1": 204904,
"c1": 95933,
"c2": 1
},
"type": "quadratic_in_x"
Expand Down
32 changes: 16 additions & 16 deletions plutus-core/cost-model/data/builtinCostModelC.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,8 @@
"valueData": {
"cpu": {
"arguments": {
"intercept": 199604,
"slope": 39211
"intercept": 1000,
"slope": 38159
},
"type": "linear_in_x"
},
Expand All @@ -1274,21 +1274,21 @@
}
},
"unValueData": {
"cpu": {
"arguments": {
"c0": 1000,
"c1": 204904,
"c2": 1
},
"type": "quadratic_in_x"
},
"memory": {
"arguments": {
"intercept": 11,
"slope": 1
"cpu": {
"arguments": {
"c0": 1000,
"c1": 95933,
"c2": 1
},
"type": "quadratic_in_x"
},
"type": "linear_in_x"
}
"memory": {
"arguments": {
"intercept": 11,
"slope": 1
},
"type": "linear_in_x"
}
},
"insertCoin": {
"cpu": {
Expand Down
2 changes: 1 addition & 1 deletion plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
valueContainsDenotation
(runCostingFunTwoArguments . paramValueContains)
toBuiltinMeaning _semvar ValueData =
let valueDataDenotation :: ValueTotalSize -> Data
let valueDataDenotation :: ValueTotalSize -> BuiltinResult Data
valueDataDenotation (ValueTotalSize v) = Value.valueData v
{-# INLINE valueDataDenotation #-}
in makeBuiltinMeaning
Expand Down
10 changes: 8 additions & 2 deletions plutus-core/plutus-core/src/PlutusCore/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,16 @@ unionValue vA vB
else (unpack vA, unpack vB)
{-# INLINEABLE unionValue #-}

valueDataMaxSize :: Int
valueDataMaxSize = 40000

{-| \(O(n)\). Encodes `Value` as `Data`, in the same way as non-builtin @Value@.
This is the denotation of @ValueData@ in Plutus V1, V2 and V3. -}
valueData :: Value -> Data
valueData = Map . fmap (bimap (B . unK) tokensData) . Map.toList . unpack
valueData :: Value -> BuiltinResult Data
valueData v =
if totalSize v <= valueDataMaxSize
then pure $ Map . fmap (bimap (B . unK) tokensData) . Map.toList . unpack $ v
else fail $ "valueData: maximum input size (" ++ show valueDataMaxSize ++ ") exceeded"
where
tokensData :: Map K Quantity -> Data
tokensData = Map . fmap (bimap (B . unK) (I . unQuantity)) . Map.toList
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ValueTotalSize -> Data
ValueTotalSize -> BuiltinResult Data
15 changes: 10 additions & 5 deletions plutus-core/plutus-core/test/Value/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,16 @@ prop_oppositeScaleIsInverse c v =
_ -> scaleIncorrectlyBound c v

prop_dataRoundtrip :: Value -> Property
prop_dataRoundtrip v = case V.unValueData d of
BuiltinSuccess v' -> (v === v') .&&. (V.valueData v' === d)
_ -> property False
where
d = V.valueData v
prop_dataRoundtrip v =
case V.valueData v of
BuiltinSuccess d ->
case V.unValueData d of
BuiltinSuccess v' ->
case V.valueData v' of
BuiltinSuccess d' -> (v === v') .&&. (d' === d)
_ -> property False
_ -> property False
_ -> property False

prop_flatRoundtrip :: Value -> Property
prop_flatRoundtrip v = Flat.unflat (Flat.flat v) === Right v
Expand Down
10 changes: 7 additions & 3 deletions plutus-ledger-api/test/Spec/V1/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,19 @@ test_split = testProperty "split" . scaleTestsBy 7 $ \value ->
-- | Test that builtin and non-builtin values are encoded identically in Data.
test_toData :: TestTree
test_toData = testProperty "toData" . scaleTestsBy 10 $ \v ->
PLC.valueData v === toData (valueFromBuiltin v)
case PLC.valueData v of
BuiltinSuccess d -> d === toData (valueFromBuiltin v)
_ -> property False

-- | Test that builtin and non-builtin values are decoded identically from Data.
test_fromData :: TestTree
test_fromData = testProperty "fromData" . scaleTestsBy 10 $ \v ->
let d = PLC.valueData v
in case PLC.unValueData d of
case PLC.valueData v of
BuiltinSuccess d ->
case PLC.unValueData d of
BuiltinSuccess v' -> valueFromBuiltin v' === unsafeFromData d
_ -> property False
_ -> property False

test_Value :: TestTree
test_Value =
Expand Down
7 changes: 6 additions & 1 deletion plutus-tx/src/PlutusTx/Builtins/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,12 @@ valueContains (BuiltinValue v1) (BuiltinValue v2) =
{-# OPAQUE valueContains #-}

mkValue :: BuiltinValue -> BuiltinData
mkValue (BuiltinValue v) = BuiltinData $ Value.valueData v
mkValue (BuiltinValue v) =
case Value.valueData v of
BuiltinSuccess d -> BuiltinData d
BuiltinSuccessWithLogs logs d -> traceAll logs (BuiltinData d)
BuiltinFailure logs err ->
traceAll (logs <> pure (display err)) $ Haskell.error "mkValue failed."
{-# OPAQUE mkValue #-}

unsafeDataAsValue :: BuiltinData -> BuiltinValue
Expand Down
Loading