Skip to content
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

Add golden plutus scripts #772

Merged
merged 7 commits into from
Mar 15, 2023
Merged

Add golden plutus scripts #772

merged 7 commits into from
Mar 15, 2023

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Mar 14, 2023

🥇 Adds our scripts in a binary form as golden files. This is also useful in case we can't reproduce them exactly as they were originally compiled using plutus-tx; which is not unlikely given we need to have the exact same version of plutus-tx, all its dependencies, and GHC.

🥇 Adds golden test suite to ensure we do not accidentally change scripts and also helps in writing the plutus scripts of the Hydra protocol as blobs into the repository.

First execution:

    Hydra.Plutus.Golden
      μHead script has not changed
        First time execution. Golden file created.
      νHead script has not changed
        First time execution. Golden file created.
      νInitial script has not changed
        First time execution. Golden file created.
      νCommit script has not changed
        First time execution. Golden file created.

When flipping a $ in the code:

    test/Hydra/Plutus/GoldenSpec.hs:37:3:
    
    1.  Hydra.Plutus.Golden μHead script has not changed
        expected: "6683772ef9e41b05e3ae8255644fcc56ea839bb1daeb8ca872bb4886"
         but got: "2e1755eb17febb4f71bdcd2ca1c81ae5f80fa98bb03a987f8f09597e"
    

Some more notes in the logbook.


  • CHANGELOG updated
  • Documentation update not needed
  • Added and/or updated haddocks
  • No new TODOs introduced or explained herafter

This ensures we do not accidentally change scripts and also persist the
binary scripts (in case we cannot reproduce them).
@ch1bo ch1bo requested review from v0d1ch, a user, pgrange and ffakenz March 14, 2023 20:45
@github-actions
Copy link

github-actions bot commented Mar 15, 2023

Test Results

297 tests  ±0   291 ✔️ ±0   26m 2s ⏱️ + 5m 33s
  99 suites ±0       6 💤 ±0 
    5 files   ±0       0 ±0 

Results for commit 5cd264c. ± Comparison against base commit 497ccb1.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Mar 15, 2023

Transactions Costs

Sizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using arbitrary values and results are not fully deterministic and comparable to previous runs.

Metadata
Generated at 2023-03-15 11:47:02.489823207 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 9492414f8f96e8483a0b8ee268fc06a954641cb2cbaa9a8b093c2c9b 4621
νCommit 5d3f107aaa56d06188cf231941cf8163e777236a9cfdc48fd4bbfa23 2422
νHead 82f16b51e2d81c6f4d42dd7398b4713a445464902f63dfd86ffe754e 8954
μHead 4083fa7081a0f4b4092fb02867c9ac594bb0e8bab8110ab242ba5a72* 4458
  • The minting policy hash is only usable for comparison. As the script is parameterized, the actual script is unique per Head.

Cost of Init Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 5056 12.99 5.11 0.51
2 5259 16.27 6.38 0.56
3 5468 18.59 7.25 0.59
5 5875 25.10 9.77 0.68
10 6897 35.14 13.50 0.83
36 12229 98.32 37.41 1.75

Cost of Commit Transaction

Currently only one UTxO per commit allowed (this is about to change soon)

UTxO Tx size % max Mem % max CPU Min fee ₳
1 603 15.83 6.22 0.35

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 824 24.67 10.02 0.46
2 114 1147 40.66 16.63 0.65
3 170 1461 58.82 24.21 0.86
4 227 1782 80.09 33.11 1.11

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 580 15.26 6.49 0.35
2 804 18.73 8.21 0.40
3 969 20.08 8.96 0.42
5 1307 22.65 10.42 0.47
10 2116 29.66 14.28 0.59
50 8725 85.71 45.19 1.55

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 677 22.16 9.28 0.43
2 840 23.45 9.99 0.45
3 1005 25.59 11.04 0.48
5 1336 28.68 12.68 0.53
10 2162 37.20 17.07 0.67
46 8103 99.83 49.23 1.67

Cost of Abort Transaction

Some variation because of random mixture of still initial and already committed outputs.

