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

Aiken: commit validator #1072

Closed
wants to merge 37 commits into from
Closed

Aiken: commit validator #1072

wants to merge 37 commits into from

Conversation

ch1bo
Copy link
Collaborator

@ch1bo ch1bo commented Sep 13, 2023

Created with @KtorZ on the Hydra/Mithril workshop in Nantes.

😈 Write the vCommit validator in Aiken and produce a plutus.json blueprint

😈 Add Hydra.Plutus module which loads validators from a plutus.json blueprint.

😈 Use the aiken created vCommit validator in hydra-node

😈 Profit! Abort/Collect transactions do fit double the participants; but, due to execution memory limits, the maximum amount of parties got increased to 7.

TODO:

  • Use plutus.json for CI golden tests.
  • Make sure the hydra-plutus lib is recompiled whenever plutus.json changes.
    • This worked once today, but then not again

image

  • Remove the plutus-tx commit validator.
  • Re-do the audit (or prove equivalence of this aiken script to the plutus-tx script)

  • CHANGELOG updated or not needed
  • Documentation updated or not needed
  • Haddocks updated or not needed
  • No new TODOs introduced or explained herafter

@github-actions
Copy link

github-actions bot commented Sep 13, 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-10-10 15:30:45.652792422 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 1757377bfe447290ea71fceda407270bc4a8e830fa0cf9d01f19facc 4106
νCommit 0cf18a11d1d2a230fcd22611a399deb8b22df9910970db79e059680a 1105
νHead e35bdf32cd3806596150c1cbab6ab5456bd957b36019ed2746bf481d 8797
μHead c2f21da19120d65ac2e339d218ec59755e80091b4ece2b4720f8da8b* 4151
  • 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 4742 11.57 4.56 0.49
2 4953 14.27 5.60 0.52
3 5155 16.82 6.57 0.56
5 5562 21.25 8.25 0.63
10 6589 33.02 12.73 0.80
37 12124 96.82 37.03 1.73

Cost of Commit Transaction

This is using ada-only outputs for better comparability.

UTxO Tx size % max Mem % max CPU Min fee ₳
1 599 12.64 4.97 0.31
2 787 16.26 6.61 0.36
3 972 20.20 8.37 0.42
5 1348 28.32 11.97 0.52
10 2286 50.99 21.84 0.82
18 3778 94.76 40.36 1.37

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 814 20.28 8.00 0.41
2 114 1134 30.12 11.83 0.53
3 171 1457 39.61 15.59 0.65
4 227 1775 46.36 18.26 0.73
5 283 2095 57.61 22.64 0.87
6 340 2422 67.35 26.57 0.99
7 396 2736 72.83 28.82 1.07
8 448 3060 81.49 32.21 1.18
9 505 3375 93.52 36.90 1.32

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 681 19.15 8.80 0.40
2 932 21.05 10.46 0.44
3 1113 22.86 12.05 0.47
5 1531 25.64 14.84 0.53
10 2500 33.50 22.10 0.69
49 10546 96.45 79.79 1.97

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 723 22.63 10.11 0.44
2 955 24.68 11.82 0.48
3 1137 27.07 13.62 0.52
5 1574 30.46 16.60 0.59
10 2557 39.35 24.32 0.76
42 9077 98.67 74.58 1.88

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 5008 17.74 7.68 0.57
2 5415 25.90 11.36 0.68
3 5946 33.95 15.07 0.79
4 6029 38.59 16.93 0.85
5 6812 50.18 22.42 1.02
6 6956 56.29 24.92 1.09
7 7131 60.56 26.63 1.15
8 7924 72.66 32.33 1.32
9 8289 83.31 37.03 1.45
10 8770 92.68 41.31 1.58
11 8986 96.73 42.91 1.64

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 ₳
10 0 0 5088 11.00 4.62 0.50
10 1 57 5128 12.13 5.35 0.51
10 5 285 5273 17.75 8.70 0.59
10 10 570 5452 24.15 12.63 0.68
10 20 1140 5813 37.41 20.68 0.86
10 30 1709 6174 49.79 28.38 1.03
10 40 2272 6527 63.42 36.59 1.21
10 50 2846 6894 76.59 44.62 1.39
10 68 3871 7537 99.50 58.74 1.71

End-To-End Benchmark Results

This page is intended to collect the latest end-to-end benchmarks results produced by Hydra's Continuous Integration system from the latest master code.

Please take those results with a grain of salt as they are currently produced from very limited cloud VMs and not controlled hardware. Instead of focusing on the absolute results, the emphasis should be on relative results, eg. how the timings for a scenario evolve as the code changes.

Generated at 2023-10-10 15:25:54.91674161 UTC

3-nodes Scenario

A rather typical setup, with 3 nodes forming a Hydra head.

Number of nodes 3
Number of txs 900
Avg. Confirmation Time (ms) 79.021974263
P99 229.40515286ms
P95 165.93765474999995ms
P50 64.6926675ms
Number of Invalid txs 0

Baseline Scenario

This scenario represents a minimal case and as such is a good baseline against which to assess the overhead introduced by more complex setups. There is a single hydra-node d with a single client submitting single input and single output transactions with a constant UTxO set of 1.

Number of nodes 1
Number of txs 300
Avg. Confirmation Time (ms) 7.585490546
P99 17.199078279999984ms
P95 13.654988400000006ms
P50 6.534554ms
Number of Invalid txs 0

