-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike: costs of hashing #155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised by the fact plutus compiler does not balk at the lack of INLINABLE
pragmas for the Hash
validator. There's something I still don't understand here.
@@ -100,6 +118,54 @@ spec = describe "On-chain contracts" $ do | |||
prop "does not survive random adversarial mutations" $ | |||
propMutation healthyCloseTx genCloseMutation | |||
|
|||
describe "Hash" $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have moved this to a dedicated HashSpec
module.
The approach looks fine, but the results look odd for SHA3 with a negative delta on the first cases? Could it be because of the Note that, for the encoding spike, I ended up writing validator as |
o.O |
The inspect-script binary reports a serialized size of 5KB for this script validator!
Ideally we would have a standalone executable for things like this, but the 'evaluateTx' and included 'Fixture's are not available outside of hydra-node tests.
e315dcd
to
917127f
Compare
The results are not so useful and have been historically recorded in our reports and in #155
The results are not so useful and have been historically recorded in our reports and in #155
❄️ Indeed the formula
s * slope + intercept
wheres = number of Word64
is used to calculate builtin hash function costs in the cost modelModelOneArgument
https://github.com/input-output-hk/plutus/blob/1efbb276ef1a10ca6961d0fd32e6141e9798bd11/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs#L111-L113runOneArgumentModel
function shows a linear multiplication ofs * slope + intercept
with a singleExMemory
argumenthttps://github.com/input-output-hk/plutus/blob/1efbb276ef1a10ca6961d0fd32e6141e9798bd11/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/BuiltinCostModel.hs#L208-L223
makeBuiltinMeaning
does determine theExMemory
cost of the provided function's argument. For hashing it's always aBuiltinBytestring
and thus the length of theBytestring
in 8-byte / 64bit words iss
. https://github.com/input-output-hk/plutus/blob/1efbb276ef1a10ca6961d0fd32e6141e9798bd11/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemory.hs#L149-L150❄️ Given the cost model parameters in
mainnet-alonzo-genesis.json
we expect
ModelOneArgumentConstantCost == 4
org-mode
table)❄️ Add a
Hash
contract to hash a given datum using supported hashing algorithms❄️ Add test to
ContractSpec
which calculates units for multiple bytes lengths and all algorithms❄️ The observed execution unit (deltas) output of
cabal test hydra-node --test-options '--match "Contract/Hash"'
show that memory usage is constant and somewhat confirms the expected cpu usage values with an additional offset between
[-20k..-200k]
and[-870k..-1M]
units for SHA2 and SHA3 respectively. It seems like the baseline is not good enough or maybe there had been some tweaks on the cost model?