Parties Tx size % max Mem % max CPU Min fee ₳
1 5174 29.49 12.60 0.71
2 5492 48.08 20.77 0.93
3 5815 70.09 30.47 1.19
4 6138 95.39 41.63 1.49

Cost of FanOut Transaction

Involves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.

Parties UTxO UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
5 0 0 5074 10.59 4.43 0.49
5 1 57 5113 12.12 5.31 0.51
5 5 285 5254 18.22 8.83 0.59
5 10 570 5434 25.85 13.24 0.69
5 20 1138 5791 41.11 22.05 0.90
5 30 1708 6157 56.37 30.86 1.10
5 40 2279 6519 71.64 39.68 1.30
5 50 2843 6873 86.92 48.50 1.50
5 58 3298 7159 99.14 55.56 1.67

@ch1bo ch1bo force-pushed the ch1bo/golden-plutus-scripts branch from ffb1380 to fb7aaa4 Compare March 15, 2023 08:07
ch1bo added 5 commits March 15, 2023 09:07
We do not gain anything from the files, when the hashes don't match and
we want to acknowledge, we would just drop the golden file and have it
regenerated by the test.
The text envelope of persisted, golden scripts is a good location to
give a full description of what script is actually included. For this,
let's also incorporate the git describe output, as it gives a very good
indication. Ideally, we change them to the actual tag, but even if not
it's a good starting point.
@ch1bo ch1bo force-pushed the ch1bo/golden-plutus-scripts branch from fb7aaa4 to 7a8817c Compare March 15, 2023 08:07
Copy link
Contributor

@pgrange pgrange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review tries to apply the perfection game protocol

I will describe what I like about this P.R. and then what improvement I can think of to make it perfect.
 Ask for clarifications if my comments are not clear.

If you disagree with my comments, just ignore them and don’t answer or explain.
 Hence I, in advance, approve the P.R.

What I like about this P.R.:

  • I just love it. It is a tremendous improvement to our code base

For me to find it perfect you would have to:

  • see other improvement proposals inline

Comment on lines 165 to 172
-- | Get the applied head minting policy script given a seed 'TxOutRef'.
mintingPolicyScript :: TxOutRef -> Script
mintingPolicyScript txOutRef =
getMintingPolicy . mkMintingPolicyScript $
$$(PlutusTx.compile [||\vInitial vHead ref -> wrapMintingPolicy (validate vInitial vHead ref)||])
`PlutusTx.applyCode` PlutusTx.liftCode Initial.validatorHash
`PlutusTx.applyCode` PlutusTx.liftCode Head.validatorHash
`PlutusTx.applyCode` PlutusTx.liftCode txOutRef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the new unappliedMintingPolicy function here. Something in the line of (doesn't compile nor work):

Suggested change
-- | Get the applied head minting policy script given a seed 'TxOutRef'.
mintingPolicyScript :: TxOutRef -> Script
mintingPolicyScript txOutRef =
getMintingPolicy . mkMintingPolicyScript $
$$(PlutusTx.compile [||\vInitial vHead ref -> wrapMintingPolicy (validate vInitial vHead ref)||])
`PlutusTx.applyCode` PlutusTx.liftCode Initial.validatorHash
`PlutusTx.applyCode` PlutusTx.liftCode Head.validatorHash
`PlutusTx.applyCode` PlutusTx.liftCode txOutRef
-- | Get the applied head minting policy script given a seed 'TxOutRef'.
mintingPolicyScript :: TxOutRef -> Script
mintingPolicyScript txOutRef =
getMintingPolicy . mkMintingPolicyScript $
unappliedMintingPolicy
`PlutusTx.applyCode` PlutusTx.liftCode txOutRef

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I only made the unappliedMintingPolicy work later and forgot to inline it :)

@v0d1ch v0d1ch self-assigned this Mar 15, 2023
Copy link
Contributor

@v0d1ch v0d1ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BAM!

@v0d1ch v0d1ch merged commit 439ee45 into master Mar 15, 2023
@v0d1ch v0d1ch deleted the ch1bo/golden-plutus-scripts branch March 15, 2023 15:42
@ch1bo ch1bo added this to the 0.10.0 milestone Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants