From c5b0a1e077446a2c024ef07b25361d596f8c1b7a Mon Sep 17 00:00:00 2001 From: kwxm Date: Mon, 19 Jun 2023 19:32:17 +0100 Subject: [PATCH 01/24] WIP --- .../budgeting-bench/Benchmarks/Crypto.hs | 2 +- .../CreateBuiltinCostModel.hs | 9 ++++ .../cost-model/data/builtinCostModel.json | 13 ++++++ plutus-core/cost-model/data/models.R | 7 ++- plutus-core/cost-model/test/TestCostModels.hs | 3 ++ .../plutus-core/src/Data/ByteString/Hash.hs | 6 +++ .../src/PlutusCore/Default/Builtins.hs | 43 +++++++++++-------- .../Evaluation/Machine/BuiltinCostModel.hs | 2 + .../Evaluation/Machine/ExBudgetingDefaults.hs | 2 + .../PlutusIR/Transform/CommuteFnWithConst.hs | 1 + .../PlutusCore/Generators/NEAT/Term.hs | 2 +- 11 files changed, 68 insertions(+), 22 deletions(-) diff --git a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs index fd6c69af1e9..2d2dfb2a810 100644 --- a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs +++ b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs @@ -317,5 +317,5 @@ makeBenchmarks gen = [ benchVerifyEd25519Signature , benchVerifyEcdsaSecp256k1Signature , benchVerifySchnorrSecp256k1Signature ] - <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_256]) + <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_256, Keccak256]) <> blsBenchmarks gen diff --git a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs index 81aa6cb25ec..a159d6a039d 100644 --- a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs +++ b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs @@ -121,6 +121,7 @@ builtinCostModelNames = BuiltinCostModelBase , paramBls12_381_millerLoop = "bls12_381_millerLoopModel" , paramBls12_381_mulMlResult = "bls12_381_mulMlResultModel" , paramBls12_381_finalVerify = "bls12_381_finalVerifyModel" + , paramKeccak256 = "keccak256Model" } @@ -232,6 +233,8 @@ createBuiltinCostModel bmfile rfile = do paramBls12_381_mulMlResult <- getParams bls12_381_mulMlResult paramBls12_381_mulMlResult paramBls12_381_finalVerify <- getParams bls12_381_finalVerify paramBls12_381_finalVerify + paramKeccak256 <- getParams keccak256 paramKeccak256 + pure $ BuiltinCostModelBase {..} -- The output of `tidy(model)` on the R side. @@ -491,6 +494,12 @@ blake2b_256 cpuModelR = do let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.blake2b_256 "") pure $ CostingFun cpuModel memModel +keccak256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) +keccak256 cpuModelR = do + cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.keccak256 "") + pure $ CostingFun cpuModel memModel + -- NB: the R model is based purely on the size of the second argument (since the -- first and third are constant size), so we have to rearrange things a bit to -- get it to work with a three-argument costing function. diff --git a/plutus-core/cost-model/data/builtinCostModel.json b/plutus-core/cost-model/data/builtinCostModel.json index b15ea8b805d..a2c27d13091 100644 --- a/plutus-core/cost-model/data/builtinCostModel.json +++ b/plutus-core/cost-model/data/builtinCostModel.json @@ -467,6 +467,19 @@ "type": "constant_cost" } }, + "keccak256": { + "cpu": { + "arguments": { + "intercept": 1234567890, + "slope": 12345 + }, + "type": "linear_cost" + }, + "memory": { + "arguments": 4, + "type": "constant_cost" + } + }, "lengthOfByteString": { "cpu": { "arguments": 1000, diff --git a/plutus-core/cost-model/data/models.R b/plutus-core/cost-model/data/models.R index a17a7e91d29..5634cbac919 100644 --- a/plutus-core/cost-model/data/models.R +++ b/plutus-core/cost-model/data/models.R @@ -127,7 +127,8 @@ arity <- function(name) { "Bls12_381_G2_uncompress" = 1, "Bls12_381_millerLoop" = 2, "Bls12_381_mulMlResult" = 2, - "Bls12_381_finalVerify" = 2 + "Bls12_381_finalVerify" = 2, + "Keccak256" = 1 ) } @@ -497,7 +498,8 @@ modelFun <- function(path) { sha2_256Model <- linearInX ("Sha2_256") sha3_256Model <- linearInX ("Sha3_256") blake2b_256Model <- linearInX ("Blake2b_256") - + keccak256_model <- linearInX ("Keccak256") + ###### Signature verification ##### ## VerifyEd25519Signature in fact takes three arguments, but the first and @@ -669,6 +671,7 @@ modelFun <- function(path) { sha2_256Model = sha2_256Model, sha3_256Model = sha3_256Model, blake2b_256Model = blake2b_256Model, + keccak256_model = keccak256_model, verifyEd25519SignatureModel = verifyEd25519SignatureModel, verifyEcdsaSecp256k1SignatureModel = verifyEcdsaSecp256k1SignatureModel, verifySchnorrSecp256k1SignatureModel = verifySchnorrSecp256k1SignatureModel, diff --git a/plutus-core/cost-model/test/TestCostModels.hs b/plutus-core/cost-model/test/TestCostModels.hs index 25ebb65884d..21270d774d9 100644 --- a/plutus-core/cost-model/test/TestCostModels.hs +++ b/plutus-core/cost-model/test/TestCostModels.hs @@ -419,5 +419,8 @@ main = , $(genTest 2 "bls12_381_millerLoop") Everywhere , $(genTest 2 "bls12_381_mulMlResult") Everywhere , $(genTest 2 "bls12_381_finalVerify") Everywhere + + -- Keccak256 + , $(genTest 1 "keccak256") ] diff --git a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs b/plutus-core/plutus-core/src/Data/ByteString/Hash.hs index 18ab0e4d9dd..c090ef4c7fd 100644 --- a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs +++ b/plutus-core/plutus-core/src/Data/ByteString/Hash.hs @@ -4,10 +4,12 @@ module Data.ByteString.Hash ( sha2_256 , sha3_256 , blake2b_256 + , keccak256 ) where import Cardano.Crypto.Hash.Blake2b import Cardano.Crypto.Hash.Class +import Cardano.Crypto.Hash.Keccak256 import Cardano.Crypto.Hash.SHA256 import Cardano.Crypto.Hash.SHA3_256 import Data.ByteString qualified as BS @@ -24,3 +26,7 @@ sha3_256 = digest (Proxy @SHA3_256) -- | Hash a [[BSL.ByteString]] using the Blake2B-256 hash function. blake2b_256 :: BS.ByteString -> BS.ByteString blake2b_256 = digest (Proxy @Blake2b_256) + +-- | Hash a [[BSL.ByteString]] using the Keccak-256 hash function. +keccak256 :: BS.ByteString -> BS.ByteString +keccak256 = digest (Proxy @Keccak256) diff --git a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs index 85a8a7a08c7..da2c61747a1 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs @@ -144,7 +144,8 @@ data DefaultFun | Bls12_381_millerLoop | Bls12_381_mulMlResult | Bls12_381_finalVerify - + -- Keccak256 + | Keccak256 deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Ix) deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc) @@ -1398,76 +1399,80 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where (\() -> [] @(Data,Data)) (runCostingFunOneArgument . paramMkNilPairData) -- BLS12_381.G1 - toBuiltinMeaning _var Bls12_381_G1_add = + toBuiltinMeaning _ver Bls12_381_G1_add = makeBuiltinMeaning BLS12_381.G1.add (runCostingFunTwoArguments . paramBls12_381_G1_add) - toBuiltinMeaning _var Bls12_381_G1_neg = + toBuiltinMeaning _ver Bls12_381_G1_neg = makeBuiltinMeaning BLS12_381.G1.neg (runCostingFunOneArgument . paramBls12_381_G1_neg) - toBuiltinMeaning _var Bls12_381_G1_scalarMul = + toBuiltinMeaning _ver Bls12_381_G1_scalarMul = makeBuiltinMeaning BLS12_381.G1.scalarMul (runCostingFunTwoArguments . paramBls12_381_G1_scalarMul) - toBuiltinMeaning _var Bls12_381_G1_compress = + toBuiltinMeaning _ver Bls12_381_G1_compress = makeBuiltinMeaning BLS12_381.G1.compress (runCostingFunOneArgument . paramBls12_381_G1_compress) - toBuiltinMeaning _var Bls12_381_G1_uncompress = + toBuiltinMeaning _ver Bls12_381_G1_uncompress = makeBuiltinMeaning (eitherToEmitter . BLS12_381.G1.uncompress) (runCostingFunOneArgument . paramBls12_381_G1_uncompress) - toBuiltinMeaning _var Bls12_381_G1_hashToGroup = + toBuiltinMeaning _ver Bls12_381_G1_hashToGroup = makeBuiltinMeaning (eitherToEmitter .* BLS12_381.G1.hashToGroup) (runCostingFunTwoArguments . paramBls12_381_G1_hashToGroup) - toBuiltinMeaning _var Bls12_381_G1_equal = + toBuiltinMeaning _ver Bls12_381_G1_equal = makeBuiltinMeaning ((==) @BLS12_381.G1.Element) (runCostingFunTwoArguments . paramBls12_381_G1_equal) -- BLS12_381.G2 - toBuiltinMeaning _var Bls12_381_G2_add = + toBuiltinMeaning _ver Bls12_381_G2_add = makeBuiltinMeaning BLS12_381.G2.add (runCostingFunTwoArguments . paramBls12_381_G2_add) - toBuiltinMeaning _var Bls12_381_G2_neg = + toBuiltinMeaning _ver Bls12_381_G2_neg = makeBuiltinMeaning BLS12_381.G2.neg (runCostingFunOneArgument . paramBls12_381_G2_neg) - toBuiltinMeaning _var Bls12_381_G2_scalarMul = + toBuiltinMeaning _ver Bls12_381_G2_scalarMul = makeBuiltinMeaning BLS12_381.G2.scalarMul (runCostingFunTwoArguments . paramBls12_381_G2_scalarMul) - toBuiltinMeaning _var Bls12_381_G2_compress = + toBuiltinMeaning _ver Bls12_381_G2_compress = makeBuiltinMeaning BLS12_381.G2.compress (runCostingFunOneArgument . paramBls12_381_G2_compress) - toBuiltinMeaning _var Bls12_381_G2_uncompress = + toBuiltinMeaning _ver Bls12_381_G2_uncompress = makeBuiltinMeaning (eitherToEmitter . BLS12_381.G2.uncompress) (runCostingFunOneArgument . paramBls12_381_G2_uncompress) - toBuiltinMeaning _var Bls12_381_G2_hashToGroup = + toBuiltinMeaning _ver Bls12_381_G2_hashToGroup = makeBuiltinMeaning (eitherToEmitter .* BLS12_381.G2.hashToGroup) (runCostingFunTwoArguments . paramBls12_381_G2_hashToGroup) - toBuiltinMeaning _var Bls12_381_G2_equal = + toBuiltinMeaning _ver Bls12_381_G2_equal = makeBuiltinMeaning ((==) @BLS12_381.G2.Element) (runCostingFunTwoArguments . paramBls12_381_G2_equal) -- BLS12_381.Pairing - toBuiltinMeaning _var Bls12_381_millerLoop = + toBuiltinMeaning _ver Bls12_381_millerLoop = makeBuiltinMeaning BLS12_381.Pairing.millerLoop (runCostingFunTwoArguments . paramBls12_381_millerLoop) - toBuiltinMeaning _var Bls12_381_mulMlResult = + toBuiltinMeaning _ver Bls12_381_mulMlResult = makeBuiltinMeaning BLS12_381.Pairing.mulMlResult (runCostingFunTwoArguments . paramBls12_381_mulMlResult) - toBuiltinMeaning _var Bls12_381_finalVerify = + toBuiltinMeaning _ver Bls12_381_finalVerify = makeBuiltinMeaning BLS12_381.Pairing.finalVerify (runCostingFunTwoArguments . paramBls12_381_finalVerify) + toBuiltinMeaning _ver Keccak256 = + makeBuiltinMeaning + Hash.keccak256 + (runCostingFunOneArgument . paramKeccak256) -- See Note [Inlining meanings of builtins]. {-# INLINE toBuiltinMeaning #-} @@ -1573,6 +1578,7 @@ instance Flat DefaultFun where Bls12_381_millerLoop -> 68 Bls12_381_mulMlResult -> 69 Bls12_381_finalVerify -> 70 + Keccak256 -> 71 decode = go =<< decodeBuiltin where go 0 = pure AddInteger @@ -1646,6 +1652,7 @@ instance Flat DefaultFun where go 68 = pure Bls12_381_millerLoop go 69 = pure Bls12_381_mulMlResult go 70 = pure Bls12_381_finalVerify + go 71 = pure Keccak256 go t = fail $ "Failed to decode builtin tag, got: " ++ show t size _ n = n + builtinTagWidth 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 a2326264525..38b7ab105bb 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs @@ -153,6 +153,8 @@ data BuiltinCostModelBase f = , paramBls12_381_millerLoop :: f ModelTwoArguments , paramBls12_381_mulMlResult :: f ModelTwoArguments , paramBls12_381_finalVerify :: f ModelTwoArguments + -- Keccak256 + , paramKeccak256 :: f ModelOneArgument } 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 636dd6e8d83..80f79c247ef 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs @@ -195,5 +195,7 @@ unitCostBuiltinCostModel = BuiltinCostModelBase , paramBls12_381_millerLoop = unitCostTwoArguments , paramBls12_381_mulMlResult = unitCostTwoArguments , paramBls12_381_finalVerify = unitCostTwoArguments + -- Keccak256 + , paramKeccak256 = unitCostOneArgument } diff --git a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs index 43d6ea91165..5b57c022049 100644 --- a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs +++ b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs @@ -108,6 +108,7 @@ isCommutative = \case Bls12_381_millerLoop -> False Bls12_381_mulMlResult -> False Bls12_381_finalVerify -> False + Keccak256 -> False -- Strings AppendString -> False EqualsString -> True diff --git a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs index dc6b70a2e9d..7350447eaee 100644 --- a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs +++ b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs @@ -399,7 +399,7 @@ defaultFunTypes = Map.fromList [(TyFunG (TyBuiltinG TyIntegerG) (TyFunG (TyBuilt ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyIntegerG) (TyBuiltinG TyIntegerG)) ,[IndexByteString]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyByteStringG) - ,[Sha2_256,Sha3_256,Blake2b_256]) + ,[Sha2_256,Sha3_256,Blake2b_256,Keccak256]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG))) ,[VerifyEd25519Signature]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG)) From 9f842609bab5146e95c42589e2173f5b4e9d3e17 Mon Sep 17 00:00:00 2001 From: kwxm Date: Mon, 19 Jun 2023 21:54:26 +0100 Subject: [PATCH 02/24] keccak256 -> keccak_256 --- .../budgeting-bench/Benchmarks/Crypto.hs | 2 +- .../create-cost-model/CreateBuiltinCostModel.hs | 10 +++++----- plutus-core/cost-model/data/builtinCostModel.json | 2 +- plutus-core/cost-model/test/TestCostModels.hs | 4 ++-- .../plutus-core/src/Data/ByteString/Hash.hs | 6 +++--- .../plutus-core/src/PlutusCore/Default/Builtins.hs | 14 +++++++------- .../Evaluation/Machine/BuiltinCostModel.hs | 4 ++-- .../Evaluation/Machine/ExBudgetingDefaults.hs | 4 ++-- .../src/PlutusIR/Transform/CommuteFnWithConst.hs | 2 +- .../testlib/PlutusCore/Generators/NEAT/Term.hs | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs index 2d2dfb2a810..5b95bcd2411 100644 --- a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs +++ b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs @@ -317,5 +317,5 @@ makeBenchmarks gen = [ benchVerifyEd25519Signature , benchVerifyEcdsaSecp256k1Signature , benchVerifySchnorrSecp256k1Signature ] - <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_256, Keccak256]) + <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_256, Keccak_256]) <> blsBenchmarks gen diff --git a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs index a159d6a039d..bb0100c1c8a 100644 --- a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs +++ b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs @@ -121,7 +121,7 @@ builtinCostModelNames = BuiltinCostModelBase , paramBls12_381_millerLoop = "bls12_381_millerLoopModel" , paramBls12_381_mulMlResult = "bls12_381_mulMlResultModel" , paramBls12_381_finalVerify = "bls12_381_finalVerifyModel" - , paramKeccak256 = "keccak256Model" + , paramKeccak_256 = "keccak_256Model" } @@ -233,7 +233,7 @@ createBuiltinCostModel bmfile rfile = do paramBls12_381_mulMlResult <- getParams bls12_381_mulMlResult paramBls12_381_mulMlResult paramBls12_381_finalVerify <- getParams bls12_381_finalVerify paramBls12_381_finalVerify - paramKeccak256 <- getParams keccak256 paramKeccak256 + paramKeccak_256 <- getParams keccak_256 paramKeccak_256 pure $ BuiltinCostModelBase {..} @@ -494,10 +494,10 @@ blake2b_256 cpuModelR = do let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.blake2b_256 "") pure $ CostingFun cpuModel memModel -keccak256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) -keccak256 cpuModelR = do +keccak_256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) +keccak_256 cpuModelR = do cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR - let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.keccak256 "") + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.keccak_256 "") pure $ CostingFun cpuModel memModel -- NB: the R model is based purely on the size of the second argument (since the diff --git a/plutus-core/cost-model/data/builtinCostModel.json b/plutus-core/cost-model/data/builtinCostModel.json index a2c27d13091..65a5a98a673 100644 --- a/plutus-core/cost-model/data/builtinCostModel.json +++ b/plutus-core/cost-model/data/builtinCostModel.json @@ -467,7 +467,7 @@ "type": "constant_cost" } }, - "keccak256": { + "keccak_256": { "cpu": { "arguments": { "intercept": 1234567890, diff --git a/plutus-core/cost-model/test/TestCostModels.hs b/plutus-core/cost-model/test/TestCostModels.hs index 21270d774d9..7a3ff1992fd 100644 --- a/plutus-core/cost-model/test/TestCostModels.hs +++ b/plutus-core/cost-model/test/TestCostModels.hs @@ -420,7 +420,7 @@ main = , $(genTest 2 "bls12_381_mulMlResult") Everywhere , $(genTest 2 "bls12_381_finalVerify") Everywhere - -- Keccak256 - , $(genTest 1 "keccak256") + -- Keccak_256 + , $(genTest 1 "keccak_256") ] diff --git a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs b/plutus-core/plutus-core/src/Data/ByteString/Hash.hs index c090ef4c7fd..2687baa0dd8 100644 --- a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs +++ b/plutus-core/plutus-core/src/Data/ByteString/Hash.hs @@ -4,7 +4,7 @@ module Data.ByteString.Hash ( sha2_256 , sha3_256 , blake2b_256 - , keccak256 + , keccak_256 ) where import Cardano.Crypto.Hash.Blake2b @@ -28,5 +28,5 @@ blake2b_256 :: BS.ByteString -> BS.ByteString blake2b_256 = digest (Proxy @Blake2b_256) -- | Hash a [[BSL.ByteString]] using the Keccak-256 hash function. -keccak256 :: BS.ByteString -> BS.ByteString -keccak256 = digest (Proxy @Keccak256) +keccak_256 :: BS.ByteString -> BS.ByteString +keccak_256 = digest (Proxy @Keccak256) diff --git a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs index da2c61747a1..a094fc67adc 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs @@ -144,8 +144,8 @@ data DefaultFun | Bls12_381_millerLoop | Bls12_381_mulMlResult | Bls12_381_finalVerify - -- Keccak256 - | Keccak256 + -- Keccak_256 + | Keccak_256 deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Ix) deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc) @@ -1469,10 +1469,10 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where makeBuiltinMeaning BLS12_381.Pairing.finalVerify (runCostingFunTwoArguments . paramBls12_381_finalVerify) - toBuiltinMeaning _ver Keccak256 = + toBuiltinMeaning _ver Keccak_256 = makeBuiltinMeaning - Hash.keccak256 - (runCostingFunOneArgument . paramKeccak256) + Hash.keccak_256 + (runCostingFunOneArgument . paramKeccak_256) -- See Note [Inlining meanings of builtins]. {-# INLINE toBuiltinMeaning #-} @@ -1578,7 +1578,7 @@ instance Flat DefaultFun where Bls12_381_millerLoop -> 68 Bls12_381_mulMlResult -> 69 Bls12_381_finalVerify -> 70 - Keccak256 -> 71 + Keccak_256 -> 71 decode = go =<< decodeBuiltin where go 0 = pure AddInteger @@ -1652,7 +1652,7 @@ instance Flat DefaultFun where go 68 = pure Bls12_381_millerLoop go 69 = pure Bls12_381_mulMlResult go 70 = pure Bls12_381_finalVerify - go 71 = pure Keccak256 + go 71 = pure Keccak_256 go t = fail $ "Failed to decode builtin tag, got: " ++ show t size _ n = n + builtinTagWidth 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 38b7ab105bb..102a98edfee 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs @@ -153,8 +153,8 @@ data BuiltinCostModelBase f = , paramBls12_381_millerLoop :: f ModelTwoArguments , paramBls12_381_mulMlResult :: f ModelTwoArguments , paramBls12_381_finalVerify :: f ModelTwoArguments - -- Keccak256 - , paramKeccak256 :: f ModelOneArgument + -- Keccak_256 + , paramKeccak_256 :: f ModelOneArgument } 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 80f79c247ef..74c3d76bb9e 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs @@ -195,7 +195,7 @@ unitCostBuiltinCostModel = BuiltinCostModelBase , paramBls12_381_millerLoop = unitCostTwoArguments , paramBls12_381_mulMlResult = unitCostTwoArguments , paramBls12_381_finalVerify = unitCostTwoArguments - -- Keccak256 - , paramKeccak256 = unitCostOneArgument + -- Keccak_256 + , paramKeccak_256 = unitCostOneArgument } diff --git a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs index 5b57c022049..4fbb0b807bd 100644 --- a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs +++ b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs @@ -108,7 +108,7 @@ isCommutative = \case Bls12_381_millerLoop -> False Bls12_381_mulMlResult -> False Bls12_381_finalVerify -> False - Keccak256 -> False + Keccak_256 -> False -- Strings AppendString -> False EqualsString -> True diff --git a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs index 7350447eaee..91548e1ae84 100644 --- a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs +++ b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs @@ -399,7 +399,7 @@ defaultFunTypes = Map.fromList [(TyFunG (TyBuiltinG TyIntegerG) (TyFunG (TyBuilt ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyIntegerG) (TyBuiltinG TyIntegerG)) ,[IndexByteString]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyByteStringG) - ,[Sha2_256,Sha3_256,Blake2b_256,Keccak256]) + ,[Sha2_256,Sha3_256,Blake2b_256,Keccak_256]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG))) ,[VerifyEd25519Signature]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG)) From 364ae3116528910acbb55929ff243147f89e83d9 Mon Sep 17 00:00:00 2001 From: kwxm Date: Tue, 20 Jun 2023 00:10:27 +0100 Subject: [PATCH 03/24] Update plutus-metatheory --- .../src/Algorithmic/CEK.lagda.md | 2 + plutus-metatheory/src/Builtin.lagda.md | 87 ++++++++++--------- plutus-metatheory/src/Untyped/CEK.lagda.md | 4 + 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/plutus-metatheory/src/Algorithmic/CEK.lagda.md b/plutus-metatheory/src/Algorithmic/CEK.lagda.md index 9e371e5d290..1be023e22fb 100644 --- a/plutus-metatheory/src/Algorithmic/CEK.lagda.md +++ b/plutus-metatheory/src/Algorithmic/CEK.lagda.md @@ -290,6 +290,8 @@ BUILTIN bls12-381-G2-uncompress (app base (V-con (tmBytestring b))) with BLS12-3 BUILTIN bls12-381-millerLoop (app (app base (V-con (tmBls12-381-g1-element e1))) (V-con (tmBls12-381-g2-element e2))) = inj₂ (V-con (tmBls12-381-mlresult (BLS12-381-millerLoop e1 e2))) BUILTIN bls12-381-mulMlResult (app (app base (V-con (tmBls12-381-mlresult r))) (V-con (tmBls12-381-mlresult r'))) = inj₂ (V-con (tmBls12-381-mlresult (BLS12-381-mulMlResult r r'))) BUILTIN bls12-381-finalVerify (app (app base (V-con (tmBls12-381-mlresult r))) (V-con (tmBls12-381-mlresult r'))) = inj₂ (V-con (tmBool (BLS12-381-finalVerify r r'))) +BUILTIN keccak-256 (app base (V-con (tmBytestring b))) = + inj₂ (V-con (tmBytestring (KECCAK-256 b))) BUILTIN' : ∀ b {A} → ∀{tn} → {pt : tn ∔ 0 ≣ fv♯ (signature b)} diff --git a/plutus-metatheory/src/Builtin.lagda.md b/plutus-metatheory/src/Builtin.lagda.md index 671acc50e63..d6a8e27605a 100644 --- a/plutus-metatheory/src/Builtin.lagda.md +++ b/plutus-metatheory/src/Builtin.lagda.md @@ -122,7 +122,8 @@ data Builtin : Set where bls12-381-millerLoop : Builtin bls12-381-mulMlResult : Builtin bls12-381-finalVerify : Builtin - + -- Keccak-256 + keccak-256 : Builtin ``` ## Signatures @@ -273,6 +274,7 @@ This is defined in its own module so that these definitions are not exported. signature bls12-381-millerLoop = ∙ [ bls12-381-g1-element , bls12-381-g2-element ]⟶ bls12-381-mlresult signature bls12-381-mulMlResult = ∙ [ bls12-381-mlresult , bls12-381-mlresult ]⟶ bls12-381-mlresult signature bls12-381-finalVerify = ∙ [ bls12-381-mlresult , bls12-381-mlresult ]⟶ bool + signature keccak-256 = ∙ [ bytestring ]⟶ bytestring open SugaredSignature using (signature) public ``` @@ -354,6 +356,7 @@ Each Agda built-in name must be mapped to a Haskell name. | Bls12_381_millerLoop | Bls12_381_mulMlResult | Bls12_381_finalVerify + | Keccak_256 ) #-} ``` @@ -364,47 +367,48 @@ whose semantics are provided by a Haskell function. ``` postulate - length : ByteString → Int - index : ByteString → Int → Int - div : Int → Int → Int - quot : Int → Int → Int - rem : Int → Int → Int - mod : Int → Int → Int - - TRACE : {a : Set} → String → a → a - - concat : ByteString → ByteString → ByteString - cons : Int → ByteString → Maybe ByteString - slice : Int → Int → ByteString → ByteString - B< : ByteString → ByteString → Bool - B<= : ByteString → ByteString → Bool - SHA2-256 : ByteString → ByteString - SHA3-256 : ByteString → ByteString - BLAKE2B-256 : ByteString → ByteString - verifyEd25519Sig : ByteString → ByteString → ByteString → Maybe Bool - verifyEcdsaSecp256k1Sig : ByteString → ByteString → ByteString → Maybe Bool + length : ByteString → Int + index : ByteString → Int → Int + div : Int → Int → Int + quot : Int → Int → Int + rem : Int → Int → Int + mod : Int → Int → Int + + TRACE : {a : Set} → String → a → a + + concat : ByteString → ByteString → ByteString + cons : Int → ByteString → Maybe ByteString + slice : Int → Int → ByteString → ByteString + B< : ByteString → ByteString → Bool + B<= : ByteString → ByteString → Bool + SHA2-256 : ByteString → ByteString + SHA3-256 : ByteString → ByteString + BLAKE2B-256 : ByteString → ByteString + verifyEd25519Sig : ByteString → ByteString → ByteString → Maybe Bool + verifyEcdsaSecp256k1Sig : ByteString → ByteString → ByteString → Maybe Bool verifySchnorrSecp256k1Sig : ByteString → ByteString → ByteString → Maybe Bool - equals : ByteString → ByteString → Bool - ENCODEUTF8 : String → ByteString - DECODEUTF8 : ByteString → Maybe String - serialiseDATA : DATA → ByteString - BLS12-381-G1-add : Bls12-381-G1-Element → Bls12-381-G1-Element → Bls12-381-G1-Element - BLS12-381-G1-neg : Bls12-381-G1-Element → Bls12-381-G1-Element - BLS12-381-G1-scalarMul : Int → Bls12-381-G1-Element → Bls12-381-G1-Element - BLS12-381-G1-equal : Bls12-381-G1-Element → Bls12-381-G1-Element → Bool - BLS12-381-G1-hashToGroup : ByteString → ByteString → Maybe Bls12-381-G1-Element - BLS12-381-G1-compress : Bls12-381-G1-Element → ByteString - BLS12-381-G1-uncompress : ByteString → Maybe Bls12-381-G1-Element -- FIXME: this really returns Either BLSTError Element - BLS12-381-G2-add : Bls12-381-G2-Element → Bls12-381-G2-Element → Bls12-381-G2-Element - BLS12-381-G2-neg : Bls12-381-G2-Element → Bls12-381-G2-Element - BLS12-381-G2-scalarMul : Int → Bls12-381-G2-Element → Bls12-381-G2-Element - BLS12-381-G2-equal : Bls12-381-G2-Element → Bls12-381-G2-Element → Bool - BLS12-381-G2-hashToGroup : ByteString → ByteString → Maybe Bls12-381-G2-Element - BLS12-381-G2-compress : Bls12-381-G2-Element → ByteString - BLS12-381-G2-uncompress : ByteString → Maybe Bls12-381-G2-Element -- FIXME: this really returns Either BLSTError Element - BLS12-381-millerLoop : Bls12-381-G1-Element → Bls12-381-G2-Element → Bls12-381-MlResult - BLS12-381-mulMlResult : Bls12-381-MlResult → Bls12-381-MlResult → Bls12-381-MlResult - BLS12-381-finalVerify : Bls12-381-MlResult → Bls12-381-MlResult → Bool + equals : ByteString → ByteString → Bool + ENCODEUTF8 : String → ByteString + DECODEUTF8 : ByteString → Maybe String + serialiseDATA : DATA → ByteString + BLS12-381-G1-add : Bls12-381-G1-Element → Bls12-381-G1-Element → Bls12-381-G1-Element + BLS12-381-G1-neg : Bls12-381-G1-Element → Bls12-381-G1-Element + BLS12-381-G1-scalarMul : Int → Bls12-381-G1-Element → Bls12-381-G1-Element + BLS12-381-G1-equal : Bls12-381-G1-Element → Bls12-381-G1-Element → Bool + BLS12-381-G1-hashToGroup : ByteString → ByteString → Maybe Bls12-381-G1-Element + BLS12-381-G1-compress : Bls12-381-G1-Element → ByteString + BLS12-381-G1-uncompress : ByteString → Maybe Bls12-381-G1-Element -- FIXME: this really returns Either BLSTError Element + BLS12-381-G2-add : Bls12-381-G2-Element → Bls12-381-G2-Element → Bls12-381-G2-Element + BLS12-381-G2-neg : Bls12-381-G2-Element → Bls12-381-G2-Element + BLS12-381-G2-scalarMul : Int → Bls12-381-G2-Element → Bls12-381-G2-Element + BLS12-381-G2-equal : Bls12-381-G2-Element → Bls12-381-G2-Element → Bool + BLS12-381-G2-hashToGroup : ByteString → ByteString → Maybe Bls12-381-G2-Element + BLS12-381-G2-compress : Bls12-381-G2-Element → ByteString + BLS12-381-G2-uncompress : ByteString → Maybe Bls12-381-G2-Element -- FIXME: this really returns Either BLSTError Element + BLS12-381-millerLoop : Bls12-381-G1-Element → Bls12-381-G2-Element → Bls12-381-MlResult + BLS12-381-mulMlResult : Bls12-381-MlResult → Bls12-381-MlResult → Bls12-381-MlResult + BLS12-381-finalVerify : Bls12-381-MlResult → Bls12-381-MlResult → Bool + KECCAK-256 : ByteString → ByteString ``` ### What builtin operations should be compiled to if we compile to Haskell @@ -492,6 +496,7 @@ postulate {-# COMPILE GHC BLS12-381-mulMlResult = Pairing.mulMlResult #-} {-# COMPILE GHC BLS12-381-finalVerify = Pairing.finalVerify #-} +{-# COMPILE GHC KECCAK-256 = B.convert . Hash.keccak_256 #-} -- no binding needed for appendStr -- no binding needed for traceStr diff --git a/plutus-metatheory/src/Untyped/CEK.lagda.md b/plutus-metatheory/src/Untyped/CEK.lagda.md index 199b9008720..2685f0c26fb 100644 --- a/plutus-metatheory/src/Untyped/CEK.lagda.md +++ b/plutus-metatheory/src/Untyped/CEK.lagda.md @@ -482,6 +482,10 @@ BUILTIN bls12-381-finalVerify = λ { (app (app base (V-con (con bls12-381-mlresult) r)) (V-con (con bls12-381-mlresult) r')) -> inj₂ (V-con (con bool) (BLS12-381-finalVerify r r')) ; _ -> inj₁ userError } +BUILTIN keccak-256 = λ + { (app base (V-con (con bytestring) b)) -> inj₂ (V-con (con bytestring) (KECCAK-256 b)) + ; _ -> inj₁ userError + } BUILTIN' : ∀ b From e20a7e13e74a9a1011fd62c02ab065334ee06c7c Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 7 Jul 2023 16:01:49 +0100 Subject: [PATCH 04/24] Add blake2b_224 --- .../src/PlutusBenchmark/Ed25519/Common.hs | 2 +- .../CreateBuiltinCostModel.hs | 19 +- plutus-core/cost-model/data/benching.csv | 202 ++++++++++++++++++ .../cost-model/data/builtinCostModel.json | 17 +- plutus-core/cost-model/data/models.R | 9 +- plutus-core/cost-model/test/TestCostModels.hs | 5 +- plutus-core/plutus-core.cabal | 2 +- .../ByteString => PlutusCore/Crypto}/Hash.hs | 7 +- .../src/PlutusCore/Default/Builtins.hs | 11 +- .../Evaluation/Machine/BuiltinCostModel.hs | 3 +- .../Evaluation/Machine/ExBudgetingDefaults.hs | 3 +- .../PlutusIR/Transform/CommuteFnWithConst.hs | 3 +- .../src/Algorithmic/CEK.lagda.md | 2 + plutus-metatheory/src/Builtin.lagda.md | 9 +- plutus-metatheory/src/Untyped/CEK.lagda.md | 4 + .../src/PlutusTx/Compiler/Builtins.hs | 4 + plutus-tx/src/PlutusTx/Builtins.hs | 12 ++ plutus-tx/src/PlutusTx/Builtins/Internal.hs | 10 +- 18 files changed, 301 insertions(+), 23 deletions(-) rename plutus-core/plutus-core/src/{Data/ByteString => PlutusCore/Crypto}/Hash.hs (83%) diff --git a/plutus-benchmark/ed25519-costs/src/PlutusBenchmark/Ed25519/Common.hs b/plutus-benchmark/ed25519-costs/src/PlutusBenchmark/Ed25519/Common.hs index ccca52d669a..77db493c664 100644 --- a/plutus-benchmark/ed25519-costs/src/PlutusBenchmark/Ed25519/Common.hs +++ b/plutus-benchmark/ed25519-costs/src/PlutusBenchmark/Ed25519/Common.hs @@ -18,6 +18,7 @@ import PlutusBenchmark.Common import System.IO (Handle) import PlutusCore (DefaultFun, DefaultUni) +import PlutusCore.Crypto.Hash qualified as Hash import PlutusTx qualified as Tx import UntypedPlutusCore qualified as UPLC @@ -31,7 +32,6 @@ import Cardano.Crypto.DSIGN.Ed25519 (Ed25519DSIGN) import Cardano.Crypto.Seed (mkSeedFromBytes) import Data.ByteString (ByteString) -import Data.ByteString.Hash qualified as Hash import Hedgehog.Internal.Gen qualified as G import Hedgehog.Internal.Range qualified as R import System.IO.Unsafe (unsafePerformIO) diff --git a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs index bb0100c1c8a..1c501ebadfd 100644 --- a/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs +++ b/plutus-core/cost-model/create-cost-model/CreateBuiltinCostModel.hs @@ -11,6 +11,7 @@ module CreateBuiltinCostModel where import PlutusCore.Crypto.BLS12_381.G1 qualified as G1 import PlutusCore.Crypto.BLS12_381.G2 qualified as G2 import PlutusCore.Crypto.BLS12_381.Pairing qualified as Pairing +import PlutusCore.Crypto.Hash qualified as Hash import PlutusCore.Evaluation.Machine.BuiltinCostModel import PlutusCore.Evaluation.Machine.CostStream import PlutusCore.Evaluation.Machine.ExMemory @@ -20,7 +21,6 @@ import Barbies (bmap, bsequence) import Control.Applicative (Const (Const, getConst)) import Control.Exception (TypeError (TypeError)) import Control.Monad.Catch (throwM) -import Data.ByteString.Hash qualified as PlutusHash import Data.ByteString.Lazy qualified as BSL (fromStrict) import Data.Coerce (coerce) import Data.Csv (FromNamedRecord, FromRecord, HasHeader (HasHeader), decode, parseNamedRecord, (.:)) @@ -121,6 +121,7 @@ builtinCostModelNames = BuiltinCostModelBase , paramBls12_381_millerLoop = "bls12_381_millerLoopModel" , paramBls12_381_mulMlResult = "bls12_381_mulMlResultModel" , paramBls12_381_finalVerify = "bls12_381_finalVerifyModel" + , paramBlake2b_224 = "blake2b_224Model" , paramKeccak_256 = "keccak_256Model" } @@ -234,6 +235,7 @@ createBuiltinCostModel bmfile rfile = do paramBls12_381_finalVerify <- getParams bls12_381_finalVerify paramBls12_381_finalVerify paramKeccak_256 <- getParams keccak_256 paramKeccak_256 + paramBlake2b_224 <- getParams blake2b_224 paramBlake2b_224 pure $ BuiltinCostModelBase {..} @@ -479,27 +481,34 @@ lessThanEqualsByteString = lessThanByteString sha2_256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) sha2_256 cpuModelR = do cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR - let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.sha2_256 "") + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ Hash.sha2_256 "") pure $ CostingFun cpuModel memModel sha3_256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) sha3_256 cpuModelR = do cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR - let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.sha3_256 "") + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ Hash.sha3_256 "") + pure $ CostingFun cpuModel memModel + +blake2b_224 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) +blake2b_224 cpuModelR = do + cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ Hash.blake2b_224 "") pure $ CostingFun cpuModel memModel blake2b_256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) blake2b_256 cpuModelR = do cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR - let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.blake2b_256 "") + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ Hash.blake2b_256 "") pure $ CostingFun cpuModel memModel keccak_256 :: MonadR m => (SomeSEXP (Region m)) -> m (CostingFun ModelOneArgument) keccak_256 cpuModelR = do cpuModel <- ModelOneArgumentLinearCost <$> readModelLinearInX cpuModelR - let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ PlutusHash.keccak_256 "") + let memModel = ModelOneArgumentConstantCost (memoryUsageAsCostingInteger $ Hash.keccak_256 "") pure $ CostingFun cpuModel memModel + -- NB: the R model is based purely on the size of the second argument (since the -- first and third are constant size), so we have to rearrange things a bit to -- get it to work with a three-argument costing function. diff --git a/plutus-core/cost-model/data/benching.csv b/plutus-core/cost-model/data/benching.csv index 266db535c35..eee7c288905 100644 --- a/plutus-core/cost-model/data/benching.csv +++ b/plutus-core/cost-model/data/benching.csv @@ -1952,6 +1952,107 @@ Sha3_256/9700,8.184775111568476e-4,8.089090018237341e-4,8.751242624177473e-4,6.0 Sha3_256/9800,8.095645418212397e-4,8.05394215887996e-4,8.185480517399119e-4,2.10946726921052e-5,6.610203607768696e-6,3.8844482240486675e-5 Sha3_256/9900,8.116231077469047e-4,8.104827185059911e-4,8.130504208793394e-4,4.2711860568391396e-6,2.7705045089524583e-6,6.140711087195331e-6 Sha3_256/10000,8.412102672028462e-4,8.339496757219296e-4,8.599082587034181e-4,4.2108581870608e-5,2.281467790187134e-5,7.083353993279055e-5 +Blake2b_224/1,1.058866177553942e-6,1.0351314758107403e-6,1.0997875510129305e-6,9.920708174473134e-8,7.715974291767419e-8,1.2667088115903637e-7 +Blake2b_224/100,2.107330600614902e-6,2.085250301573818e-6,2.160520364571667e-6,1.1154563846001125e-7,6.624355320221705e-8,1.8843169839743749e-7 +Blake2b_224/200,3.1205266308808506e-6,3.113891238282638e-6,3.1319878747000982e-6,2.601651133118648e-8,1.2867766179902705e-8,4.310562951097803e-8 +Blake2b_224/300,4.268730462545677e-6,4.243175561102078e-6,4.3707988665135e-6,1.3543939273131508e-7,3.722883454516397e-8,2.992750325653483e-7 +Blake2b_224/400,5.203703999264517e-6,5.181251155914204e-6,5.269964344801538e-6,1.1878782978195955e-7,4.627745172019428e-8,2.351209310363118e-7 +Blake2b_224/500,5.9766933425290175e-6,5.943121410413661e-6,6.113447296521537e-6,1.8328390977785487e-7,9.04268173046435e-8,3.6868393318502817e-7 +Blake2b_224/600,6.926410268167192e-6,6.899367091404922e-6,7.058435359120732e-6,1.6241938746539412e-7,3.86286372144923e-8,3.6129734443575376e-7 +Blake2b_224/700,7.960807600401682e-6,7.919519601426342e-6,8.052751143815135e-6,2.2600124001819423e-7,1.2672491295073285e-7,3.7858569709712303e-7 +Blake2b_224/800,8.929845277711268e-6,8.885144560950643e-6,9.020777088973703e-6,2.3054856850272647e-7,1.146045107467147e-7,3.5421889583240286e-7 +Blake2b_224/900,1.0141412884144537e-5,1.0066189052329049e-5,1.0275995410819495e-5,3.233198010355464e-7,1.3838809456917152e-7,5.694614551739967e-7 +Blake2b_224/1000,1.1079460771572386e-5,1.1017853145970594e-5,1.124148140052456e-5,3.163027938982787e-7,9.833819139493731e-8,5.806592851555981e-7 +Blake2b_224/1100,1.2157313241942673e-5,1.2092229754930612e-5,1.2348874671702757e-5,3.274245976729878e-7,1.8347703653825065e-7,6.25660369994514e-7 +Blake2b_224/1200,1.3105450473074357e-5,1.3036133931831585e-5,1.3322606046224055e-5,3.624524471377895e-7,1.1985181272133687e-7,7.775664458833712e-7 +Blake2b_224/1300,1.4420843458255736e-5,1.427446064578974e-5,1.4974938101890508e-5,8.910347033664329e-7,2.7751065461262917e-7,1.8127861154341888e-6 +Blake2b_224/1400,1.5282873742090178e-5,1.518010160184062e-5,1.561995331348422e-5,5.270540076052484e-7,2.1417870110176802e-7,1.044090938240202e-6 +Blake2b_224/1500,1.643301672555558e-5,1.625616833037685e-5,1.7028187798634615e-5,8.949825857175185e-7,2.810681685109168e-7,1.922422539301018e-6 +Blake2b_224/1600,1.727374155938813e-5,1.7173527988701872e-5,1.752298877037424e-5,5.126226862239113e-7,1.8943612087454928e-7,1.0100415117455722e-6 +Blake2b_224/1700,1.8703134079717747e-5,1.8522849684517468e-5,1.898180590588165e-5,8.009447904602967e-7,3.4817061315308816e-7,1.2137044176066547e-6 +Blake2b_224/1800,1.9474381009051905e-5,1.932092167719618e-5,2.001293645131103e-5,8.621216674729439e-7,2.372464799203578e-7,1.7575820254208253e-6 +Blake2b_224/1900,2.0762284490885648e-5,2.055138474868901e-5,2.162675902998507e-5,1.4593916612620253e-6,4.2127796412191557e-7,3.0024997056874457e-6 +Blake2b_224/2000,2.1450953002367843e-5,2.1299691589763634e-5,2.1851485568344984e-5,7.283016629400576e-7,3.2633088472450186e-7,1.3780418191093748e-6 +Blake2b_224/2100,2.3151391464857453e-5,2.283998133447509e-5,2.415120557697002e-5,1.6057999274481308e-6,4.579962492140958e-7,3.5285844080917673e-6 +Blake2b_224/2200,2.3710908285742288e-5,2.356267116686948e-5,2.40614981178673e-5,7.470645508255186e-7,3.416934396881511e-7,1.3210584404820492e-6 +Blake2b_224/2300,2.4938324643164525e-5,2.480399056540811e-5,2.5129706168270916e-5,5.534862976747581e-7,4.873874624407568e-7,7.287070155692917e-7 +Blake2b_224/2400,2.5646698818620143e-5,2.5454451725827738e-5,2.6392488459054712e-5,1.041552240439053e-6,2.5855525741466896e-7,2.3036759310004334e-6 +Blake2b_224/2500,2.701435782125882e-5,2.6875064429996345e-5,2.7251963757446096e-5,6.656434396496787e-7,5.526538224922398e-7,9.404818053685724e-7 +Blake2b_224/2600,2.824619173685573e-5,2.7947274552806432e-5,2.894360703288434e-5,1.617588072821016e-6,5.760960571136145e-7,2.9883607880704334e-6 +Blake2b_224/2700,2.8651149710333944e-5,2.8615925497632304e-5,2.8717660384703762e-5,1.487391411405925e-7,9.446005014634933e-8,2.3840337178240049e-7 +Blake2b_224/2800,3.070078613147394e-5,3.009899080202408e-5,3.377392753674611e-5,3.4068644712085665e-6,8.869328621305489e-7,7.36197303646939e-6 +Blake2b_224/2900,3.066485085874718e-5,3.062366907561051e-5,3.0738968017802157e-5,1.814934696064304e-7,1.0170661869225304e-7,2.9292269928377886e-7 +Blake2b_224/3000,3.324166047338545e-5,3.238001006002742e-5,3.6548632045068745e-5,5.1985397666397054e-6,9.085835797766876e-7,1.0958109172879896e-5 +Blake2b_224/3100,3.269571701774213e-5,3.26503296983935e-5,3.2892771575489165e-5,2.744226412990958e-7,1.196184308167465e-7,5.369018794725474e-7 +Blake2b_224/3200,3.403414498426972e-5,3.383547603766881e-5,3.44060342687195e-5,7.793617065463054e-7,4.947083305077382e-7,1.3640231718038043e-6 +Blake2b_224/3300,3.5191911198808575e-5,3.4975856099566444e-5,3.559975958419949e-5,9.554921634053676e-7,4.5106315211441897e-7,1.6732876093183978e-6 +Blake2b_224/3400,3.6299983044848614e-5,3.607651654452228e-5,3.6834825835150854e-5,1.1726631208876317e-6,4.7046840498547025e-7,2.0924564783182554e-6 +Blake2b_224/3500,3.7184429946046445e-5,3.698739440809114e-5,3.778776848470064e-5,1.0037040121187468e-6,4.0518285929747154e-7,2.2417937175971216e-6 +Blake2b_224/3600,3.840866780140864e-5,3.8149050306292474e-5,3.917103224448523e-5,1.2596195116128801e-6,7.963165416815914e-7,2.302352099767382e-6 +Blake2b_224/3700,3.9294281823211015e-5,3.9103362977724796e-5,3.994754461695739e-5,1.0025151081715906e-6,4.5802076200791174e-7,1.930475338498495e-6 +Blake2b_224/3800,4.085457352424134e-5,4.0475701914508404e-5,4.194606975169997e-5,2.411967997228894e-6,7.143052001834435e-7,4.503547172929313e-6 +Blake2b_224/3900,4.1401782967735845e-5,4.1067928100038166e-5,4.2166223812038024e-5,1.6236459936687913e-6,5.723574392853032e-7,2.9409066078574e-6 +Blake2b_224/4000,4.305852453950664e-5,4.25592105539392e-5,4.480427691374125e-5,2.701147133021977e-6,9.544936925476275e-7,5.431689349120135e-6 +Blake2b_224/4100,4.381019846748734e-5,4.345823180581767e-5,4.482232490214268e-5,1.976761088414672e-6,5.635156238837936e-7,3.6690503220990954e-6 +Blake2b_224/4200,4.6452218907865266e-5,4.517575732548842e-5,5.124685950343986e-5,7.996912692664038e-6,1.0134804619726385e-6,1.6890920690060025e-5 +Blake2b_224/4300,4.580032601579891e-5,4.5432024546409205e-5,4.675962339730293e-5,1.890892899364981e-6,6.407605370087998e-7,3.469291741968523e-6 +Blake2b_224/4400,4.7011542963424426e-5,4.6795994333716095e-5,4.7300630049449276e-5,1.0124011946453653e-6,8.644218843362557e-7,1.262280076812194e-6 +Blake2b_224/4500,4.8263428673205516e-5,4.770043989710043e-5,5.017639074740447e-5,3.144072033341603e-6,8.414096897583511e-7,6.452288689517197e-6 +Blake2b_224/4600,4.8445901122611766e-5,4.8359560688624594e-5,4.858804554686844e-5,4.166000090724304e-7,2.4245451539383286e-7,6.755278870209941e-7 +Blake2b_224/4700,5.1939317614595166e-5,5.025060151226696e-5,5.8514001983542456e-5,1.0719438144258418e-5,1.2565748469896127e-6,2.2712584275315713e-5 +Blake2b_224/4800,5.007732684892432e-5,4.999857858036226e-5,5.027397220880092e-5,3.792893042649552e-7,1.485234536903998e-7,7.690060202192783e-7 +Blake2b_224/4900,5.2120841871901004e-5,5.1797373719436974e-5,5.3082441682407334e-5,1.7052410870391374e-6,8.100051819458479e-7,3.2276621717440923e-6 +Blake2b_224/5000,5.2793199542638503e-5,5.254612254421397e-5,5.325704977869127e-5,1.1785775054919608e-6,5.583864989409697e-7,1.8851786277282938e-6 +Blake2b_224/5100,5.3942383638939037e-5,5.3641684623565606e-5,5.431336906455128e-5,1.0707631188104636e-6,6.352626102340837e-7,1.52306614949696e-6 +Blake2b_224/5200,5.451166773813132e-5,5.42257349121218e-5,5.5390841649537726e-5,1.5110857868612025e-6,3.8031576971011696e-7,3.2218905469622576e-6 +Blake2b_224/5300,5.648801634404324e-5,5.6057818770489175e-5,5.73419066788937e-5,2.0378063732099633e-6,1.1331029003961625e-6,3.6563677932081437e-6 +Blake2b_224/5400,5.7254941425727845e-5,5.688940262571059e-5,5.833597570764728e-5,2.133955957253102e-6,7.531025669283287e-7,3.9056456822706396e-6 +Blake2b_224/5500,5.872316309731186e-5,5.8328722819704726e-5,5.9364357176065786e-5,1.610008475419188e-6,1.100828386132166e-6,2.4451954155142213e-6 +Blake2b_224/5600,5.931210917835381e-5,5.8917152839999444e-5,6.087278722098536e-5,2.2251660045094325e-6,9.15140502453878e-7,4.65950953866282e-6 +Blake2b_224/5700,6.215514275557973e-5,6.084891058690365e-5,6.706122421979483e-5,7.73375065641883e-6,1.1322652583957729e-6,1.618904195183443e-5 +Blake2b_224/5800,6.175644395456324e-5,6.11933804906771e-5,6.332888995968914e-5,2.420544666988894e-6,1.0000826318531565e-6,4.40525487407305e-6 +Blake2b_224/5900,6.243993725928432e-5,6.20368472680124e-5,6.293126931785049e-5,1.5478447285884925e-6,1.2347738979348174e-6,2.2423598546105343e-6 +Blake2b_224/6000,6.45410842306157e-5,6.355821704813892e-5,6.73893814759681e-5,5.303784639946252e-6,1.8232975208964398e-6,9.728271235227386e-6 +Blake2b_224/6100,6.390970054430798e-5,6.38471562651913e-5,6.400609429196815e-5,2.4718405623831327e-7,1.3995582504990076e-7,3.8434661233437644e-7 +Blake2b_224/6200,6.601636626946353e-5,6.562484286334059e-5,6.673227387831775e-5,1.8118162925812202e-6,1.2394943166130247e-6,2.7428832620760607e-6 +Blake2b_224/6300,6.587844669577577e-5,6.579556803956619e-5,6.60511269285151e-5,4.2203646929841997e-7,1.7590016138473002e-7,7.086379099907451e-7 +Blake2b_224/6400,6.754098701148434e-5,6.711969379426472e-5,6.856807540247602e-5,2.1047584786973716e-6,1.0688208542090978e-6,3.953840013130626e-6 +Blake2b_224/6500,6.85018160193559e-5,6.81309063819066e-5,6.923405943162597e-5,1.7659693177738799e-6,8.558135894928747e-7,2.735691609587542e-6 +Blake2b_224/6600,6.97291809661803e-5,6.929098170120306e-5,7.056929406155067e-5,2.2314542618911207e-6,1.0536947705981734e-6,3.880722796879969e-6 +Blake2b_224/6700,7.033170837816322e-5,6.992204991368149e-5,7.110501415853444e-5,1.9288035182342045e-6,8.285577200839928e-7,3.603829804653193e-6 +Blake2b_224/6800,7.215019618956995e-5,7.151798132625188e-5,7.543833525566771e-5,3.5883092032351707e-6,1.2136809275599759e-6,8.24934621126507e-6 +Blake2b_224/6900,7.277345027387052e-5,7.227152370896168e-5,7.392639952138141e-5,2.5198544565488386e-6,9.574689231383706e-7,4.497312390884969e-6 +Blake2b_224/7000,7.542100015002116e-5,7.457755852181226e-5,7.73659805581287e-5,4.12699378788349e-6,1.6621154064157677e-6,6.826335360140617e-6 +Blake2b_224/7100,7.501846925876904e-5,7.441222630450554e-5,7.739560083965258e-5,3.767150719731263e-6,5.844350431639585e-7,7.904480577358747e-6 +Blake2b_224/7200,7.625349447348937e-5,7.584288016380027e-5,7.686579021734493e-5,1.935043498212277e-6,1.5019813713618807e-6,2.9743493095957967e-6 +Blake2b_224/7300,7.867686996269496e-5,7.736496284462024e-5,8.24428945316185e-5,6.5648083323212774e-6,3.326617479622458e-6,1.1513708345582944e-5 +Blake2b_224/7400,7.73331226239276e-5,7.721217382764899e-5,7.755403756649285e-5,5.011023140000701e-7,2.3247717170048617e-7,8.361142791740651e-7 +Blake2b_224/7500,7.893505965244809e-5,7.858698474546532e-5,7.9492145557212e-5,1.551120300813045e-6,1.1355369498544397e-6,2.2334530742102727e-6 +Blake2b_224/7600,7.951398375468233e-5,7.92427747148934e-5,8.030870027370407e-5,1.7218665966762041e-6,4.5681256214597136e-7,3.2352049838941144e-6 +Blake2b_224/7700,8.1452519863899e-5,8.090538447558784e-5,8.295088106225043e-5,2.541211550994998e-6,1.4062664490181118e-6,4.504449111839382e-6 +Blake2b_224/7800,8.207903820857649e-5,8.170449004932678e-5,8.313559171862275e-5,1.7105124903471437e-6,8.135065760794694e-7,3.117950198400677e-6 +Blake2b_224/7900,8.393147524804484e-5,8.330017167117384e-5,8.62505230255256e-5,3.584872683487768e-6,1.7174784518508134e-6,6.794683285005506e-6 +Blake2b_224/8000,8.3825819999056e-5,8.334365663807378e-5,8.526037952056482e-5,2.794970076266031e-6,3.4372149081961747e-7,5.23900546718916e-6 +Blake2b_224/8100,8.811153483960476e-5,8.658724146658528e-5,9.337501359265689e-5,8.157238626099442e-6,2.0289028177244018e-6,1.729041815745543e-5 +Blake2b_224/8200,8.724097374257806e-5,8.617242852671937e-5,9.095502360181812e-5,5.930613053851916e-6,1.1444343042998763e-6,1.2306206477893369e-5 +Blake2b_224/8300,8.751884399990794e-5,8.699274647190729e-5,8.844915407633328e-5,2.1618179344058463e-6,1.3400734366470524e-6,3.7477942102857113e-6 +Blake2b_224/8400,9.095964508498637e-5,8.944457726830796e-5,9.515400337929247e-5,9.359538667784902e-6,2.5835708183424045e-6,1.752165469933864e-5 +Blake2b_224/8500,8.868933381584902e-5,8.857593091388947e-5,8.901279797094519e-5,6.055788893827932e-7,2.8987326022520383e-7,1.1604345915445252e-6 +Blake2b_224/8600,9.057637563844374e-5,9.00547341127989e-5,9.165252316441544e-5,2.428030839144897e-6,1.4056240507150723e-6,4.219498291169897e-6 +Blake2b_224/8700,9.110045852574082e-5,9.064162048178214e-5,9.229281232839039e-5,2.137784089836855e-6,1.141433363380656e-6,3.952923630426898e-6 +Blake2b_224/8800,9.318871336974877e-5,9.242897700461663e-5,9.562685602332356e-5,3.792748907280084e-6,1.5001028836988998e-6,7.250400004918398e-6 +Blake2b_224/8900,9.360329440975812e-5,9.31329278305362e-5,9.497575669370548e-5,2.654514477159443e-6,1.0585127429358854e-6,5.179485832229895e-6 +Blake2b_224/9000,9.530259633292818e-5,9.468050564590097e-5,9.6698756954451e-5,3.5708511894771407e-6,1.813471099741736e-6,6.663361005512879e-6 +Blake2b_224/9100,9.544428099804767e-5,9.490837827998098e-5,9.738995634107796e-5,2.9818848127578524e-6,1.2378842643534602e-6,5.825349979177486e-6 +Blake2b_224/9200,9.951974963995942e-5,9.735144542096317e-5,1.0729565427403032e-4,1.3897449313016696e-5,2.358955213392349e-6,2.9387011525475844e-5 +Blake2b_224/9300,9.769975457736239e-5,9.681985473129997e-5,9.976142113799069e-5,4.49771772500704e-6,1.58921803240278e-6,8.806476238062705e-6 +Blake2b_224/9400,9.827038630248854e-5,9.816213296341588e-5,9.847520082819936e-5,5.315284097789278e-7,2.492651378522865e-7,8.962233742992072e-7 +Blake2b_224/9500,1.0260387829993494e-4,1.0054152132260939e-4,1.0725361150597839e-4,9.55389968763581e-6,2.078358053075761e-6,1.832725832326639e-5 +Blake2b_224/9600,1.0007151305427532e-4,9.984253633897067e-5,1.0054280560758327e-4,1.0309806821705763e-6,6.49666813208504e-7,1.7802288080269005e-6 +Blake2b_224/9700,1.0207647561413394e-4,1.014787688985795e-4,1.0323633561979889e-4,2.771596965813564e-6,1.691011489945188e-6,4.739988720152948e-6 +Blake2b_224/9800,1.0227941028300047e-4,1.017729043697749e-4,1.0444631558372355e-4,2.52368984984658e-6,9.555889044727126e-7,5.869269836003722e-6 +Blake2b_224/9900,1.0465353877735825e-4,1.0408786611233812e-4,1.0606485586693787e-4,3.384054598698011e-6,1.6580780889069696e-6,5.960723836126841e-6 +Blake2b_224/10000,1.0493704545146666e-4,1.0435372217420162e-4,1.0650937107249171e-4,3.234244305844669e-6,1.125263001034833e-6,5.9368682331128935e-6 Blake2b_256/1,1.058866177553942e-6,1.0351314758107403e-6,1.0997875510129305e-6,9.920708174473134e-8,7.715974291767419e-8,1.2667088115903637e-7 Blake2b_256/100,2.107330600614902e-6,2.085250301573818e-6,2.160520364571667e-6,1.1154563846001125e-7,6.624355320221705e-8,1.8843169839743749e-7 Blake2b_256/200,3.1205266308808506e-6,3.113891238282638e-6,3.1319878747000982e-6,2.601651133118648e-8,1.2867766179902705e-8,4.310562951097803e-8 @@ -2053,6 +2154,107 @@ Blake2b_256/9700,1.0207647561413394e-4,1.014787688985795e-4,1.0323633561979889e- Blake2b_256/9800,1.0227941028300047e-4,1.017729043697749e-4,1.0444631558372355e-4,2.52368984984658e-6,9.555889044727126e-7,5.869269836003722e-6 Blake2b_256/9900,1.0465353877735825e-4,1.0408786611233812e-4,1.0606485586693787e-4,3.384054598698011e-6,1.6580780889069696e-6,5.960723836126841e-6 Blake2b_256/10000,1.0493704545146666e-4,1.0435372217420162e-4,1.0650937107249171e-4,3.234244305844669e-6,1.125263001034833e-6,5.9368682331128935e-6 +Keccak_256/1,1.058866177553942e-6,1.0351314758107403e-6,1.0997875510129305e-6,9.920708174473134e-8,7.715974291767419e-8,1.2667088115903637e-7 +Keccak_256/100,2.107330600614902e-6,2.085250301573818e-6,2.160520364571667e-6,1.1154563846001125e-7,6.624355320221705e-8,1.8843169839743749e-7 +Keccak_256/200,3.1205266308808506e-6,3.113891238282638e-6,3.1319878747000982e-6,2.601651133118648e-8,1.2867766179902705e-8,4.310562951097803e-8 +Keccak_256/300,4.268730462545677e-6,4.243175561102078e-6,4.3707988665135e-6,1.3543939273131508e-7,3.722883454516397e-8,2.992750325653483e-7 +Keccak_256/400,5.203703999264517e-6,5.181251155914204e-6,5.269964344801538e-6,1.1878782978195955e-7,4.627745172019428e-8,2.351209310363118e-7 +Keccak_256/500,5.9766933425290175e-6,5.943121410413661e-6,6.113447296521537e-6,1.8328390977785487e-7,9.04268173046435e-8,3.6868393318502817e-7 +Keccak_256/600,6.926410268167192e-6,6.899367091404922e-6,7.058435359120732e-6,1.6241938746539412e-7,3.86286372144923e-8,3.6129734443575376e-7 +Keccak_256/700,7.960807600401682e-6,7.919519601426342e-6,8.052751143815135e-6,2.2600124001819423e-7,1.2672491295073285e-7,3.7858569709712303e-7 +Keccak_256/800,8.929845277711268e-6,8.885144560950643e-6,9.020777088973703e-6,2.3054856850272647e-7,1.146045107467147e-7,3.5421889583240286e-7 +Keccak_256/900,1.0141412884144537e-5,1.0066189052329049e-5,1.0275995410819495e-5,3.233198010355464e-7,1.3838809456917152e-7,5.694614551739967e-7 +Keccak_256/1000,1.1079460771572386e-5,1.1017853145970594e-5,1.124148140052456e-5,3.163027938982787e-7,9.833819139493731e-8,5.806592851555981e-7 +Keccak_256/1100,1.2157313241942673e-5,1.2092229754930612e-5,1.2348874671702757e-5,3.274245976729878e-7,1.8347703653825065e-7,6.25660369994514e-7 +Keccak_256/1200,1.3105450473074357e-5,1.3036133931831585e-5,1.3322606046224055e-5,3.624524471377895e-7,1.1985181272133687e-7,7.775664458833712e-7 +Keccak_256/1300,1.4420843458255736e-5,1.427446064578974e-5,1.4974938101890508e-5,8.910347033664329e-7,2.7751065461262917e-7,1.8127861154341888e-6 +Keccak_256/1400,1.5282873742090178e-5,1.518010160184062e-5,1.561995331348422e-5,5.270540076052484e-7,2.1417870110176802e-7,1.044090938240202e-6 +Keccak_256/1500,1.643301672555558e-5,1.625616833037685e-5,1.7028187798634615e-5,8.949825857175185e-7,2.810681685109168e-7,1.922422539301018e-6 +Keccak_256/1600,1.727374155938813e-5,1.7173527988701872e-5,1.752298877037424e-5,5.126226862239113e-7,1.8943612087454928e-7,1.0100415117455722e-6 +Keccak_256/1700,1.8703134079717747e-5,1.8522849684517468e-5,1.898180590588165e-5,8.009447904602967e-7,3.4817061315308816e-7,1.2137044176066547e-6 +Keccak_256/1800,1.9474381009051905e-5,1.932092167719618e-5,2.001293645131103e-5,8.621216674729439e-7,2.372464799203578e-7,1.7575820254208253e-6 +Keccak_256/1900,2.0762284490885648e-5,2.055138474868901e-5,2.162675902998507e-5,1.4593916612620253e-6,4.2127796412191557e-7,3.0024997056874457e-6 +Keccak_256/2000,2.1450953002367843e-5,2.1299691589763634e-5,2.1851485568344984e-5,7.283016629400576e-7,3.2633088472450186e-7,1.3780418191093748e-6 +Keccak_256/2100,2.3151391464857453e-5,2.283998133447509e-5,2.415120557697002e-5,1.6057999274481308e-6,4.579962492140958e-7,3.5285844080917673e-6 +Keccak_256/2200,2.3710908285742288e-5,2.356267116686948e-5,2.40614981178673e-5,7.470645508255186e-7,3.416934396881511e-7,1.3210584404820492e-6 +Keccak_256/2300,2.4938324643164525e-5,2.480399056540811e-5,2.5129706168270916e-5,5.534862976747581e-7,4.873874624407568e-7,7.287070155692917e-7 +Keccak_256/2400,2.5646698818620143e-5,2.5454451725827738e-5,2.6392488459054712e-5,1.041552240439053e-6,2.5855525741466896e-7,2.3036759310004334e-6 +Keccak_256/2500,2.701435782125882e-5,2.6875064429996345e-5,2.7251963757446096e-5,6.656434396496787e-7,5.526538224922398e-7,9.404818053685724e-7 +Keccak_256/2600,2.824619173685573e-5,2.7947274552806432e-5,2.894360703288434e-5,1.617588072821016e-6,5.760960571136145e-7,2.9883607880704334e-6 +Keccak_256/2700,2.8651149710333944e-5,2.8615925497632304e-5,2.8717660384703762e-5,1.487391411405925e-7,9.446005014634933e-8,2.3840337178240049e-7 +Keccak_256/2800,3.070078613147394e-5,3.009899080202408e-5,3.377392753674611e-5,3.4068644712085665e-6,8.869328621305489e-7,7.36197303646939e-6 +Keccak_256/2900,3.066485085874718e-5,3.062366907561051e-5,3.0738968017802157e-5,1.814934696064304e-7,1.0170661869225304e-7,2.9292269928377886e-7 +Keccak_256/3000,3.324166047338545e-5,3.238001006002742e-5,3.6548632045068745e-5,5.1985397666397054e-6,9.085835797766876e-7,1.0958109172879896e-5 +Keccak_256/3100,3.269571701774213e-5,3.26503296983935e-5,3.2892771575489165e-5,2.744226412990958e-7,1.196184308167465e-7,5.369018794725474e-7 +Keccak_256/3200,3.403414498426972e-5,3.383547603766881e-5,3.44060342687195e-5,7.793617065463054e-7,4.947083305077382e-7,1.3640231718038043e-6 +Keccak_256/3300,3.5191911198808575e-5,3.4975856099566444e-5,3.559975958419949e-5,9.554921634053676e-7,4.5106315211441897e-7,1.6732876093183978e-6 +Keccak_256/3400,3.6299983044848614e-5,3.607651654452228e-5,3.6834825835150854e-5,1.1726631208876317e-6,4.7046840498547025e-7,2.0924564783182554e-6 +Keccak_256/3500,3.7184429946046445e-5,3.698739440809114e-5,3.778776848470064e-5,1.0037040121187468e-6,4.0518285929747154e-7,2.2417937175971216e-6 +Keccak_256/3600,3.840866780140864e-5,3.8149050306292474e-5,3.917103224448523e-5,1.2596195116128801e-6,7.963165416815914e-7,2.302352099767382e-6 +Keccak_256/3700,3.9294281823211015e-5,3.9103362977724796e-5,3.994754461695739e-5,1.0025151081715906e-6,4.5802076200791174e-7,1.930475338498495e-6 +Keccak_256/3800,4.085457352424134e-5,4.0475701914508404e-5,4.194606975169997e-5,2.411967997228894e-6,7.143052001834435e-7,4.503547172929313e-6 +Keccak_256/3900,4.1401782967735845e-5,4.1067928100038166e-5,4.2166223812038024e-5,1.6236459936687913e-6,5.723574392853032e-7,2.9409066078574e-6 +Keccak_256/4000,4.305852453950664e-5,4.25592105539392e-5,4.480427691374125e-5,2.701147133021977e-6,9.544936925476275e-7,5.431689349120135e-6 +Keccak_256/4100,4.381019846748734e-5,4.345823180581767e-5,4.482232490214268e-5,1.976761088414672e-6,5.635156238837936e-7,3.6690503220990954e-6 +Keccak_256/4200,4.6452218907865266e-5,4.517575732548842e-5,5.124685950343986e-5,7.996912692664038e-6,1.0134804619726385e-6,1.6890920690060025e-5 +Keccak_256/4300,4.580032601579891e-5,4.5432024546409205e-5,4.675962339730293e-5,1.890892899364981e-6,6.407605370087998e-7,3.469291741968523e-6 +Keccak_256/4400,4.7011542963424426e-5,4.6795994333716095e-5,4.7300630049449276e-5,1.0124011946453653e-6,8.644218843362557e-7,1.262280076812194e-6 +Keccak_256/4500,4.8263428673205516e-5,4.770043989710043e-5,5.017639074740447e-5,3.144072033341603e-6,8.414096897583511e-7,6.452288689517197e-6 +Keccak_256/4600,4.8445901122611766e-5,4.8359560688624594e-5,4.858804554686844e-5,4.166000090724304e-7,2.4245451539383286e-7,6.755278870209941e-7 +Keccak_256/4700,5.1939317614595166e-5,5.025060151226696e-5,5.8514001983542456e-5,1.0719438144258418e-5,1.2565748469896127e-6,2.2712584275315713e-5 +Keccak_256/4800,5.007732684892432e-5,4.999857858036226e-5,5.027397220880092e-5,3.792893042649552e-7,1.485234536903998e-7,7.690060202192783e-7 +Keccak_256/4900,5.2120841871901004e-5,5.1797373719436974e-5,5.3082441682407334e-5,1.7052410870391374e-6,8.100051819458479e-7,3.2276621717440923e-6 +Keccak_256/5000,5.2793199542638503e-5,5.254612254421397e-5,5.325704977869127e-5,1.1785775054919608e-6,5.583864989409697e-7,1.8851786277282938e-6 +Keccak_256/5100,5.3942383638939037e-5,5.3641684623565606e-5,5.431336906455128e-5,1.0707631188104636e-6,6.352626102340837e-7,1.52306614949696e-6 +Keccak_256/5200,5.451166773813132e-5,5.42257349121218e-5,5.5390841649537726e-5,1.5110857868612025e-6,3.8031576971011696e-7,3.2218905469622576e-6 +Keccak_256/5300,5.648801634404324e-5,5.6057818770489175e-5,5.73419066788937e-5,2.0378063732099633e-6,1.1331029003961625e-6,3.6563677932081437e-6 +Keccak_256/5400,5.7254941425727845e-5,5.688940262571059e-5,5.833597570764728e-5,2.133955957253102e-6,7.531025669283287e-7,3.9056456822706396e-6 +Keccak_256/5500,5.872316309731186e-5,5.8328722819704726e-5,5.9364357176065786e-5,1.610008475419188e-6,1.100828386132166e-6,2.4451954155142213e-6 +Keccak_256/5600,5.931210917835381e-5,5.8917152839999444e-5,6.087278722098536e-5,2.2251660045094325e-6,9.15140502453878e-7,4.65950953866282e-6 +Keccak_256/5700,6.215514275557973e-5,6.084891058690365e-5,6.706122421979483e-5,7.73375065641883e-6,1.1322652583957729e-6,1.618904195183443e-5 +Keccak_256/5800,6.175644395456324e-5,6.11933804906771e-5,6.332888995968914e-5,2.420544666988894e-6,1.0000826318531565e-6,4.40525487407305e-6 +Keccak_256/5900,6.243993725928432e-5,6.20368472680124e-5,6.293126931785049e-5,1.5478447285884925e-6,1.2347738979348174e-6,2.2423598546105343e-6 +Keccak_256/6000,6.45410842306157e-5,6.355821704813892e-5,6.73893814759681e-5,5.303784639946252e-6,1.8232975208964398e-6,9.728271235227386e-6 +Keccak_256/6100,6.390970054430798e-5,6.38471562651913e-5,6.400609429196815e-5,2.4718405623831327e-7,1.3995582504990076e-7,3.8434661233437644e-7 +Keccak_256/6200,6.601636626946353e-5,6.562484286334059e-5,6.673227387831775e-5,1.8118162925812202e-6,1.2394943166130247e-6,2.7428832620760607e-6 +Keccak_256/6300,6.587844669577577e-5,6.579556803956619e-5,6.60511269285151e-5,4.2203646929841997e-7,1.7590016138473002e-7,7.086379099907451e-7 +Keccak_256/6400,6.754098701148434e-5,6.711969379426472e-5,6.856807540247602e-5,2.1047584786973716e-6,1.0688208542090978e-6,3.953840013130626e-6 +Keccak_256/6500,6.85018160193559e-5,6.81309063819066e-5,6.923405943162597e-5,1.7659693177738799e-6,8.558135894928747e-7,2.735691609587542e-6 +Keccak_256/6600,6.97291809661803e-5,6.929098170120306e-5,7.056929406155067e-5,2.2314542618911207e-6,1.0536947705981734e-6,3.880722796879969e-6 +Keccak_256/6700,7.033170837816322e-5,6.992204991368149e-5,7.110501415853444e-5,1.9288035182342045e-6,8.285577200839928e-7,3.603829804653193e-6 +Keccak_256/6800,7.215019618956995e-5,7.151798132625188e-5,7.543833525566771e-5,3.5883092032351707e-6,1.2136809275599759e-6,8.24934621126507e-6 +Keccak_256/6900,7.277345027387052e-5,7.227152370896168e-5,7.392639952138141e-5,2.5198544565488386e-6,9.574689231383706e-7,4.497312390884969e-6 +Keccak_256/7000,7.542100015002116e-5,7.457755852181226e-5,7.73659805581287e-5,4.12699378788349e-6,1.6621154064157677e-6,6.826335360140617e-6 +Keccak_256/7100,7.501846925876904e-5,7.441222630450554e-5,7.739560083965258e-5,3.767150719731263e-6,5.844350431639585e-7,7.904480577358747e-6 +Keccak_256/7200,7.625349447348937e-5,7.584288016380027e-5,7.686579021734493e-5,1.935043498212277e-6,1.5019813713618807e-6,2.9743493095957967e-6 +Keccak_256/7300,7.867686996269496e-5,7.736496284462024e-5,8.24428945316185e-5,6.5648083323212774e-6,3.326617479622458e-6,1.1513708345582944e-5 +Keccak_256/7400,7.73331226239276e-5,7.721217382764899e-5,7.755403756649285e-5,5.011023140000701e-7,2.3247717170048617e-7,8.361142791740651e-7 +Keccak_256/7500,7.893505965244809e-5,7.858698474546532e-5,7.9492145557212e-5,1.551120300813045e-6,1.1355369498544397e-6,2.2334530742102727e-6 +Keccak_256/7600,7.951398375468233e-5,7.92427747148934e-5,8.030870027370407e-5,1.7218665966762041e-6,4.5681256214597136e-7,3.2352049838941144e-6 +Keccak_256/7700,8.1452519863899e-5,8.090538447558784e-5,8.295088106225043e-5,2.541211550994998e-6,1.4062664490181118e-6,4.504449111839382e-6 +Keccak_256/7800,8.207903820857649e-5,8.170449004932678e-5,8.313559171862275e-5,1.7105124903471437e-6,8.135065760794694e-7,3.117950198400677e-6 +Keccak_256/7900,8.393147524804484e-5,8.330017167117384e-5,8.62505230255256e-5,3.584872683487768e-6,1.7174784518508134e-6,6.794683285005506e-6 +Keccak_256/8000,8.3825819999056e-5,8.334365663807378e-5,8.526037952056482e-5,2.794970076266031e-6,3.4372149081961747e-7,5.23900546718916e-6 +Keccak_256/8100,8.811153483960476e-5,8.658724146658528e-5,9.337501359265689e-5,8.157238626099442e-6,2.0289028177244018e-6,1.729041815745543e-5 +Keccak_256/8200,8.724097374257806e-5,8.617242852671937e-5,9.095502360181812e-5,5.930613053851916e-6,1.1444343042998763e-6,1.2306206477893369e-5 +Keccak_256/8300,8.751884399990794e-5,8.699274647190729e-5,8.844915407633328e-5,2.1618179344058463e-6,1.3400734366470524e-6,3.7477942102857113e-6 +Keccak_256/8400,9.095964508498637e-5,8.944457726830796e-5,9.515400337929247e-5,9.359538667784902e-6,2.5835708183424045e-6,1.752165469933864e-5 +Keccak_256/8500,8.868933381584902e-5,8.857593091388947e-5,8.901279797094519e-5,6.055788893827932e-7,2.8987326022520383e-7,1.1604345915445252e-6 +Keccak_256/8600,9.057637563844374e-5,9.00547341127989e-5,9.165252316441544e-5,2.428030839144897e-6,1.4056240507150723e-6,4.219498291169897e-6 +Keccak_256/8700,9.110045852574082e-5,9.064162048178214e-5,9.229281232839039e-5,2.137784089836855e-6,1.141433363380656e-6,3.952923630426898e-6 +Keccak_256/8800,9.318871336974877e-5,9.242897700461663e-5,9.562685602332356e-5,3.792748907280084e-6,1.5001028836988998e-6,7.250400004918398e-6 +Keccak_256/8900,9.360329440975812e-5,9.31329278305362e-5,9.497575669370548e-5,2.654514477159443e-6,1.0585127429358854e-6,5.179485832229895e-6 +Keccak_256/9000,9.530259633292818e-5,9.468050564590097e-5,9.6698756954451e-5,3.5708511894771407e-6,1.813471099741736e-6,6.663361005512879e-6 +Keccak_256/9100,9.544428099804767e-5,9.490837827998098e-5,9.738995634107796e-5,2.9818848127578524e-6,1.2378842643534602e-6,5.825349979177486e-6 +Keccak_256/9200,9.951974963995942e-5,9.735144542096317e-5,1.0729565427403032e-4,1.3897449313016696e-5,2.358955213392349e-6,2.9387011525475844e-5 +Keccak_256/9300,9.769975457736239e-5,9.681985473129997e-5,9.976142113799069e-5,4.49771772500704e-6,1.58921803240278e-6,8.806476238062705e-6 +Keccak_256/9400,9.827038630248854e-5,9.816213296341588e-5,9.847520082819936e-5,5.315284097789278e-7,2.492651378522865e-7,8.962233742992072e-7 +Keccak_256/9500,1.0260387829993494e-4,1.0054152132260939e-4,1.0725361150597839e-4,9.55389968763581e-6,2.078358053075761e-6,1.832725832326639e-5 +Keccak_256/9600,1.0007151305427532e-4,9.984253633897067e-5,1.0054280560758327e-4,1.0309806821705763e-6,6.49666813208504e-7,1.7802288080269005e-6 +Keccak_256/9700,1.0207647561413394e-4,1.014787688985795e-4,1.0323633561979889e-4,2.771596965813564e-6,1.691011489945188e-6,4.739988720152948e-6 +Keccak_256/9800,1.0227941028300047e-4,1.017729043697749e-4,1.0444631558372355e-4,2.52368984984658e-6,9.555889044727126e-7,5.869269836003722e-6 +Keccak_256/9900,1.0465353877735825e-4,1.0408786611233812e-4,1.0606485586693787e-4,3.384054598698011e-6,1.6580780889069696e-6,5.960723836126841e-6 +Keccak_256/10000,1.0493704545146666e-4,1.0435372217420162e-4,1.0650937107249171e-4,3.234244305844669e-6,1.125263001034833e-6,5.9368682331128935e-6 Bls12_381_G1_add/12/12,1.66632732699414e-6,1.66529329666621e-6,1.6672949997954758e-6,3.5081441131624374e-9,3.0809353761891355e-9,4.092938813345758e-9 Bls12_381_G1_add/12/12,1.6753127089572078e-6,1.6744838692321767e-6,1.6762510140685204e-6,3.0956520418533004e-9,2.5666119678554987e-9,3.680937282056884e-9 Bls12_381_G1_add/12/12,1.6641381470922022e-6,1.6633073889172297e-6,1.6650520313544842e-6,2.9164556837276715e-9,2.3800451071253958e-9,3.586341322980612e-9 diff --git a/plutus-core/cost-model/data/builtinCostModel.json b/plutus-core/cost-model/data/builtinCostModel.json index 65a5a98a673..a1558756127 100644 --- a/plutus-core/cost-model/data/builtinCostModel.json +++ b/plutus-core/cost-model/data/builtinCostModel.json @@ -57,6 +57,19 @@ "type": "constant_cost" } }, + "blake2b_224": { + "cpu": { + "arguments": { + "intercept": 9999999999, + "slope": 9999999999 + }, + "type": "linear_cost" + }, + "memory": { + "arguments": 4, + "type": "constant_cost" + } + }, "blake2b_256": { "cpu": { "arguments": { @@ -470,8 +483,8 @@ "keccak_256": { "cpu": { "arguments": { - "intercept": 1234567890, - "slope": 12345 + "intercept": 9999999999, + "slope": 9999999999 }, "type": "linear_cost" }, diff --git a/plutus-core/cost-model/data/models.R b/plutus-core/cost-model/data/models.R index 5634cbac919..cd77bb0bc87 100644 --- a/plutus-core/cost-model/data/models.R +++ b/plutus-core/cost-model/data/models.R @@ -128,7 +128,8 @@ arity <- function(name) { "Bls12_381_millerLoop" = 2, "Bls12_381_mulMlResult" = 2, "Bls12_381_finalVerify" = 2, - "Keccak256" = 1 + "Keccak_256" = 1, + "Blake2b_224" = 1 ) } @@ -497,8 +498,9 @@ modelFun <- function(path) { sha2_256Model <- linearInX ("Sha2_256") sha3_256Model <- linearInX ("Sha3_256") + blake2b_224Model <- linearInX ("Blake2b_224") blake2b_256Model <- linearInX ("Blake2b_256") - keccak256_model <- linearInX ("Keccak256") + keccak_256Model <- linearInX ("Keccak_256") ###### Signature verification ##### @@ -670,8 +672,9 @@ modelFun <- function(path) { lessThanEqualsByteStringModel = lessThanEqualsByteStringModel, sha2_256Model = sha2_256Model, sha3_256Model = sha3_256Model, + blake2b_224Model = blake2b_224Model, blake2b_256Model = blake2b_256Model, - keccak256_model = keccak256_model, + keccak_256Model = keccak_256Model, verifyEd25519SignatureModel = verifyEd25519SignatureModel, verifyEcdsaSecp256k1SignatureModel = verifyEcdsaSecp256k1SignatureModel, verifySchnorrSecp256k1SignatureModel = verifySchnorrSecp256k1SignatureModel, diff --git a/plutus-core/cost-model/test/TestCostModels.hs b/plutus-core/cost-model/test/TestCostModels.hs index 7a3ff1992fd..2e7546b25a8 100644 --- a/plutus-core/cost-model/test/TestCostModels.hs +++ b/plutus-core/cost-model/test/TestCostModels.hs @@ -420,7 +420,8 @@ main = , $(genTest 2 "bls12_381_mulMlResult") Everywhere , $(genTest 2 "bls12_381_finalVerify") Everywhere - -- Keccak_256 + -- Keccak_256, Blake2b_224 , $(genTest 1 "keccak_256") - ] + , $(genTest 1 "blake2b_224") + ] diff --git a/plutus-core/plutus-core.cabal b/plutus-core/plutus-core.cabal index 5c65d6a1172..6cbb9f75d07 100644 --- a/plutus-core/plutus-core.cabal +++ b/plutus-core/plutus-core.cabal @@ -71,7 +71,6 @@ common lang library import: lang exposed-modules: - Data.ByteString.Hash Data.Either.Extras Data.List.Extras Data.MultiSet.Lens @@ -95,6 +94,7 @@ library PlutusCore.Crypto.BLS12_381.G2 PlutusCore.Crypto.BLS12_381.Pairing PlutusCore.Crypto.Ed25519 + PlutusCore.Crypto.Hash PlutusCore.Crypto.Secp256k1 PlutusCore.Data PlutusCore.DataFilePaths diff --git a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs similarity index 83% rename from plutus-core/plutus-core/src/Data/ByteString/Hash.hs rename to plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs index 2687baa0dd8..d0f879dc45b 100644 --- a/plutus-core/plutus-core/src/Data/ByteString/Hash.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs @@ -1,8 +1,9 @@ -- | Hash functions for lazy [[Data.ByteString.ByteString]]s {-# LANGUAGE TypeApplications #-} -module Data.ByteString.Hash +module PlutusCore.Crypto.Hash ( sha2_256 , sha3_256 + , blake2b_224 , blake2b_256 , keccak_256 ) where @@ -23,6 +24,10 @@ sha2_256 = digest (Proxy @SHA256) sha3_256 :: BS.ByteString -> BS.ByteString sha3_256 = digest (Proxy @SHA3_256) +-- | Hash a [[BSL.ByteString]] using the Blake2B-256 hash function. +blake2b_224 :: BS.ByteString -> BS.ByteString +blake2b_224 = digest (Proxy @Blake2b_224) + -- | Hash a [[BSL.ByteString]] using the Blake2B-256 hash function. blake2b_256 :: BS.ByteString -> BS.ByteString blake2b_256 = digest (Proxy @Blake2b_256) diff --git a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs index a094fc67adc..4bb0d601bd9 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs @@ -29,11 +29,11 @@ import PlutusCore.Crypto.BLS12_381.G1 qualified as BLS12_381.G1 import PlutusCore.Crypto.BLS12_381.G2 qualified as BLS12_381.G2 import PlutusCore.Crypto.BLS12_381.Pairing qualified as BLS12_381.Pairing import PlutusCore.Crypto.Ed25519 (verifyEd25519Signature_V1, verifyEd25519Signature_V2) +import PlutusCore.Crypto.Hash qualified as Hash import PlutusCore.Crypto.Secp256k1 (verifyEcdsaSecp256k1Signature, verifySchnorrSecp256k1Signature) import Codec.Serialise (serialise) import Data.ByteString qualified as BS -import Data.ByteString.Hash qualified as Hash import Data.ByteString.Lazy qualified as BSL import Data.Char import Data.Ix @@ -144,8 +144,9 @@ data DefaultFun | Bls12_381_millerLoop | Bls12_381_mulMlResult | Bls12_381_finalVerify - -- Keccak_256 + -- Keccak_256, Blake2b_224 | Keccak_256 + | Blake2b_224 deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Ix) deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc) @@ -1473,6 +1474,10 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where makeBuiltinMeaning Hash.keccak_256 (runCostingFunOneArgument . paramKeccak_256) + toBuiltinMeaning _ver Blake2b_224 = + makeBuiltinMeaning + Hash.blake2b_224 + (runCostingFunOneArgument . paramBlake2b_224) -- See Note [Inlining meanings of builtins]. {-# INLINE toBuiltinMeaning #-} @@ -1579,6 +1584,7 @@ instance Flat DefaultFun where Bls12_381_mulMlResult -> 69 Bls12_381_finalVerify -> 70 Keccak_256 -> 71 + Blake2b_224 -> 72 decode = go =<< decodeBuiltin where go 0 = pure AddInteger @@ -1653,6 +1659,7 @@ instance Flat DefaultFun where go 69 = pure Bls12_381_mulMlResult go 70 = pure Bls12_381_finalVerify go 71 = pure Keccak_256 + go 72 = pure Blake2b_224 go t = fail $ "Failed to decode builtin tag, got: " ++ show t size _ n = n + builtinTagWidth 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 102a98edfee..21e54713bec 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs @@ -153,8 +153,9 @@ data BuiltinCostModelBase f = , paramBls12_381_millerLoop :: f ModelTwoArguments , paramBls12_381_mulMlResult :: f ModelTwoArguments , paramBls12_381_finalVerify :: f ModelTwoArguments - -- Keccak_256 + -- Keccak_256, Blake2b_224 , paramKeccak_256 :: f ModelOneArgument + , paramBlake2b_224 :: f ModelOneArgument } 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 74c3d76bb9e..67784d66d08 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExBudgetingDefaults.hs @@ -195,7 +195,8 @@ unitCostBuiltinCostModel = BuiltinCostModelBase , paramBls12_381_millerLoop = unitCostTwoArguments , paramBls12_381_mulMlResult = unitCostTwoArguments , paramBls12_381_finalVerify = unitCostTwoArguments - -- Keccak_256 + -- Keccak_256, Blake2b_224 , paramKeccak_256 = unitCostOneArgument + , paramBlake2b_224 = unitCostOneArgument } diff --git a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs index 4fbb0b807bd..8b2e2cfc24c 100644 --- a/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs +++ b/plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteFnWithConst.hs @@ -87,7 +87,9 @@ isCommutative = \case -- Cryptography and hashes Sha2_256 -> False Sha3_256 -> False + Blake2b_224 -> False Blake2b_256 -> False + Keccak_256 -> False VerifyEd25519Signature -> False VerifyEcdsaSecp256k1Signature -> False VerifySchnorrSecp256k1Signature -> False @@ -108,7 +110,6 @@ isCommutative = \case Bls12_381_millerLoop -> False Bls12_381_mulMlResult -> False Bls12_381_finalVerify -> False - Keccak_256 -> False -- Strings AppendString -> False EqualsString -> True diff --git a/plutus-metatheory/src/Algorithmic/CEK.lagda.md b/plutus-metatheory/src/Algorithmic/CEK.lagda.md index 1be023e22fb..685f1cf7aba 100644 --- a/plutus-metatheory/src/Algorithmic/CEK.lagda.md +++ b/plutus-metatheory/src/Algorithmic/CEK.lagda.md @@ -292,6 +292,8 @@ BUILTIN bls12-381-mulMlResult (app (app base (V-con (tmBls12-381-mlresult r))) ( BUILTIN bls12-381-finalVerify (app (app base (V-con (tmBls12-381-mlresult r))) (V-con (tmBls12-381-mlresult r'))) = inj₂ (V-con (tmBool (BLS12-381-finalVerify r r'))) BUILTIN keccak-256 (app base (V-con (tmBytestring b))) = inj₂ (V-con (tmBytestring (KECCAK-256 b))) +BUILTIN blake2b-224 (app base (V-con (tmBytestring b))) = + inj₂ (V-con (tmBytestring (BLAKE2B-224 b))) BUILTIN' : ∀ b {A} → ∀{tn} → {pt : tn ∔ 0 ≣ fv♯ (signature b)} diff --git a/plutus-metatheory/src/Builtin.lagda.md b/plutus-metatheory/src/Builtin.lagda.md index d6a8e27605a..9b7db5cc5a9 100644 --- a/plutus-metatheory/src/Builtin.lagda.md +++ b/plutus-metatheory/src/Builtin.lagda.md @@ -122,8 +122,9 @@ data Builtin : Set where bls12-381-millerLoop : Builtin bls12-381-mulMlResult : Builtin bls12-381-finalVerify : Builtin - -- Keccak-256 + -- Keccak-256, Blake2b-224 keccak-256 : Builtin + blake2b-224 : Builtin ``` ## Signatures @@ -275,6 +276,7 @@ This is defined in its own module so that these definitions are not exported. signature bls12-381-mulMlResult = ∙ [ bls12-381-mlresult , bls12-381-mlresult ]⟶ bls12-381-mlresult signature bls12-381-finalVerify = ∙ [ bls12-381-mlresult , bls12-381-mlresult ]⟶ bool signature keccak-256 = ∙ [ bytestring ]⟶ bytestring + signature blake2b-224 = ∙ [ bytestring ]⟶ bytestring open SugaredSignature using (signature) public ``` @@ -357,6 +359,7 @@ Each Agda built-in name must be mapped to a Haskell name. | Bls12_381_mulMlResult | Bls12_381_finalVerify | Keccak_256 + | Blake2b_224 ) #-} ``` @@ -409,6 +412,7 @@ postulate BLS12-381-mulMlResult : Bls12-381-MlResult → Bls12-381-MlResult → Bls12-381-MlResult BLS12-381-finalVerify : Bls12-381-MlResult → Bls12-381-MlResult → Bool KECCAK-256 : ByteString → ByteString + BLAKE2B-224 : ByteString → ByteString ``` ### What builtin operations should be compiled to if we compile to Haskell @@ -419,7 +423,7 @@ postulate {-# FOREIGN GHC import qualified Data.ByteString as BS #-} {-# FOREIGN GHC import qualified Data.ByteArray as B #-} {-# FOREIGN GHC import Debug.Trace (trace) #-} -{-# FOREIGN GHC import Data.ByteString.Hash as Hash #-} +{-# FOREIGN GHC import PlutusCore.Crypto.Hash as Hash #-} {-# FOREIGN GHC import Data.Text.Encoding #-} {-# FOREIGN GHC import qualified Data.Text as Text #-} {-# FOREIGN GHC import Data.Either.Extra (eitherToMaybe) #-} @@ -497,6 +501,7 @@ postulate {-# COMPILE GHC BLS12-381-finalVerify = Pairing.finalVerify #-} {-# COMPILE GHC KECCAK-256 = B.convert . Hash.keccak_256 #-} +{-# COMPILE GHC BLAKE2B-224 = B.convert . Hash.blake2b_224 #-} -- no binding needed for appendStr -- no binding needed for traceStr diff --git a/plutus-metatheory/src/Untyped/CEK.lagda.md b/plutus-metatheory/src/Untyped/CEK.lagda.md index 2685f0c26fb..830782b3490 100644 --- a/plutus-metatheory/src/Untyped/CEK.lagda.md +++ b/plutus-metatheory/src/Untyped/CEK.lagda.md @@ -486,6 +486,10 @@ BUILTIN keccak-256 = λ { (app base (V-con (con bytestring) b)) -> inj₂ (V-con (con bytestring) (KECCAK-256 b)) ; _ -> inj₁ userError } +BUILTIN blake2b-224 = λ + { (app base (V-con (con bytestring) b)) -> inj₂ (V-con (con bytestring) (BLAKE2B-224 b)) + ; _ -> inj₁ userError + } BUILTIN' : ∀ b diff --git a/plutus-tx-plugin/src/PlutusTx/Compiler/Builtins.hs b/plutus-tx-plugin/src/PlutusTx/Compiler/Builtins.hs index cb99c0d3e0b..4d49d35c771 100644 --- a/plutus-tx-plugin/src/PlutusTx/Compiler/Builtins.hs +++ b/plutus-tx-plugin/src/PlutusTx/Compiler/Builtins.hs @@ -168,7 +168,9 @@ builtinNames = [ , 'Builtins.indexByteString , 'Builtins.sha2_256 , 'Builtins.sha3_256 + , 'Builtins.blake2b_224 , 'Builtins.blake2b_256 + , 'Builtins.keccak_256 , 'Builtins.equalsByteString , 'Builtins.lessThanByteString , 'Builtins.lessThanEqualsByteString @@ -307,7 +309,9 @@ defineBuiltinTerms = do defineBuiltinTerm annMayInline 'Builtins.indexByteString $ mkBuiltin PLC.IndexByteString defineBuiltinTerm annMayInline 'Builtins.sha2_256 $ mkBuiltin PLC.Sha2_256 defineBuiltinTerm annMayInline 'Builtins.sha3_256 $ mkBuiltin PLC.Sha3_256 + defineBuiltinTerm annMayInline 'Builtins.blake2b_224 $ mkBuiltin PLC.Blake2b_224 defineBuiltinTerm annMayInline 'Builtins.blake2b_256 $ mkBuiltin PLC.Blake2b_256 + defineBuiltinTerm annMayInline 'Builtins.keccak_256 $ mkBuiltin PLC.Keccak_256 defineBuiltinTerm annMayInline 'Builtins.equalsByteString $ mkBuiltin PLC.EqualsByteString defineBuiltinTerm annMayInline 'Builtins.lessThanByteString $ mkBuiltin PLC.LessThanByteString defineBuiltinTerm annMayInline 'Builtins.lessThanEqualsByteString $ mkBuiltin PLC.LessThanEqualsByteString diff --git a/plutus-tx/src/PlutusTx/Builtins.hs b/plutus-tx/src/PlutusTx/Builtins.hs index af571835b8b..28832dffb23 100644 --- a/plutus-tx/src/PlutusTx/Builtins.hs +++ b/plutus-tx/src/PlutusTx/Builtins.hs @@ -19,7 +19,9 @@ module PlutusTx.Builtins ( , greaterThanEqualsByteString , sha2_256 , sha3_256 + , blake2b_224 , blake2b_256 + , keccak_256 , verifyEd25519Signature , verifyEcdsaSecp256k1Signature , verifySchnorrSecp256k1Signature @@ -144,11 +146,21 @@ sha2_256 = BI.sha2_256 sha3_256 :: BuiltinByteString -> BuiltinByteString sha3_256 = BI.sha3_256 +{-# INLINABLE blake2b_224 #-} +-- | The BLAKE2B-224 hash of a 'ByteString' +blake2b_224 :: BuiltinByteString -> BuiltinByteString +blake2b_224 = BI.blake2b_256 + {-# INLINABLE blake2b_256 #-} -- | The BLAKE2B-256 hash of a 'ByteString' blake2b_256 :: BuiltinByteString -> BuiltinByteString blake2b_256 = BI.blake2b_256 +{-# INLINABLE keccak_256 #-} +-- | The KECCAK-256 hash of a 'ByteString' +keccak_256 :: BuiltinByteString -> BuiltinByteString +keccak_256 = BI.keccak_256 + {-# INLINABLE verifyEd25519Signature #-} -- | Ed25519 signature verification. Verify that the signature is a signature of -- the message by the public key. This will fail if key or the signature are not diff --git a/plutus-tx/src/PlutusTx/Builtins/Internal.hs b/plutus-tx/src/PlutusTx/Builtins/Internal.hs index 059c82570c8..595549179d2 100644 --- a/plutus-tx/src/PlutusTx/Builtins/Internal.hs +++ b/plutus-tx/src/PlutusTx/Builtins/Internal.hs @@ -19,7 +19,6 @@ import Control.DeepSeq (NFData (..)) import Control.Monad.Trans.Writer.Strict (runWriter) import Data.ByteArray qualified as BA import Data.ByteString qualified as BS -import Data.ByteString.Hash qualified as Hash import Data.ByteString.Lazy qualified as BSL import Data.Coerce (coerce) import Data.Data @@ -33,6 +32,7 @@ import PlutusCore.Crypto.BLS12_381.G1 qualified as BLS12_381.G1 import PlutusCore.Crypto.BLS12_381.G2 qualified as BLS12_381.G2 import PlutusCore.Crypto.BLS12_381.Pairing qualified as BLS12_381.Pairing import PlutusCore.Crypto.Ed25519 qualified +import PlutusCore.Crypto.Hash qualified as Hash import PlutusCore.Crypto.Secp256k1 qualified import PlutusCore.Data qualified as PLC import PlutusCore.Evaluation.Result (EvaluationResult (EvaluationFailure, EvaluationSuccess)) @@ -239,10 +239,18 @@ sha2_256 (BuiltinByteString b) = BuiltinByteString $ Hash.sha2_256 b sha3_256 :: BuiltinByteString -> BuiltinByteString sha3_256 (BuiltinByteString b) = BuiltinByteString $ Hash.sha3_256 b +{-# NOINLINE blake2b_224 #-} +blake2b_224 :: BuiltinByteString -> BuiltinByteString +blake2b_224 (BuiltinByteString b) = BuiltinByteString $ Hash.blake2b_224 b + {-# NOINLINE blake2b_256 #-} blake2b_256 :: BuiltinByteString -> BuiltinByteString blake2b_256 (BuiltinByteString b) = BuiltinByteString $ Hash.blake2b_256 b +{-# NOINLINE keccak_256 #-} +keccak_256 :: BuiltinByteString -> BuiltinByteString +keccak_256 (BuiltinByteString b) = BuiltinByteString $ Hash.keccak_256 b + {-# NOINLINE verifyEd25519Signature #-} verifyEd25519Signature :: BuiltinByteString -> BuiltinByteString -> BuiltinByteString -> BuiltinBool verifyEd25519Signature (BuiltinByteString vk) (BuiltinByteString msg) (BuiltinByteString sig) = From 5d474b2ff436ea3f92391086e27297cdba762115 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 7 Jul 2023 16:06:30 +0100 Subject: [PATCH 05/24] Add blake2b_224 --- plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs index 5b95bcd2411..fab8b7ce884 100644 --- a/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs +++ b/plutus-core/cost-model/budgeting-bench/Benchmarks/Crypto.hs @@ -317,5 +317,5 @@ makeBenchmarks gen = [ benchVerifyEd25519Signature , benchVerifyEcdsaSecp256k1Signature , benchVerifySchnorrSecp256k1Signature ] - <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_256, Keccak_256]) + <> (benchByteStringOneArgOp <$> [Sha2_256, Sha3_256, Blake2b_224, Blake2b_256, Keccak_256]) <> blsBenchmarks gen From 1925c6c6a9f376e630a43b0b2f4903a4c6d86b42 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 7 Jul 2023 16:09:16 +0100 Subject: [PATCH 06/24] Add blake2b_224 --- plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs index 91548e1ae84..67323f53617 100644 --- a/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs +++ b/plutus-core/testlib/PlutusCore/Generators/NEAT/Term.hs @@ -399,7 +399,7 @@ defaultFunTypes = Map.fromList [(TyFunG (TyBuiltinG TyIntegerG) (TyFunG (TyBuilt ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyIntegerG) (TyBuiltinG TyIntegerG)) ,[IndexByteString]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyByteStringG) - ,[Sha2_256,Sha3_256,Blake2b_256,Keccak_256]) + ,[Sha2_256,Sha3_256,Blake2b_224,Blake2b_256,Keccak_256]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG))) ,[VerifyEd25519Signature]) ,(TyFunG (TyBuiltinG TyByteStringG) (TyFunG (TyBuiltinG TyByteStringG) (TyBuiltinG TyBoolG)) From dcc817ed14ab2eccf4910b7c3deecc0003cdf829 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 7 Jul 2023 16:39:35 +0100 Subject: [PATCH 07/24] Merge update --- plutus-metatheory/src/Untyped/CEK.lagda.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plutus-metatheory/src/Untyped/CEK.lagda.md b/plutus-metatheory/src/Untyped/CEK.lagda.md index e0697e477b6..9c7aa01f1a7 100644 --- a/plutus-metatheory/src/Untyped/CEK.lagda.md +++ b/plutus-metatheory/src/Untyped/CEK.lagda.md @@ -484,11 +484,11 @@ BUILTIN bls12-381-finalVerify = λ ; _ -> inj₁ userError } BUILTIN keccak-256 = λ - { (app base (V-con (con bytestring) b)) -> inj₂ (V-con (con bytestring) (KECCAK-256 b)) + { (app base (V-con bytestring b)) -> inj₂ (V-con bytestring (KECCAK-256 b)) ; _ -> inj₁ userError } BUILTIN blake2b-224 = λ - { (app base (V-con (con bytestring) b)) -> inj₂ (V-con (con bytestring) (BLAKE2B-224 b)) + { (app base (V-con bytestring b)) -> inj₂ (V-con bytestring (BLAKE2B-224 b)) ; _ -> inj₁ userError } From 824b63d185a9415af4cd32a2820e4ca12bae6ea7 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 7 Jul 2023 17:00:31 +0100 Subject: [PATCH 08/24] Fix a couple of omissions --- .../testlib/PlutusCore/Generators/Hedgehog/Denotation.hs | 3 +++ plutus-tx/src/PlutusTx/Prelude.hs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Denotation.hs b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Denotation.hs index aac26115891..c5bf3bb751c 100644 --- a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Denotation.hs +++ b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Denotation.hs @@ -137,5 +137,8 @@ typedBuiltins . insertBuiltin AppendByteString . insertBuiltin Sha2_256 . insertBuiltin Sha3_256 + . insertBuiltin Blake2b_224 + . insertBuiltin Blake2b_256 + . insertBuiltin Keccak_256 . insertBuiltin EqualsByteString $ DenotationContext mempty diff --git a/plutus-tx/src/PlutusTx/Prelude.hs b/plutus-tx/src/PlutusTx/Prelude.hs index ef888c9ebb8..6f6c09f203a 100644 --- a/plutus-tx/src/PlutusTx/Prelude.hs +++ b/plutus-tx/src/PlutusTx/Prelude.hs @@ -67,6 +67,9 @@ module PlutusTx.Prelude ( -- * Hashes and Signatures sha2_256, sha3_256, + blake2b_224, + blake2b_256, + keccak_256, verifyEd25519Signature, verifyEcdsaSecp256k1Signature, verifySchnorrSecp256k1Signature, From 5413bef9710c9895cbee97060772ee5f9fd2db15 Mon Sep 17 00:00:00 2001 From: kwxm Date: Mon, 10 Jul 2023 08:33:45 +0100 Subject: [PATCH 09/24] Add missing imports --- plutus-tx/src/PlutusTx/Prelude.hs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plutus-tx/src/PlutusTx/Prelude.hs b/plutus-tx/src/PlutusTx/Prelude.hs index 6f6c09f203a..039b2e26ddb 100644 --- a/plutus-tx/src/PlutusTx/Prelude.hs +++ b/plutus-tx/src/PlutusTx/Prelude.hs @@ -118,19 +118,20 @@ import PlutusTx.Base as Base import PlutusTx.Bool as Bool import PlutusTx.Builtins (BuiltinBLS12_381_G1_Element, BuiltinBLS12_381_G2_Element, BuiltinBLS12_381_MlResult, BuiltinByteString, BuiltinData, BuiltinString, - Integer, appendByteString, appendString, bls12_381_G1_add, - bls12_381_G1_compress, bls12_381_G1_equals, bls12_381_G1_generator, - bls12_381_G1_hashToGroup, bls12_381_G1_neg, bls12_381_G1_scalarMul, - bls12_381_G1_uncompress, bls12_381_G1_zero, bls12_381_G2_add, - bls12_381_G2_compress, bls12_381_G2_equals, bls12_381_G2_generator, - bls12_381_G2_hashToGroup, bls12_381_G2_neg, bls12_381_G2_scalarMul, - bls12_381_G2_uncompress, bls12_381_G2_zero, bls12_381_finalVerify, - bls12_381_millerLoop, bls12_381_mulMlResult, consByteString, decodeUtf8, - emptyByteString, emptyString, encodeUtf8, equalsByteString, equalsString, - error, fromBuiltin, greaterThanByteString, indexByteString, - lengthOfByteString, lessThanByteString, sha2_256, sha3_256, - sliceByteString, toBuiltin, trace, verifyEcdsaSecp256k1Signature, - verifyEd25519Signature, verifySchnorrSecp256k1Signature) + Integer, appendByteString, appendString, blake2b_224, blake2b_256, + bls12_381_G1_add, bls12_381_G1_compress, bls12_381_G1_equals, + bls12_381_G1_generator, bls12_381_G1_hashToGroup, bls12_381_G1_neg, + bls12_381_G1_scalarMul, bls12_381_G1_uncompress, bls12_381_G1_zero, + bls12_381_G2_add, bls12_381_G2_compress, bls12_381_G2_equals, + bls12_381_G2_generator, bls12_381_G2_hashToGroup, bls12_381_G2_neg, + bls12_381_G2_scalarMul, bls12_381_G2_uncompress, bls12_381_G2_zero, + bls12_381_finalVerify, bls12_381_millerLoop, bls12_381_mulMlResult, + consByteString, decodeUtf8, emptyByteString, emptyString, encodeUtf8, + equalsByteString, equalsString, error, fromBuiltin, greaterThanByteString, + indexByteString, keccak_256, lengthOfByteString, lessThanByteString, + sha2_256, sha3_256, sliceByteString, toBuiltin, trace, + verifyEcdsaSecp256k1Signature, verifyEd25519Signature, + verifySchnorrSecp256k1Signature) import PlutusTx.Builtins qualified as Builtins import PlutusTx.Either as Either From e464e23406cb5904a56a8f02f8cb5770db564302 Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:30:23 +0100 Subject: [PATCH 10/24] Add keccak_256 and blake2b_224 to V3.ParamName --- plutus-ledger-api/src/PlutusLedgerApi/V3/ParamName.hs | 6 ++++++ plutus-ledger-api/test/Spec/CostModelParams.hs | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plutus-ledger-api/src/PlutusLedgerApi/V3/ParamName.hs b/plutus-ledger-api/src/PlutusLedgerApi/V3/ParamName.hs index 23523a02532..6313a82c545 100644 --- a/plutus-ledger-api/src/PlutusLedgerApi/V3/ParamName.hs +++ b/plutus-ledger-api/src/PlutusLedgerApi/V3/ParamName.hs @@ -232,5 +232,11 @@ data ParamName = | Bls12_381_millerLoop'memory'arguments | Bls12_381_mulMlResult'cpu'arguments | Bls12_381_mulMlResult'memory'arguments + | Keccak_256'cpu'arguments'intercept + | Keccak_256'cpu'arguments'slope + | Keccak_256'memory'arguments + | Blake2b_224'cpu'arguments'intercept + | Blake2b_224'cpu'arguments'slope + | Blake2b_224'memory'arguments deriving stock (Eq, Ord, Enum, Ix, Bounded, Generic) deriving IsParamName via (GenericParamName ParamName) diff --git a/plutus-ledger-api/test/Spec/CostModelParams.hs b/plutus-ledger-api/test/Spec/CostModelParams.hs index 4b7dcee515c..aeffd393a0c 100644 --- a/plutus-ledger-api/test/Spec/CostModelParams.hs +++ b/plutus-ledger-api/test/Spec/CostModelParams.hs @@ -30,13 +30,13 @@ tests = 166 @=? length v1CostModelParamNames 175 @=? length (enumerate @V2.ParamName) 175 @=? length v2CostModelParamNames - 217 @=? length (enumerate @V3.ParamName) - 217 @=? length v3CostModelParamNames + 223 @=? length (enumerate @V3.ParamName) + 223 @=? length v3CostModelParamNames , testCase "context length" $ do let defaultCostValues = Map.elems $ fromJust defaultCostModelParams -- the defaultcostmodelparams reflects only the latest version V3, so this should succeed because the lengths match assertBool "wrong number of arguments in V2.mkContext" $ isRight $ runExcept $ runWriterT $ V3.mkEvaluationContext defaultCostValues - -- currently v2 args ==v3 args + -- currently v2 args == v3 args assertBool "wrong number of arguments in V2.mkContext" $ isRight $ runExcept $ runWriterT $ V2.mkEvaluationContext defaultCostValues -- this one should succeed because we pass more params assertBool "larger number of params did not warn" $ hasWarnMoreParams (length v3CostModelParamNames) (length v3CostModelParamNames+1) $ From f4bb2ef16faa7b8656afc78cae9898b181cf6bd4 Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:34:51 +0100 Subject: [PATCH 11/24] Add test for keccak_256 and blake2b_224 --- .../test/Evaluation/Builtins/Definition.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index 628eda1e098..98a0d7d7a36 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -627,6 +627,15 @@ test_Crypto = testCase "Crypto" $ do -- b2sum -l 256 hex output: 256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610 evals @ByteString "%l\131\178\151\DC1M \ESC0\ETB\159?\SO\240\202\206\151\131b-\165\151C&\180\&6\ETB\138\238\246\DLE" Blake2b_256 [cons @ByteString "hello world"] + -- independently verified by `/usr/bin/b2sum -l 224` with the hex output converted to ascii text + -- b2sum -l 224 hex output: 42d1854b7d69e3b57c64fcc7b4f64171b47dff43fba6ac0499ff437f + evals @ByteString "B\209\133K}i\227\181|d\252\199\180\246Aq\180}\255C\251\166\172\EOT\153\255C\DEL" + Blake2b_224 [cons @ByteString "hello world"] + -- independently verified by the calculator at `https://emn178.github.io/online-tools/keccak_256.html` + -- with the hex output converted to ascii text + -- hex output: 47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad + evals @ByteString "G\ETB2\133\168\215\&4\RS^\151/\198w(c\132\248\STX\248\239B\165\236_\ETX\187\250%L\176\US\173" + Keccak_256 [cons @ByteString "hello world"] -- Test all remaining builtins of the default universe test_Other :: TestTree From 5d348282a9ad115dac5829aef18071888f7e084f Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:35:26 +0100 Subject: [PATCH 12/24] Fake cost model for keccak_256 and blake2b_224 --- plutus-core/cost-model/data/benching.csv | 203 +++++++++--------- .../cost-model/data/builtinCostModel.json | 8 +- 2 files changed, 106 insertions(+), 105 deletions(-) diff --git a/plutus-core/cost-model/data/benching.csv b/plutus-core/cost-model/data/benching.csv index eee7c288905..96b09e2418f 100644 --- a/plutus-core/cost-model/data/benching.csv +++ b/plutus-core/cost-model/data/benching.csv @@ -1,5 +1,6 @@ # Benchmark results for cost model update prior to Vasil HF (12th May 2022). # BLS12-381 results: May 2023 +# Preliminary costing figures for Keccak_256 (same as Sha3_256) and Blake2b_224 (same as Blake2b_256): July 2023 benchmark,t,t.mean.lb,t.mean.ub,t.sd,t.sd.lb,t.sd.ub IfThenElse/100/100,9.903368819621599e-7,9.67013522777269e-7,1.0172648298758596e-6,7.964815537277713e-8,6.98433698700813e-8,9.587075593393516e-8 IfThenElse/100/500,1.0855692272700772e-6,1.0476374612918429e-6,1.1620386696812784e-6,1.5989478294521692e-7,8.85710711974263e-8,3.1376848013729205e-7 @@ -2154,107 +2155,107 @@ Blake2b_256/9700,1.0207647561413394e-4,1.014787688985795e-4,1.0323633561979889e- Blake2b_256/9800,1.0227941028300047e-4,1.017729043697749e-4,1.0444631558372355e-4,2.52368984984658e-6,9.555889044727126e-7,5.869269836003722e-6 Blake2b_256/9900,1.0465353877735825e-4,1.0408786611233812e-4,1.0606485586693787e-4,3.384054598698011e-6,1.6580780889069696e-6,5.960723836126841e-6 Blake2b_256/10000,1.0493704545146666e-4,1.0435372217420162e-4,1.0650937107249171e-4,3.234244305844669e-6,1.125263001034833e-6,5.9368682331128935e-6 -Keccak_256/1,1.058866177553942e-6,1.0351314758107403e-6,1.0997875510129305e-6,9.920708174473134e-8,7.715974291767419e-8,1.2667088115903637e-7 -Keccak_256/100,2.107330600614902e-6,2.085250301573818e-6,2.160520364571667e-6,1.1154563846001125e-7,6.624355320221705e-8,1.8843169839743749e-7 -Keccak_256/200,3.1205266308808506e-6,3.113891238282638e-6,3.1319878747000982e-6,2.601651133118648e-8,1.2867766179902705e-8,4.310562951097803e-8 -Keccak_256/300,4.268730462545677e-6,4.243175561102078e-6,4.3707988665135e-6,1.3543939273131508e-7,3.722883454516397e-8,2.992750325653483e-7 -Keccak_256/400,5.203703999264517e-6,5.181251155914204e-6,5.269964344801538e-6,1.1878782978195955e-7,4.627745172019428e-8,2.351209310363118e-7 -Keccak_256/500,5.9766933425290175e-6,5.943121410413661e-6,6.113447296521537e-6,1.8328390977785487e-7,9.04268173046435e-8,3.6868393318502817e-7 -Keccak_256/600,6.926410268167192e-6,6.899367091404922e-6,7.058435359120732e-6,1.6241938746539412e-7,3.86286372144923e-8,3.6129734443575376e-7 -Keccak_256/700,7.960807600401682e-6,7.919519601426342e-6,8.052751143815135e-6,2.2600124001819423e-7,1.2672491295073285e-7,3.7858569709712303e-7 -Keccak_256/800,8.929845277711268e-6,8.885144560950643e-6,9.020777088973703e-6,2.3054856850272647e-7,1.146045107467147e-7,3.5421889583240286e-7 -Keccak_256/900,1.0141412884144537e-5,1.0066189052329049e-5,1.0275995410819495e-5,3.233198010355464e-7,1.3838809456917152e-7,5.694614551739967e-7 -Keccak_256/1000,1.1079460771572386e-5,1.1017853145970594e-5,1.124148140052456e-5,3.163027938982787e-7,9.833819139493731e-8,5.806592851555981e-7 -Keccak_256/1100,1.2157313241942673e-5,1.2092229754930612e-5,1.2348874671702757e-5,3.274245976729878e-7,1.8347703653825065e-7,6.25660369994514e-7 -Keccak_256/1200,1.3105450473074357e-5,1.3036133931831585e-5,1.3322606046224055e-5,3.624524471377895e-7,1.1985181272133687e-7,7.775664458833712e-7 -Keccak_256/1300,1.4420843458255736e-5,1.427446064578974e-5,1.4974938101890508e-5,8.910347033664329e-7,2.7751065461262917e-7,1.8127861154341888e-6 -Keccak_256/1400,1.5282873742090178e-5,1.518010160184062e-5,1.561995331348422e-5,5.270540076052484e-7,2.1417870110176802e-7,1.044090938240202e-6 -Keccak_256/1500,1.643301672555558e-5,1.625616833037685e-5,1.7028187798634615e-5,8.949825857175185e-7,2.810681685109168e-7,1.922422539301018e-6 -Keccak_256/1600,1.727374155938813e-5,1.7173527988701872e-5,1.752298877037424e-5,5.126226862239113e-7,1.8943612087454928e-7,1.0100415117455722e-6 -Keccak_256/1700,1.8703134079717747e-5,1.8522849684517468e-5,1.898180590588165e-5,8.009447904602967e-7,3.4817061315308816e-7,1.2137044176066547e-6 -Keccak_256/1800,1.9474381009051905e-5,1.932092167719618e-5,2.001293645131103e-5,8.621216674729439e-7,2.372464799203578e-7,1.7575820254208253e-6 -Keccak_256/1900,2.0762284490885648e-5,2.055138474868901e-5,2.162675902998507e-5,1.4593916612620253e-6,4.2127796412191557e-7,3.0024997056874457e-6 -Keccak_256/2000,2.1450953002367843e-5,2.1299691589763634e-5,2.1851485568344984e-5,7.283016629400576e-7,3.2633088472450186e-7,1.3780418191093748e-6 -Keccak_256/2100,2.3151391464857453e-5,2.283998133447509e-5,2.415120557697002e-5,1.6057999274481308e-6,4.579962492140958e-7,3.5285844080917673e-6 -Keccak_256/2200,2.3710908285742288e-5,2.356267116686948e-5,2.40614981178673e-5,7.470645508255186e-7,3.416934396881511e-7,1.3210584404820492e-6 -Keccak_256/2300,2.4938324643164525e-5,2.480399056540811e-5,2.5129706168270916e-5,5.534862976747581e-7,4.873874624407568e-7,7.287070155692917e-7 -Keccak_256/2400,2.5646698818620143e-5,2.5454451725827738e-5,2.6392488459054712e-5,1.041552240439053e-6,2.5855525741466896e-7,2.3036759310004334e-6 -Keccak_256/2500,2.701435782125882e-5,2.6875064429996345e-5,2.7251963757446096e-5,6.656434396496787e-7,5.526538224922398e-7,9.404818053685724e-7 -Keccak_256/2600,2.824619173685573e-5,2.7947274552806432e-5,2.894360703288434e-5,1.617588072821016e-6,5.760960571136145e-7,2.9883607880704334e-6 -Keccak_256/2700,2.8651149710333944e-5,2.8615925497632304e-5,2.8717660384703762e-5,1.487391411405925e-7,9.446005014634933e-8,2.3840337178240049e-7 -Keccak_256/2800,3.070078613147394e-5,3.009899080202408e-5,3.377392753674611e-5,3.4068644712085665e-6,8.869328621305489e-7,7.36197303646939e-6 -Keccak_256/2900,3.066485085874718e-5,3.062366907561051e-5,3.0738968017802157e-5,1.814934696064304e-7,1.0170661869225304e-7,2.9292269928377886e-7 -Keccak_256/3000,3.324166047338545e-5,3.238001006002742e-5,3.6548632045068745e-5,5.1985397666397054e-6,9.085835797766876e-7,1.0958109172879896e-5 -Keccak_256/3100,3.269571701774213e-5,3.26503296983935e-5,3.2892771575489165e-5,2.744226412990958e-7,1.196184308167465e-7,5.369018794725474e-7 -Keccak_256/3200,3.403414498426972e-5,3.383547603766881e-5,3.44060342687195e-5,7.793617065463054e-7,4.947083305077382e-7,1.3640231718038043e-6 -Keccak_256/3300,3.5191911198808575e-5,3.4975856099566444e-5,3.559975958419949e-5,9.554921634053676e-7,4.5106315211441897e-7,1.6732876093183978e-6 -Keccak_256/3400,3.6299983044848614e-5,3.607651654452228e-5,3.6834825835150854e-5,1.1726631208876317e-6,4.7046840498547025e-7,2.0924564783182554e-6 -Keccak_256/3500,3.7184429946046445e-5,3.698739440809114e-5,3.778776848470064e-5,1.0037040121187468e-6,4.0518285929747154e-7,2.2417937175971216e-6 -Keccak_256/3600,3.840866780140864e-5,3.8149050306292474e-5,3.917103224448523e-5,1.2596195116128801e-6,7.963165416815914e-7,2.302352099767382e-6 -Keccak_256/3700,3.9294281823211015e-5,3.9103362977724796e-5,3.994754461695739e-5,1.0025151081715906e-6,4.5802076200791174e-7,1.930475338498495e-6 -Keccak_256/3800,4.085457352424134e-5,4.0475701914508404e-5,4.194606975169997e-5,2.411967997228894e-6,7.143052001834435e-7,4.503547172929313e-6 -Keccak_256/3900,4.1401782967735845e-5,4.1067928100038166e-5,4.2166223812038024e-5,1.6236459936687913e-6,5.723574392853032e-7,2.9409066078574e-6 -Keccak_256/4000,4.305852453950664e-5,4.25592105539392e-5,4.480427691374125e-5,2.701147133021977e-6,9.544936925476275e-7,5.431689349120135e-6 -Keccak_256/4100,4.381019846748734e-5,4.345823180581767e-5,4.482232490214268e-5,1.976761088414672e-6,5.635156238837936e-7,3.6690503220990954e-6 -Keccak_256/4200,4.6452218907865266e-5,4.517575732548842e-5,5.124685950343986e-5,7.996912692664038e-6,1.0134804619726385e-6,1.6890920690060025e-5 -Keccak_256/4300,4.580032601579891e-5,4.5432024546409205e-5,4.675962339730293e-5,1.890892899364981e-6,6.407605370087998e-7,3.469291741968523e-6 -Keccak_256/4400,4.7011542963424426e-5,4.6795994333716095e-5,4.7300630049449276e-5,1.0124011946453653e-6,8.644218843362557e-7,1.262280076812194e-6 -Keccak_256/4500,4.8263428673205516e-5,4.770043989710043e-5,5.017639074740447e-5,3.144072033341603e-6,8.414096897583511e-7,6.452288689517197e-6 -Keccak_256/4600,4.8445901122611766e-5,4.8359560688624594e-5,4.858804554686844e-5,4.166000090724304e-7,2.4245451539383286e-7,6.755278870209941e-7 -Keccak_256/4700,5.1939317614595166e-5,5.025060151226696e-5,5.8514001983542456e-5,1.0719438144258418e-5,1.2565748469896127e-6,2.2712584275315713e-5 -Keccak_256/4800,5.007732684892432e-5,4.999857858036226e-5,5.027397220880092e-5,3.792893042649552e-7,1.485234536903998e-7,7.690060202192783e-7 -Keccak_256/4900,5.2120841871901004e-5,5.1797373719436974e-5,5.3082441682407334e-5,1.7052410870391374e-6,8.100051819458479e-7,3.2276621717440923e-6 -Keccak_256/5000,5.2793199542638503e-5,5.254612254421397e-5,5.325704977869127e-5,1.1785775054919608e-6,5.583864989409697e-7,1.8851786277282938e-6 -Keccak_256/5100,5.3942383638939037e-5,5.3641684623565606e-5,5.431336906455128e-5,1.0707631188104636e-6,6.352626102340837e-7,1.52306614949696e-6 -Keccak_256/5200,5.451166773813132e-5,5.42257349121218e-5,5.5390841649537726e-5,1.5110857868612025e-6,3.8031576971011696e-7,3.2218905469622576e-6 -Keccak_256/5300,5.648801634404324e-5,5.6057818770489175e-5,5.73419066788937e-5,2.0378063732099633e-6,1.1331029003961625e-6,3.6563677932081437e-6 -Keccak_256/5400,5.7254941425727845e-5,5.688940262571059e-5,5.833597570764728e-5,2.133955957253102e-6,7.531025669283287e-7,3.9056456822706396e-6 -Keccak_256/5500,5.872316309731186e-5,5.8328722819704726e-5,5.9364357176065786e-5,1.610008475419188e-6,1.100828386132166e-6,2.4451954155142213e-6 -Keccak_256/5600,5.931210917835381e-5,5.8917152839999444e-5,6.087278722098536e-5,2.2251660045094325e-6,9.15140502453878e-7,4.65950953866282e-6 -Keccak_256/5700,6.215514275557973e-5,6.084891058690365e-5,6.706122421979483e-5,7.73375065641883e-6,1.1322652583957729e-6,1.618904195183443e-5 -Keccak_256/5800,6.175644395456324e-5,6.11933804906771e-5,6.332888995968914e-5,2.420544666988894e-6,1.0000826318531565e-6,4.40525487407305e-6 -Keccak_256/5900,6.243993725928432e-5,6.20368472680124e-5,6.293126931785049e-5,1.5478447285884925e-6,1.2347738979348174e-6,2.2423598546105343e-6 -Keccak_256/6000,6.45410842306157e-5,6.355821704813892e-5,6.73893814759681e-5,5.303784639946252e-6,1.8232975208964398e-6,9.728271235227386e-6 -Keccak_256/6100,6.390970054430798e-5,6.38471562651913e-5,6.400609429196815e-5,2.4718405623831327e-7,1.3995582504990076e-7,3.8434661233437644e-7 -Keccak_256/6200,6.601636626946353e-5,6.562484286334059e-5,6.673227387831775e-5,1.8118162925812202e-6,1.2394943166130247e-6,2.7428832620760607e-6 -Keccak_256/6300,6.587844669577577e-5,6.579556803956619e-5,6.60511269285151e-5,4.2203646929841997e-7,1.7590016138473002e-7,7.086379099907451e-7 -Keccak_256/6400,6.754098701148434e-5,6.711969379426472e-5,6.856807540247602e-5,2.1047584786973716e-6,1.0688208542090978e-6,3.953840013130626e-6 -Keccak_256/6500,6.85018160193559e-5,6.81309063819066e-5,6.923405943162597e-5,1.7659693177738799e-6,8.558135894928747e-7,2.735691609587542e-6 -Keccak_256/6600,6.97291809661803e-5,6.929098170120306e-5,7.056929406155067e-5,2.2314542618911207e-6,1.0536947705981734e-6,3.880722796879969e-6 -Keccak_256/6700,7.033170837816322e-5,6.992204991368149e-5,7.110501415853444e-5,1.9288035182342045e-6,8.285577200839928e-7,3.603829804653193e-6 -Keccak_256/6800,7.215019618956995e-5,7.151798132625188e-5,7.543833525566771e-5,3.5883092032351707e-6,1.2136809275599759e-6,8.24934621126507e-6 -Keccak_256/6900,7.277345027387052e-5,7.227152370896168e-5,7.392639952138141e-5,2.5198544565488386e-6,9.574689231383706e-7,4.497312390884969e-6 -Keccak_256/7000,7.542100015002116e-5,7.457755852181226e-5,7.73659805581287e-5,4.12699378788349e-6,1.6621154064157677e-6,6.826335360140617e-6 -Keccak_256/7100,7.501846925876904e-5,7.441222630450554e-5,7.739560083965258e-5,3.767150719731263e-6,5.844350431639585e-7,7.904480577358747e-6 -Keccak_256/7200,7.625349447348937e-5,7.584288016380027e-5,7.686579021734493e-5,1.935043498212277e-6,1.5019813713618807e-6,2.9743493095957967e-6 -Keccak_256/7300,7.867686996269496e-5,7.736496284462024e-5,8.24428945316185e-5,6.5648083323212774e-6,3.326617479622458e-6,1.1513708345582944e-5 -Keccak_256/7400,7.73331226239276e-5,7.721217382764899e-5,7.755403756649285e-5,5.011023140000701e-7,2.3247717170048617e-7,8.361142791740651e-7 -Keccak_256/7500,7.893505965244809e-5,7.858698474546532e-5,7.9492145557212e-5,1.551120300813045e-6,1.1355369498544397e-6,2.2334530742102727e-6 -Keccak_256/7600,7.951398375468233e-5,7.92427747148934e-5,8.030870027370407e-5,1.7218665966762041e-6,4.5681256214597136e-7,3.2352049838941144e-6 -Keccak_256/7700,8.1452519863899e-5,8.090538447558784e-5,8.295088106225043e-5,2.541211550994998e-6,1.4062664490181118e-6,4.504449111839382e-6 -Keccak_256/7800,8.207903820857649e-5,8.170449004932678e-5,8.313559171862275e-5,1.7105124903471437e-6,8.135065760794694e-7,3.117950198400677e-6 -Keccak_256/7900,8.393147524804484e-5,8.330017167117384e-5,8.62505230255256e-5,3.584872683487768e-6,1.7174784518508134e-6,6.794683285005506e-6 -Keccak_256/8000,8.3825819999056e-5,8.334365663807378e-5,8.526037952056482e-5,2.794970076266031e-6,3.4372149081961747e-7,5.23900546718916e-6 -Keccak_256/8100,8.811153483960476e-5,8.658724146658528e-5,9.337501359265689e-5,8.157238626099442e-6,2.0289028177244018e-6,1.729041815745543e-5 -Keccak_256/8200,8.724097374257806e-5,8.617242852671937e-5,9.095502360181812e-5,5.930613053851916e-6,1.1444343042998763e-6,1.2306206477893369e-5 -Keccak_256/8300,8.751884399990794e-5,8.699274647190729e-5,8.844915407633328e-5,2.1618179344058463e-6,1.3400734366470524e-6,3.7477942102857113e-6 -Keccak_256/8400,9.095964508498637e-5,8.944457726830796e-5,9.515400337929247e-5,9.359538667784902e-6,2.5835708183424045e-6,1.752165469933864e-5 -Keccak_256/8500,8.868933381584902e-5,8.857593091388947e-5,8.901279797094519e-5,6.055788893827932e-7,2.8987326022520383e-7,1.1604345915445252e-6 -Keccak_256/8600,9.057637563844374e-5,9.00547341127989e-5,9.165252316441544e-5,2.428030839144897e-6,1.4056240507150723e-6,4.219498291169897e-6 -Keccak_256/8700,9.110045852574082e-5,9.064162048178214e-5,9.229281232839039e-5,2.137784089836855e-6,1.141433363380656e-6,3.952923630426898e-6 -Keccak_256/8800,9.318871336974877e-5,9.242897700461663e-5,9.562685602332356e-5,3.792748907280084e-6,1.5001028836988998e-6,7.250400004918398e-6 -Keccak_256/8900,9.360329440975812e-5,9.31329278305362e-5,9.497575669370548e-5,2.654514477159443e-6,1.0585127429358854e-6,5.179485832229895e-6 -Keccak_256/9000,9.530259633292818e-5,9.468050564590097e-5,9.6698756954451e-5,3.5708511894771407e-6,1.813471099741736e-6,6.663361005512879e-6 -Keccak_256/9100,9.544428099804767e-5,9.490837827998098e-5,9.738995634107796e-5,2.9818848127578524e-6,1.2378842643534602e-6,5.825349979177486e-6 -Keccak_256/9200,9.951974963995942e-5,9.735144542096317e-5,1.0729565427403032e-4,1.3897449313016696e-5,2.358955213392349e-6,2.9387011525475844e-5 -Keccak_256/9300,9.769975457736239e-5,9.681985473129997e-5,9.976142113799069e-5,4.49771772500704e-6,1.58921803240278e-6,8.806476238062705e-6 -Keccak_256/9400,9.827038630248854e-5,9.816213296341588e-5,9.847520082819936e-5,5.315284097789278e-7,2.492651378522865e-7,8.962233742992072e-7 -Keccak_256/9500,1.0260387829993494e-4,1.0054152132260939e-4,1.0725361150597839e-4,9.55389968763581e-6,2.078358053075761e-6,1.832725832326639e-5 -Keccak_256/9600,1.0007151305427532e-4,9.984253633897067e-5,1.0054280560758327e-4,1.0309806821705763e-6,6.49666813208504e-7,1.7802288080269005e-6 -Keccak_256/9700,1.0207647561413394e-4,1.014787688985795e-4,1.0323633561979889e-4,2.771596965813564e-6,1.691011489945188e-6,4.739988720152948e-6 -Keccak_256/9800,1.0227941028300047e-4,1.017729043697749e-4,1.0444631558372355e-4,2.52368984984658e-6,9.555889044727126e-7,5.869269836003722e-6 -Keccak_256/9900,1.0465353877735825e-4,1.0408786611233812e-4,1.0606485586693787e-4,3.384054598698011e-6,1.6580780889069696e-6,5.960723836126841e-6 -Keccak_256/10000,1.0493704545146666e-4,1.0435372217420162e-4,1.0650937107249171e-4,3.234244305844669e-6,1.125263001034833e-6,5.9368682331128935e-6 +Keccak_256/1,2.6637834364908643e-6,2.6500683436362203e-6,2.6940990934882223e-6,7.415380686554382e-8,1.4234384592361887e-8,1.3926238073876516e-7 +Keccak_256/100,1.0384878923789275e-5,1.0299518982811075e-5,1.0587551499338973e-5,4.1546040513805105e-7,2.0402128569845577e-7,7.440229206636783e-7 +Keccak_256/200,1.873272007391154e-5,1.8651702127581144e-5,1.9013053381316348e-5,4.797634496754229e-7,2.1966656567060545e-7,9.227643922677627e-7 +Keccak_256/300,2.7376395809513264e-5,2.7203016107623865e-5,2.7838894304495133e-5,1.0130219256635149e-6,4.970229570247994e-7,1.7636355307830306e-6 +Keccak_256/400,3.5529661625208374e-5,3.5332554663952266e-5,3.623965856008854e-5,1.081379721815545e-6,3.4823242508602053e-7,2.332587052505977e-6 +Keccak_256/500,4.441131400074538e-5,4.4149139869194216e-5,4.512674889457937e-5,1.482740687532944e-6,7.845556437216703e-7,2.5542466268827426e-6 +Keccak_256/600,5.231311872948966e-5,5.2027855325213246e-5,5.2931128155400976e-5,1.3419411050607229e-6,6.591928643308637e-7,2.471737516377871e-6 +Keccak_256/700,6.146197162420632e-5,6.082527665157453e-5,6.43991455246836e-5,3.603947323683563e-6,9.489810966909419e-7,8.00269679583419e-6 +Keccak_256/800,6.925798488595668e-5,6.893327332219402e-5,7.000112228243194e-5,1.6206521866158302e-6,1.1016054107030048e-6,2.5968216832452853e-6 +Keccak_256/900,7.741020799070552e-5,7.665606746398165e-5,7.951782810578138e-5,4.4169850078491486e-6,1.157141009704791e-6,9.11377583808473e-6 +Keccak_256/1000,8.4596594930448e-5,8.415063459548403e-5,8.568104067461462e-5,2.324895116686479e-6,9.473143053643448e-7,4.131836731295439e-6 +Keccak_256/1100,9.516526156241932e-5,9.420843511516844e-5,9.783935295065141e-5,5.0944163525223965e-6,2.251528991731225e-6,9.972743029229619e-6 +Keccak_256/1200,1.013260652131899e-4,1.007406888853914e-4,1.0337606662971892e-4,3.359645913846741e-6,6.77657250283219e-7,7.00972650505731e-6 +Keccak_256/1300,1.1035615134068431e-4,1.0984144923636734e-4,1.1099193071262251e-4,2.1706601087708973e-6,1.6687978929868126e-6,3.1255453200444803e-6 +Keccak_256/1400,1.1851532492993163e-4,1.1782019720799248e-4,1.2011816823759949e-4,3.332203339558678e-6,1.8339716469854883e-6,5.743576545338824e-6 +Keccak_256/1500,1.2665599890162378e-4,1.2605415919277207e-4,1.2725391531342824e-4,2.071584236704953e-6,1.693911238356604e-6,2.526733588237636e-6 +Keccak_256/1600,1.3557606282927736e-4,1.3463946762643135e-4,1.3811604346016434e-4,5.026477400899149e-6,2.1652660120928515e-6,9.89972002078025e-6 +Keccak_256/1700,1.428129814295034e-4,1.4234237091288726e-4,1.435974265442861e-4,2.152496444575058e-6,1.327602384680457e-6,2.861506191181342e-6 +Keccak_256/1800,1.5218453663150982e-4,1.5072629396311867e-4,1.5763716488451654e-4,9.24673644204529e-6,2.3528961227796473e-6,1.9192893674104223e-5 +Keccak_256/1900,1.577510947381966e-4,1.5764170581813192e-4,1.5795530014060032e-4,4.7228565629112143e-7,3.7675225466089085e-7,6.487170396523074e-7 +Keccak_256/2000,1.681885238682706e-4,1.6737543495110794e-4,1.6945866534499738e-4,3.515695916931956e-6,2.321911792255769e-6,5.890930736521897e-6 +Keccak_256/2100,1.743270813639824e-4,1.7411796816697828e-4,1.7484476227524226e-4,1.1219249485088755e-6,6.710791012939064e-7,1.9872299349957094e-6 +Keccak_256/2200,1.8491055736666117e-4,1.8381575295519002e-4,1.8668688183533808e-4,4.7117674548669546e-6,2.8566296759093374e-6,7.486704332652367e-6 +Keccak_256/2300,1.9109176997217866e-4,1.9074188947386695e-4,1.9205951827297408e-4,1.9086628329852974e-6,6.091924716541135e-7,3.906594979141733e-6 +Keccak_256/2400,2.0106130097335504e-4,2.001087425852568e-4,2.0228460430107644e-4,3.9564811300095e-6,2.9560558989046624e-6,6.0102572526643595e-6 +Keccak_256/2500,2.0834186136102124e-4,2.0756680107002302e-4,2.1066999775414555e-4,4.070577234738832e-6,1.9728591619750054e-6,7.962562302955725e-6 +Keccak_256/2600,2.1673777208398385e-4,2.1577198961616494e-4,2.1821018034657273e-4,4.447071486011747e-6,3.2307309425119235e-6,6.472155781642112e-6 +Keccak_256/2700,2.2357236324599492e-4,2.2285435994483702e-4,2.2572739991502956e-4,3.73088088056033e-6,1.8909597669435455e-6,7.07064406172045e-6 +Keccak_256/2800,2.3364739446605733e-4,2.3267394372490793e-4,2.3542839712253143e-4,4.9895589027612055e-6,3.977433542266473e-6,6.726761052192333e-6 +Keccak_256/2900,2.4034020040115804e-4,2.395177322456027e-4,2.4233724272802154e-4,4.0952739571449755e-6,9.600437672170778e-7,8.776739703436944e-6 +Keccak_256/3000,2.50614448444733e-4,2.4889110154317827e-4,2.557022737831864e-4,8.30223430895056e-6,4.130906692062173e-6,1.5271163252013033e-5 +Keccak_256/3100,2.5772101000720295e-4,2.5659261734820715e-4,2.594181752891131e-4,4.6976665456669936e-6,2.2820716748818774e-6,8.380871180444725e-6 +Keccak_256/3200,2.7023491910601444e-4,2.675713097028704e-4,2.7770096095361803e-4,1.4646774568379722e-5,5.055333412028661e-6,2.7041863196337112e-5 +Keccak_256/3300,2.750980830534133e-4,2.7378934293615314e-4,2.7757490473989736e-4,6.75328979802326e-6,4.145205052760608e-6,1.0830611597489727e-5 +Keccak_256/3400,2.8810645244606065e-4,2.8610016557514427e-4,2.942447090001034e-4,1.1085403492504216e-5,4.958469568090809e-6,2.1248265068942765e-5 +Keccak_256/3500,2.900903795275683e-4,2.8876842967186694e-4,2.96278908217471e-4,8.052764701778327e-6,2.3314230092612353e-6,1.7709611288378073e-5 +Keccak_256/3600,3.0140808129857955e-4,2.997665903384135e-4,3.039702841524672e-4,6.52338138388585e-6,5.1504113118086385e-6,9.684747056064236e-6 +Keccak_256/3700,3.080307244751622e-4,3.061232170167755e-4,3.127202265481372e-4,9.13856089993026e-6,5.1491746373728935e-6,1.6128118816150775e-5 +Keccak_256/3800,3.1435638978319493e-4,3.1342562026928303e-4,3.1594077818708466e-4,4.573680406419949e-6,2.524274448484961e-6,6.687420574651699e-6 +Keccak_256/3900,3.2941997969328495e-4,3.2549705014629587e-4,3.389113884194543e-4,2.0874130589243927e-5,7.47827618804301e-6,3.856988915581171e-5 +Keccak_256/4000,3.297828026148832e-4,3.2938449416981797e-4,3.308565306216013e-4,2.038203359372591e-6,1.1100625252234633e-6,3.6861089156556844e-6 +Keccak_256/4100,3.3928976976385774e-4,3.382071016201025e-4,3.412588354349887e-4,4.624782556027045e-6,2.283934348741967e-6,8.147238926401684e-6 +Keccak_256/4200,3.4795187481351583e-4,3.4664815123199364e-4,3.5206539820220747e-4,6.3927444473131775e-6,2.888333042004809e-6,1.1126279895453884e-5 +Keccak_256/4300,3.551051631725477e-4,3.5338445279766947e-4,3.590642567739351e-4,7.684859735785069e-6,4.7560962773875295e-6,1.299511036091701e-5 +Keccak_256/4400,3.635402936806696e-4,3.6248169712833667e-4,3.65552606310045e-4,5.136971088890153e-6,3.283805175618681e-6,7.949387929812838e-6 +Keccak_256/4500,3.741135580718237e-4,3.718044707316597e-4,3.779241157201648e-4,8.988928332855831e-6,6.015376775198757e-6,1.4359243728834066e-5 +Keccak_256/4600,3.7932114037943384e-4,3.781569971062559e-4,3.822097234211708e-4,5.80702616161616e-6,1.8788321994079397e-6,1.265030775187973e-5 +Keccak_256/4700,3.91254701359179e-4,3.887697301408231e-4,3.957097405148063e-4,1.1188980996314521e-5,6.856985435010405e-6,1.9256627969433442e-5 +Keccak_256/4800,3.972097837997648e-4,3.956100722435229e-4,3.9960758944327854e-4,6.756337912741137e-6,3.7097471622818896e-6,1.1044017622313881e-5 +Keccak_256/4900,4.1024492978727504e-4,4.070854155920875e-4,4.165966112549566e-4,1.652111370040386e-5,6.710840261505874e-6,2.9983355268144866e-5 +Keccak_256/5000,4.139671095049149e-4,4.119753614225236e-4,4.186699313904884e-4,1.01418839091986e-5,3.830494108089602e-6,1.8157661313875703e-5 +Keccak_256/5100,4.295178972149762e-4,4.2614284888913646e-4,4.425035969318529e-4,2.091501955985991e-5,6.025657185789001e-6,4.2909160150910666e-5 +Keccak_256/5200,4.3185360206268616e-4,4.289534731165703e-4,4.415814992573456e-4,1.5665050669888664e-5,6.30670500093019e-6,3.0201486246834207e-5 +Keccak_256/5300,4.3637417902577376e-4,4.3545972043629956e-4,4.3873967992814444e-4,4.992753851847736e-6,2.1250217401119317e-6,9.671117477728313e-6 +Keccak_256/5400,4.5098675398703807e-4,4.475291188273498e-4,4.5611970156876337e-4,1.5170600274226752e-5,9.53841803817166e-6,2.1483820527672436e-5 +Keccak_256/5500,4.519031911535861e-4,4.5148933834358233e-4,4.5284329582967415e-4,2.215133847643241e-6,1.2730825625332917e-6,3.727085485553896e-6 +Keccak_256/5600,4.704036029263635e-4,4.6654021458069283e-4,4.802992643466273e-4,1.9153838150789107e-5,9.481974981034492e-6,3.605827586701094e-5 +Keccak_256/5700,4.691813771230415e-4,4.684129833777636e-4,4.717729238732512e-4,3.914272738012923e-6,1.539475732902292e-6,8.078066903247671e-6 +Keccak_256/5800,4.8044705013704887e-4,4.788280844699025e-4,4.837021581274331e-4,8.506741461376966e-6,6.22035940004687e-6,1.3409045013356972e-5 +Keccak_256/5900,4.890050632086859e-4,4.862440434807285e-4,4.943215411041448e-4,1.2571344847392131e-5,5.1996966121898e-6,2.1046076745501723e-5 +Keccak_256/6000,4.967156303098427e-4,4.94556214191154e-4,5.025870720689423e-4,1.0753560075394183e-5,6.994493353512699e-6,1.816648463474485e-5 +Keccak_256/6100,5.020905730526634e-4,5.004879758803594e-4,5.056614178163512e-4,7.975241245773403e-6,5.294508217603698e-6,1.1550677843168308e-5 +Keccak_256/6200,5.167845063028143e-4,5.138153244020399e-4,5.221637293741477e-4,1.3916402011442033e-5,8.590710711979322e-6,2.2858297903772485e-5 +Keccak_256/6300,5.200284416881216e-4,5.177831035624464e-4,5.241397811585168e-4,9.695476508625677e-6,4.236494070820014e-6,1.81621198672742e-5 +Keccak_256/6400,5.410187723276736e-4,5.342596610082935e-4,5.589732750590747e-4,3.658265071101594e-5,1.1193401196670726e-5,6.74960563110616e-5 +Keccak_256/6500,5.373981341007184e-4,5.345359586706052e-4,5.455865300292178e-4,1.50090426149825e-5,5.259039690902752e-6,2.94681914868859e-5 +Keccak_256/6600,5.480481053617652e-4,5.451595783813507e-4,5.514468044076349e-4,9.738957254639473e-6,7.223375798639206e-6,1.2671718566294824e-5 +Keccak_256/6700,5.608422322785302e-4,5.559298691535741e-4,5.745419400184589e-4,2.5440959657263225e-5,1.2360409554175836e-5,4.8078262383517483e-5 +Keccak_256/6800,5.599954931188882e-4,5.591750581803563e-4,5.615390113975694e-4,3.766396149888457e-6,2.0647551653990656e-6,5.988335983330024e-6 +Keccak_256/6900,5.741813365641268e-4,5.719249805644799e-4,5.774651034301985e-4,1.043558730641999e-5,8.676046155393541e-6,1.3385792133420242e-5 +Keccak_256/7000,5.750612390397035e-4,5.743785751161468e-4,5.763351750986648e-4,3.3384495657748045e-6,2.151661751700496e-6,4.767815307407561e-6 +Keccak_256/7100,5.871740764581088e-4,5.846103152538361e-4,5.90659332111672e-4,1.0449874090148043e-5,8.087867591215027e-6,1.385640505451476e-5 +Keccak_256/7200,5.940417207763448e-4,5.922586799087095e-4,5.972962336875984e-4,8.200316849895089e-6,5.167451594537617e-6,1.2178253404699001e-5 +Keccak_256/7300,6.055955771367805e-4,6.026185164686538e-4,6.10342641355597e-4,1.3322203723001107e-5,9.060523444356078e-6,2.16579030807173e-5 +Keccak_256/7400,6.10492811699494e-4,6.081130497549421e-4,6.154479553246858e-4,1.1302232855346995e-5,4.951395964352462e-6,2.1116760669484014e-5 +Keccak_256/7500,6.278178047296497e-4,6.23050981489455e-4,6.420801751468504e-4,2.6318404734385527e-5,1.0660747883637787e-5,5.2025657392045616e-5 +Keccak_256/7600,6.29844181634675e-4,6.267953894628897e-4,6.400920633647427e-4,1.7448639365674905e-5,1.0095288007081883e-5,3.169236042810735e-5 +Keccak_256/7700,6.453729091807372e-4,6.387165446362803e-4,6.666036267029603e-4,3.830121496960569e-5,1.3616992759634221e-5,7.730648758545404e-5 +Keccak_256/7800,6.440168174302182e-4,6.403595655751105e-4,6.530978124600925e-4,1.8648718453731754e-5,9.112824297263112e-6,3.208189849624319e-5 +Keccak_256/7900,6.507898966590318e-4,6.487378447773963e-4,6.550741788703146e-4,8.889556443286878e-6,6.2749331455985695e-6,1.2286757223630543e-5 +Keccak_256/8000,6.675793489927192e-4,6.625092089178659e-4,6.817835294053653e-4,2.861479659986518e-5,1.3943381224895395e-5,4.96172630467765e-5 +Keccak_256/8100,6.637869362714735e-4,6.630265713991821e-4,6.66617773709556e-4,4.099714800619507e-6,1.546977987769956e-6,8.98052526216875e-6 +Keccak_256/8200,6.768407432111539e-4,6.739746738882888e-4,6.812254501144184e-4,1.2849021093430535e-5,8.469458192410848e-6,1.9337861527584046e-5 +Keccak_256/8300,6.849100561676128e-4,6.823832770515572e-4,6.909865982556507e-4,1.3394624651058318e-5,8.214241859687581e-6,2.2229652182793725e-5 +Keccak_256/8400,6.950319041341391e-4,6.922545712023196e-4,7.007790433676476e-4,1.2837947317726925e-5,8.6648595641488e-6,2.1591786424383653e-5 +Keccak_256/8500,7.016659083234887e-4,6.993715784904575e-4,7.081115667423045e-4,1.2141057630787694e-5,4.540171201415418e-6,2.3674583441142757e-5 +Keccak_256/8600,7.137115213526595e-4,7.102961773433777e-4,7.285870635979069e-4,2.1240891489599457e-5,9.447281322612378e-6,4.4354961668817335e-5 +Keccak_256/8700,7.166113393569523e-4,7.1424839665635e-4,7.214250310107626e-4,1.1819720244484975e-5,5.227361017338131e-6,2.2565047621077503e-5 +Keccak_256/8800,7.308315105052713e-4,7.27769608967153e-4,7.356294647319879e-4,1.2639095581376595e-5,1.0912908325334058e-5,1.4500625346390942e-5 +Keccak_256/8900,7.373734771071274e-4,7.33129401377429e-4,7.459299457390334e-4,2.1583715424993908e-5,8.130743387019095e-6,4.10910843275842e-5 +Keccak_256/9000,7.392834523254786e-4,7.38430119430436e-4,7.40957462045368e-4,4.019393574879251e-6,2.5717498496947086e-6,6.669832216764657e-6 +Keccak_256/9100,7.557172477394312e-4,7.521912826601422e-4,7.603776443013758e-4,1.4924287673410182e-5,1.2805427772856144e-5,1.718028900730454e-5 +Keccak_256/9200,7.581449242395754e-4,7.552431650597578e-4,7.645187804446517e-4,1.3596831090199132e-5,7.225032453834538e-6,2.453737042398974e-5 +Keccak_256/9300,7.70130974845434e-4,7.66335023770309e-4,7.755764686791857e-4,1.5447582446194295e-5,1.199541980217028e-5,2.08587867808974e-5 +Keccak_256/9400,7.727548143378526e-4,7.706575998921518e-4,7.794037906637187e-4,1.2869460476143076e-5,6.4487090710073795e-6,2.2347626113306032e-5 +Keccak_256/9500,7.916204932726256e-4,7.855447591130216e-4,8.055450959002214e-4,2.5212825682776374e-5,1.4843411494727653e-5,4.1388810981618446e-5 +Keccak_256/9600,7.910325950453119e-4,7.878667634635248e-4,7.975579547416167e-4,1.3761291546428596e-5,7.855406564288026e-6,2.167342607962298e-5 +Keccak_256/9700,8.184775111568476e-4,8.089090018237341e-4,8.751242624177473e-4,6.0368653014329285e-5,1.5265992920198803e-5,1.4322761069108847e-4 +Keccak_256/9800,8.095645418212397e-4,8.05394215887996e-4,8.185480517399119e-4,2.10946726921052e-5,6.610203607768696e-6,3.8844482240486675e-5 +Keccak_256/9900,8.116231077469047e-4,8.104827185059911e-4,8.130504208793394e-4,4.2711860568391396e-6,2.7705045089524583e-6,6.140711087195331e-6 +Keccak_256/10000,8.412102672028462e-4,8.339496757219296e-4,8.599082587034181e-4,4.2108581870608e-5,2.281467790187134e-5,7.083353993279055e-5 Bls12_381_G1_add/12/12,1.66632732699414e-6,1.66529329666621e-6,1.6672949997954758e-6,3.5081441131624374e-9,3.0809353761891355e-9,4.092938813345758e-9 Bls12_381_G1_add/12/12,1.6753127089572078e-6,1.6744838692321767e-6,1.6762510140685204e-6,3.0956520418533004e-9,2.5666119678554987e-9,3.680937282056884e-9 Bls12_381_G1_add/12/12,1.6641381470922022e-6,1.6633073889172297e-6,1.6650520313544842e-6,2.9164556837276715e-9,2.3800451071253958e-9,3.586341322980612e-9 diff --git a/plutus-core/cost-model/data/builtinCostModel.json b/plutus-core/cost-model/data/builtinCostModel.json index a1558756127..e1fd262c885 100644 --- a/plutus-core/cost-model/data/builtinCostModel.json +++ b/plutus-core/cost-model/data/builtinCostModel.json @@ -60,8 +60,8 @@ "blake2b_224": { "cpu": { "arguments": { - "intercept": 9999999999, - "slope": 9999999999 + "intercept": 117366, + "slope": 10475 }, "type": "linear_cost" }, @@ -483,8 +483,8 @@ "keccak_256": { "cpu": { "arguments": { - "intercept": 9999999999, - "slope": 9999999999 + "intercept": 1927926, + "slope": 82523 }, "type": "linear_cost" }, From 2b35645f7d73d9b3badfa5b8dc2f0697c4de7216 Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:39:11 +0100 Subject: [PATCH 13/24] Update json file for CostModelInterface tests --- .../defaultCostModelParams.json | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/plutus-core/plutus-core/test/CostModelInterface/defaultCostModelParams.json b/plutus-core/plutus-core/test/CostModelInterface/defaultCostModelParams.json index 22e6d2d58bb..075a87e260f 100644 --- a/plutus-core/plutus-core/test/CostModelInterface/defaultCostModelParams.json +++ b/plutus-core/plutus-core/test/CostModelInterface/defaultCostModelParams.json @@ -13,15 +13,60 @@ "appendString-memory-arguments-slope": 1, "bData-cpu-arguments": 1000, "bData-memory-arguments": 32, + "blake2b_224-cpu-arguments-intercept": 117366, + "blake2b_224-cpu-arguments-slope": 10475, + "blake2b_224-memory-arguments": 4, "blake2b_256-cpu-arguments-intercept": 117366, "blake2b_256-cpu-arguments-slope": 10475, "blake2b_256-memory-arguments": 4, + "bls12_381_G1_add-cpu-arguments": 1046420, + "bls12_381_G1_add-memory-arguments": 18, + "bls12_381_G1_compress-cpu-arguments": 3387741, + "bls12_381_G1_compress-memory-arguments": 6, + "bls12_381_G1_equal-cpu-arguments": 545063, + "bls12_381_G1_equal-memory-arguments": 1, + "bls12_381_G1_hashToGroup-cpu-arguments-intercept": 66311195, + "bls12_381_G1_hashToGroup-cpu-arguments-slope": 23097, + "bls12_381_G1_hashToGroup-memory-arguments": 18, + "bls12_381_G1_neg-cpu-arguments": 292890, + "bls12_381_G1_neg-memory-arguments": 18, + "bls12_381_G1_scalarMul-cpu-arguments-intercept": 94607019, + "bls12_381_G1_scalarMul-cpu-arguments-slope": 87060, + "bls12_381_G1_scalarMul-memory-arguments": 18, + "bls12_381_G1_uncompress-cpu-arguments": 16598737, + "bls12_381_G1_uncompress-memory-arguments": 18, + "bls12_381_G2_add-cpu-arguments": 2359410, + "bls12_381_G2_add-memory-arguments": 36, + "bls12_381_G2_compress-cpu-arguments": 3973992, + "bls12_381_G2_compress-memory-arguments": 12, + "bls12_381_G2_equal-cpu-arguments": 1102635, + "bls12_381_G2_equal-memory-arguments": 1, + "bls12_381_G2_hashToGroup-cpu-arguments-intercept": 204557793, + "bls12_381_G2_hashToGroup-cpu-arguments-slope": 23271, + "bls12_381_G2_hashToGroup-memory-arguments": 36, + "bls12_381_G2_neg-cpu-arguments": 307813, + "bls12_381_G2_neg-memory-arguments": 36, + "bls12_381_G2_scalarMul-cpu-arguments-intercept": 190191402, + "bls12_381_G2_scalarMul-cpu-arguments-slope": 85902, + "bls12_381_G2_scalarMul-memory-arguments": 36, + "bls12_381_G2_uncompress-cpu-arguments": 33191512, + "bls12_381_G2_uncompress-memory-arguments": 36, + "bls12_381_finalVerify-cpu-arguments": 388656972, + "bls12_381_finalVerify-memory-arguments": 1, + "bls12_381_millerLoop-cpu-arguments": 402099373, + "bls12_381_millerLoop-memory-arguments": 72, + "bls12_381_mulMlResult-cpu-arguments": 2544991, + "bls12_381_mulMlResult-memory-arguments": 72, "cekApplyCost-exBudgetCPU": 23000, "cekApplyCost-exBudgetMemory": 100, "cekBuiltinCost-exBudgetCPU": 23000, "cekBuiltinCost-exBudgetMemory": 100, + "cekCaseCost-exBudgetCPU": 23000, + "cekCaseCost-exBudgetMemory": 100, "cekConstCost-exBudgetCPU": 23000, "cekConstCost-exBudgetMemory": 100, + "cekConstrCost-exBudgetCPU": 23000, + "cekConstrCost-exBudgetMemory": 100, "cekDelayCost-exBudgetCPU": 23000, "cekDelayCost-exBudgetMemory": 100, "cekForceCost-exBudgetCPU": 23000, @@ -82,6 +127,9 @@ "ifThenElse-memory-arguments": 1, "indexByteString-cpu-arguments": 57667, "indexByteString-memory-arguments": 4, + "keccak_256-cpu-arguments-intercept": 1927926, + "keccak_256-cpu-arguments-slope": 82523, + "keccak_256-memory-arguments": 4, "lengthOfByteString-cpu-arguments": 1000, "lengthOfByteString-memory-arguments": 10, "lessThanByteString-cpu-arguments-intercept": 197145, @@ -166,12 +214,12 @@ "unListData-memory-arguments": 32, "unMapData-cpu-arguments": 38314, "unMapData-memory-arguments": 32, - "verifyEcdsaSecp256k1Signature-cpu-arguments": 35892428, + "verifyEcdsaSecp256k1Signature-cpu-arguments": 35190005, "verifyEcdsaSecp256k1Signature-memory-arguments": 10, - "verifyEd25519Signature-cpu-arguments-intercept": 9462713, - "verifyEd25519Signature-cpu-arguments-slope": 1021, + "verifyEd25519Signature-cpu-arguments-intercept": 57996947, + "verifyEd25519Signature-cpu-arguments-slope": 18975, "verifyEd25519Signature-memory-arguments": 10, - "verifySchnorrSecp256k1Signature-cpu-arguments-intercept": 38887044, - "verifySchnorrSecp256k1Signature-cpu-arguments-slope": 32947, + "verifySchnorrSecp256k1Signature-cpu-arguments-intercept": 39121781, + "verifySchnorrSecp256k1Signature-cpu-arguments-slope": 32260, "verifySchnorrSecp256k1Signature-memory-arguments": 10 } From 3847cca13de991c7468aff0ff31d5701e1ae36ec Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:51:03 +0100 Subject: [PATCH 14/24] Add changelog entries --- .../20230720_184504_kenneth.mackenzie_keccak256.md | 5 +++++ .../20230720_184626_kenneth.mackenzie_keccak256.md | 4 ++++ .../20230720_184825_kenneth.mackenzie_keccak256.md | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 plutus-core/changelog.d/20230720_184504_kenneth.mackenzie_keccak256.md create mode 100644 plutus-ledger-api/changelog.d/20230720_184626_kenneth.mackenzie_keccak256.md create mode 100644 plutus-tx/changelog.d/20230720_184825_kenneth.mackenzie_keccak256.md diff --git a/plutus-core/changelog.d/20230720_184504_kenneth.mackenzie_keccak256.md b/plutus-core/changelog.d/20230720_184504_kenneth.mackenzie_keccak256.md new file mode 100644 index 00000000000..d2db5f34a13 --- /dev/null +++ b/plutus-core/changelog.d/20230720_184504_kenneth.mackenzie_keccak256.md @@ -0,0 +1,5 @@ +### Added + +- `keccak_256` builtin +- `blake2b_224` builtin + diff --git a/plutus-ledger-api/changelog.d/20230720_184626_kenneth.mackenzie_keccak256.md b/plutus-ledger-api/changelog.d/20230720_184626_kenneth.mackenzie_keccak256.md new file mode 100644 index 00000000000..778976f374d --- /dev/null +++ b/plutus-ledger-api/changelog.d/20230720_184626_kenneth.mackenzie_keccak256.md @@ -0,0 +1,4 @@ +### Added + +- cost model parameters for `keccak_256` builtin +- cost model parameters for `blake2b_224` builtin diff --git a/plutus-tx/changelog.d/20230720_184825_kenneth.mackenzie_keccak256.md b/plutus-tx/changelog.d/20230720_184825_kenneth.mackenzie_keccak256.md new file mode 100644 index 00000000000..88d1c59636e --- /dev/null +++ b/plutus-tx/changelog.d/20230720_184825_kenneth.mackenzie_keccak256.md @@ -0,0 +1,4 @@ +### Added + +- Haskell function for `keccak_256` builtin +- Haskell function for `blake2b_224` builtin From 11a1d4c74b4545a4f9f215e55396d7eed946007a Mon Sep 17 00:00:00 2001 From: kwxm Date: Thu, 20 Jul 2023 18:56:20 +0100 Subject: [PATCH 15/24] Add Keccak_256 and Blake2b_224 to Versions.hs in plutus-ledger-api --- plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs b/plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs index bb7a48742fe..f2552fe4cfc 100644 --- a/plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs +++ b/plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs @@ -108,7 +108,8 @@ builtinsIntroducedIn = Map.fromList [ Bls12_381_G2_add, Bls12_381_G2_neg, Bls12_381_G2_scalarMul, Bls12_381_G2_equal, Bls12_381_G2_hashToGroup, Bls12_381_G2_compress, Bls12_381_G2_uncompress, - Bls12_381_millerLoop, Bls12_381_mulMlResult, Bls12_381_finalVerify + Bls12_381_millerLoop, Bls12_381_mulMlResult, Bls12_381_finalVerify, + Keccak_256, Blake2b_224 ]) ] From 2213976d794e2e1d829467aeb0de345d35219240 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 21 Jul 2023 12:28:49 +0100 Subject: [PATCH 16/24] Typo in comment --- plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs index d0f879dc45b..31b4606132f 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs @@ -24,7 +24,7 @@ sha2_256 = digest (Proxy @SHA256) sha3_256 :: BS.ByteString -> BS.ByteString sha3_256 = digest (Proxy @SHA3_256) --- | Hash a [[BSL.ByteString]] using the Blake2B-256 hash function. +-- | Hash a [[BSL.ByteString]] using the Blake2B-224 hash function. blake2b_224 :: BS.ByteString -> BS.ByteString blake2b_224 = digest (Proxy @Blake2b_224) From f8d5adf0e9b558a63a233cb4126eee58a5eebb0c Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 21 Jul 2023 12:34:26 +0100 Subject: [PATCH 17/24] Typo in comment --- plutus-core/plutus-core/test/CostModelInterface/Spec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-core/plutus-core/test/CostModelInterface/Spec.hs b/plutus-core/plutus-core/test/CostModelInterface/Spec.hs index 384709dcfd8..a1c3bb2721a 100644 --- a/plutus-core/plutus-core/test/CostModelInterface/Spec.hs +++ b/plutus-core/plutus-core/test/CostModelInterface/Spec.hs @@ -35,7 +35,7 @@ that we provide, but there's opportunity for things to move out of sync: So it's sensible to have some regression tests. -We can't just test against out own 'defaultCostModelParams', since in the case of error 2 that would +We can't just test against our own 'defaultCostModelParams', since in the case of error 2 that would *also* change, so we instead need to have a checked-in version of the parameters. -} From 470ee028f39e0aef74fb351e3c33cdc3dc81f5c0 Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 21 Jul 2023 23:32:07 +0100 Subject: [PATCH 18/24] Fix dodgy Haddock --- plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs index 31b4606132f..b49908cf4bd 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs @@ -16,22 +16,22 @@ import Cardano.Crypto.Hash.SHA3_256 import Data.ByteString qualified as BS import Data.Proxy --- | Hash a [[BSL.ByteString]] using the SHA-256 hash function. +-- | Hash a ByteString using the SHA-256 hash function. sha2_256 :: BS.ByteString -> BS.ByteString sha2_256 = digest (Proxy @SHA256) --- | Hash a [[BSL.ByteString]] using the SHA3-256 hash function. +-- | Hash a ByteString using the SHA3-256 hash function. sha3_256 :: BS.ByteString -> BS.ByteString sha3_256 = digest (Proxy @SHA3_256) --- | Hash a [[BSL.ByteString]] using the Blake2B-224 hash function. +-- | Hash a ByteString using the Blake2b-224 hash function. blake2b_224 :: BS.ByteString -> BS.ByteString blake2b_224 = digest (Proxy @Blake2b_224) --- | Hash a [[BSL.ByteString]] using the Blake2B-256 hash function. +-- | Hash a ByteString using the Blake2b-256 hash function. blake2b_256 :: BS.ByteString -> BS.ByteString blake2b_256 = digest (Proxy @Blake2b_256) --- | Hash a [[BSL.ByteString]] using the Keccak-256 hash function. +-- | Hash a ByteString using the Keccak-256 hash function. keccak_256 :: BS.ByteString -> BS.ByteString keccak_256 = digest (Proxy @Keccak256) From c74fe1adac844bc41148c54b3815b1da231a869b Mon Sep 17 00:00:00 2001 From: kwxm Date: Fri, 21 Jul 2023 23:35:16 +0100 Subject: [PATCH 19/24] Fix dodgy Haddock --- plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs index b49908cf4bd..c956927be49 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Crypto/Hash.hs @@ -16,22 +16,22 @@ import Cardano.Crypto.Hash.SHA3_256 import Data.ByteString qualified as BS import Data.Proxy --- | Hash a ByteString using the SHA-256 hash function. +-- | Hash a `ByteString` using the SHA-256 hash function. sha2_256 :: BS.ByteString -> BS.ByteString sha2_256 = digest (Proxy @SHA256) --- | Hash a ByteString using the SHA3-256 hash function. +-- | Hash a `ByteString` using the SHA3-256 hash function. sha3_256 :: BS.ByteString -> BS.ByteString sha3_256 = digest (Proxy @SHA3_256) --- | Hash a ByteString using the Blake2b-224 hash function. +-- | Hash a `ByteString` using the Blake2b-224 hash function. blake2b_224 :: BS.ByteString -> BS.ByteString blake2b_224 = digest (Proxy @Blake2b_224) --- | Hash a ByteString using the Blake2b-256 hash function. +-- | Hash a `ByteString` using the Blake2b-256 hash function. blake2b_256 :: BS.ByteString -> BS.ByteString blake2b_256 = digest (Proxy @Blake2b_256) --- | Hash a ByteString using the Keccak-256 hash function. +-- | Hash a `ByteString` using the Keccak-256 hash function. keccak_256 :: BS.ByteString -> BS.ByteString keccak_256 = digest (Proxy @Keccak256) From 108aab83b6d89d7d5a44f40731880a0c0b77a76f Mon Sep 17 00:00:00 2001 From: kwxm Date: Sat, 22 Jul 2023 07:23:13 +0100 Subject: [PATCH 20/24] Add property test for hash sizes --- .../test/Evaluation/Builtins/Definition.hs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index 98a0d7d7a36..c38698e03f8 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -48,6 +48,7 @@ import Control.Exception import Data.ByteString (ByteString) import Data.DList qualified as DList import Data.Proxy +import Data.String (fromString) import Data.Text (Text) import Hedgehog hiding (Opaque, Size, Var) import Hedgehog.Gen qualified as Gen @@ -637,6 +638,33 @@ test_Crypto = testCase "Crypto" $ do evals @ByteString "G\ETB2\133\168\215\&4\RS^\151/\198w(c\132\248\STX\248\239B\165\236_\ETX\187\250%L\176\US\173" Keccak_256 [cons @ByteString "hello world"] +test_HashSize :: DefaultFun -> Integer -> TestTree +test_HashSize hashFun expectedNumBits = + let testName = "HashSize " ++ show hashFun ++ " is " ++ show expectedNumBits ++ " bits" + propName = fromString $ "HashSize " ++ show hashFun + in testPropertyNamed + testName + propName + . property $ do + bs <- forAll $ Gen.bytes (Range.linear 0 1000) + let term = mkIterAppNoAnn (builtin () MultiplyInteger) + [ cons @Integer 8 + , mkIterAppNoAnn (builtin () LengthOfByteString) [ + mkIterAppNoAnn (builtin () hashFun) [cons @ByteString bs] + ] + ] + typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term === Right (EvaluationSuccess (cons @Integer expectedNumBits)) + +test_HashSizes :: TestTree +test_HashSizes = + testGroup "Hash sizes" + [ test_HashSize Sha2_256 256 + , test_HashSize Sha3_256 256 + , test_HashSize Blake2b_256 256 + , test_HashSize Keccak_256 256 + , test_HashSize Blake2b_224 224 + ] + -- Test all remaining builtins of the default universe test_Other :: TestTree test_Other = testCase "Other" $ do @@ -699,8 +727,8 @@ test_SignatureVerification = testGroup "Ed25519 signatures (V1)" [ testPropertyNamed "Ed25519_V1 verification behaves correctly on all inputs" - "ed25519_V1_correct" . - property $ ed25519_V1Prop + "ed25519_V1_correct" + . property $ ed25519_V1Prop ], testGroup "Ed25519 signatures (V2)" [ testPropertyNamed @@ -747,6 +775,7 @@ test_definition = , test_List , test_Data , test_Crypto + , test_HashSizes , test_SignatureVerification , test_BLS12_381 , test_Other From 1893009a2a9be189c4ea1abb78f7dd35d9899caf Mon Sep 17 00:00:00 2001 From: kwxm Date: Sat, 22 Jul 2023 07:27:49 +0100 Subject: [PATCH 21/24] Haddock for hash size tests --- .../untyped-plutus-core/test/Evaluation/Builtins/Definition.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index c38698e03f8..0a4c0b2f9bf 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -638,6 +638,7 @@ test_Crypto = testCase "Crypto" $ do evals @ByteString "G\ETB2\133\168\215\&4\RS^\151/\198w(c\132\248\STX\248\239B\165\236_\ETX\187\250%L\176\US\173" Keccak_256 [cons @ByteString "hello world"] +-- | Test that hashes produced by a hash function contain the expected number of bits test_HashSize :: DefaultFun -> Integer -> TestTree test_HashSize hashFun expectedNumBits = let testName = "HashSize " ++ show hashFun ++ " is " ++ show expectedNumBits ++ " bits" @@ -655,6 +656,7 @@ test_HashSize hashFun expectedNumBits = ] typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term === Right (EvaluationSuccess (cons @Integer expectedNumBits)) +-- | Check that all hash functions return hashes with the correct number of bits test_HashSizes :: TestTree test_HashSizes = testGroup "Hash sizes" From 5e75810b03201d324deccfb3d795ceff3d4db100 Mon Sep 17 00:00:00 2001 From: kwxm Date: Sat, 22 Jul 2023 07:29:05 +0100 Subject: [PATCH 22/24] Formatting --- .../untyped-plutus-core/test/Evaluation/Builtins/Definition.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index 0a4c0b2f9bf..9adcea3db12 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -646,7 +646,7 @@ test_HashSize hashFun expectedNumBits = in testPropertyNamed testName propName - . property $ do + . property $ do bs <- forAll $ Gen.bytes (Range.linear 0 1000) let term = mkIterAppNoAnn (builtin () MultiplyInteger) [ cons @Integer 8 From 6b0dc96e95f1182fe7624aae0a9578aafad43a5e Mon Sep 17 00:00:00 2001 From: kwxm Date: Sat, 22 Jul 2023 07:30:06 +0100 Subject: [PATCH 23/24] Formatting --- .../test/Evaluation/Builtins/Definition.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index 9adcea3db12..fcffeebf749 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -650,9 +650,8 @@ test_HashSize hashFun expectedNumBits = bs <- forAll $ Gen.bytes (Range.linear 0 1000) let term = mkIterAppNoAnn (builtin () MultiplyInteger) [ cons @Integer 8 - , mkIterAppNoAnn (builtin () LengthOfByteString) [ - mkIterAppNoAnn (builtin () hashFun) [cons @ByteString bs] - ] + , mkIterAppNoAnn (builtin () LengthOfByteString) + [mkIterAppNoAnn (builtin () hashFun) [cons @ByteString bs]] ] typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term === Right (EvaluationSuccess (cons @Integer expectedNumBits)) From ae29519e418e42c0d8ac61614ba99a0390a7f157 Mon Sep 17 00:00:00 2001 From: kwxm Date: Wed, 26 Jul 2023 13:22:11 +0100 Subject: [PATCH 24/24] Fix some BLS-related comments (unrelated to this PR) --- .../src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs index ee2a549c5e3..48448167e39 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs @@ -273,7 +273,7 @@ g1ElementCost = singletonRose . unsafeToSatInt $ BLS12_381.G1.memSizeBytes `div` instance ExMemoryUsage BLS12_381.G1.Element where memoryUsage _ = g1ElementCost - -- Should be 12 + -- Should be 18 {-# NOINLINE g2ElementCost #-} g2ElementCost :: CostRose @@ -281,7 +281,7 @@ g2ElementCost = singletonRose . unsafeToSatInt $ BLS12_381.G2.memSizeBytes `div` instance ExMemoryUsage BLS12_381.G2.Element where memoryUsage _ = g2ElementCost - -- Should be 24 + -- Should be 36 {-# NOINLINE mlResultElementCost #-} mlResultElementCost :: CostRose @@ -289,4 +289,4 @@ mlResultElementCost = singletonRose . unsafeToSatInt $ BLS12_381.Pairing.mlResul instance ExMemoryUsage BLS12_381.Pairing.MlResult where memoryUsage _ = mlResultElementCost - -- Should be 144 + -- Should be 72