hydra-plutus/aiken.toml Outdated Show resolved Hide resolved
@v0d1ch
Copy link
Contributor

v0d1ch commented Oct 4, 2023

Make sure the hydra-plutus lib is recompiled whenever plutus.json changes.

Note: Locally I always see recompilation when I change plutus.json file

@v0d1ch
Copy link
Contributor

v0d1ch commented Oct 4, 2023

This is related to work on this branch https://github.com/cardano-foundation/CIPs/tree/master/CIP-0057
I am not sure if we want to keep (duplicated) commit datum and redeemer on the Haskell side until this CIP is implemented by the Plutus team. Problem we are having is that currently there is no way to go from plutus.json blueprint of commit datum/redeemer to equivalent in haskell where we need this to be able to build a commit tx.

@ffakenz ffakenz marked this pull request as ready for review October 5, 2023 12:32
@abailly-iohk
Copy link
Contributor

Regarding this task:
Screenshot 2023-10-05 at 16 37 37

This is not something we can do ourselves quickly, I will check with auditors how long it might take and report here but this might block integration of this PR.

@abailly-iohk
Copy link
Contributor

Not sure why the CI is red. I wonder if you should merge that PR straight away given the security implications: I have reached out to bcryptic for more information on how they could review aiken SCs. The commit script is simple enough but this will be an issue for the Initial or Head scripts which are much more involved.

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Test Results

356 tests   351 ✔️  18m 25s ⏱️
120 suites      5 💤
    6 files        0
    1 errors

For more details on these parsing errors, see this check.

Results for commit 60817a9.

♻️ This comment has been updated with latest results.

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.

The main thing is we have an entry in the changelog that doesn't belong in this PR. Other than that 👌

CHANGELOG.md Outdated Show resolved Hide resolved
flake.nix Show resolved Hide resolved
hydra-node/src/Hydra/Chain.hs Show resolved Hide resolved
hydra-plutus/test/Hydra/Plutus/GoldenSpec.hs Outdated Show resolved Hide resolved
@ffakenz ffakenz requested a review from v0d1ch October 7, 2023 09:39
@ffakenz ffakenz force-pushed the workshop/aiken-scripts branch 2 times, most recently from 4dc7797 to b4bb881 Compare October 7, 2023 10:33
@abailly-iohk
Copy link
Contributor

As the aiken scripts are not audited, and while they are awaiting audit, one option would be to add a feature flag to the hydra-node that would allow a user to decide, while we are still developing them, to use them or not. eg. something like hydra-node run --use-aiken ... that would select the Aiken scripts (when they are available) to post transactions.
This is more work as we need to maintain the old Commit script, but it allows us to merge this PR and keep developing Aiken scripts without having to bother about diverging changes.

We intend to create one of the hydra-plutus scripts with aiken.
This separates the aiken build, which yields the plutus.json blueprint
and the haskell build which provides access to the compiled validators.
ffakenz and others added 23 commits October 10, 2023 17:15
- In order to compile and rebase against master we need this type
since currently there is no way to go from the openApi style of json
encoding for plutus redeemer to actual Plutus `Data` type.
CIP-57 is related to this conversion but this is ongoing work still.
By regenerating the plutus.json file using -k flag during aiken build.
This removes the need of using aiken/builtin function decode_utf8,
providing some small optimization.

Also recreated plutus scripts.
Also removed its golden spec.

Finally added a note about a fragility being present while accessing
the commit validator script from the blueprintJSON.
Because soon then Plutus team will provide such parsers.
We don't need this piece of code now that we fixed the aiken nix build input in
the plutus tests.

Also removed wrong entry in CHANGELOG.
@abailly-iohk
Copy link
Contributor

We close the PR for now because we think the experiment is done and provided good results, but there's not pressing need to migrate everything to aiken

@ffakenz ffakenz deleted the workshop/aiken-scripts branch December 13, 2023 13:55
waitForProcess gitStatusProcessHandle
-- Read git log file and verify plutus.json did not change
gitLogContents <- decodeUtf8 <$> readFileBS gitLogFilePath
gitLogContents `shouldNotContain` "plutus.json"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should: not run git (assumes a working copy), but rather run aiken build and assert freshly generated plutus.json contents vs the embedded one from Hydra.Plutus

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should: not need this file anymore

, plutus-core >=1.7 && <1.10
, plutus-ledger-api >=1.7 && <1.10
, plutus-tx >=1.7 && <1.10
, plutus-tx-plugin >=1.7 && <1.10
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to update these

"narHash": "sha256-cOhHYQUt7TgtNkN+Am5eGWlPbKVL8Vsn7FDf1b1Psfo=",
"owner": "aiken-lang",
"repo": "aiken",
"rev": "78ff6cf178f9e7707d1a5297e4a774c9ab81d73e",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should: use the latest aiken version

@@ -48,7 +48,7 @@ maxMainnetLovelace = 100_000_000
-- The value is obtained from calculating the costs of running the scripts
-- and on-chan validators (see 'computeCollectComCost' 'computeAbortCost')
maximumNumberOfParties :: Int
maximumNumberOfParties = 4
maximumNumberOfParties = 7
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should revisit this

@ch1bo ch1bo mentioned this pull request Oct 4, 2024
4 tasks
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.

5 participants