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 verified compilation certification component #6413

Merged
merged 59 commits into from
Sep 10, 2024

Conversation

ana-pantilie
Copy link
Contributor

@ana-pantilie ana-pantilie commented Aug 14, 2024

Fixes #5941

This PR implements the following:

  • adds the top-level VerifiedCompilation component to the Agda code
  • the UPLC compiler now generates a list of intermediate ASTs which are added to a state layer in the monad stack
  • integrates the Agda certification component into the uplc executable as a --certify <file-name> option to uplc optimise; it was necessary to pull it out into a separate package called plutus-executables because of cyclic dependencies

Notes:

  • I wasn't able to move library plutus-core-execlib to plutus-executables because plutus-benchmark and plutus-metatheory depend on the library
  • the uplc/plc/pir executables are no longer supported on Windows because they now depend on the metatheory; is this a problem?

TODO in future PRs:

  • tag ASTs with optimisation
  • proper proof serialisation
  • check whether the proofs can be reloaded into Agda properly
  • add CI tests

Try it out

To try this out, try:

cabal exec uplc -- example -s fibonacci | cabal exec uplc -- optimise --certify certificate-fibonacci

where certificate-fibonacci is the name of the .agda file that will be created with the proof object.

This is currently providing a negative result (the certificate is no), even though force-delay is clearly being applied! But now we have an example on which to start debugging. As pointed out by @ramsay-t , the result is correct because it's applying optimisations which currently haven't been specified in the certifier!


Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Changelog fragments have been written (if appropriate)
    • Relevant tickets are mentioned in commit messages
    • Formatting, PNG optimization, etc. are updated
  • PR
    • (For external contributions) Corresponding issue exists and is linked in the description
    • Targeting master unless this is a cherry-pick backport
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
Signed-off-by: Ana Pantilie <ana.pantilie95@gmail.com>
@ana-pantilie ana-pantilie marked this pull request as ready for review August 19, 2024 16:50
@ana-pantilie ana-pantilie requested review from a team and ramsay-t August 19, 2024 16:50
@ana-pantilie
Copy link
Contributor Author

ci/eval is failing but I have no idea why, if anyone does please let me know. Nevertheless, this should be ready for review now.

Copy link
Member

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

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

@bezirg has unified the pir, plc and uplc executables into the plutus executable, which I think is the one you'd want to integrate with.

Copy link
Contributor

@ramsay-t ramsay-t left a comment

Choose a reason for hiding this comment

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

The integration is great! The log/show information can be improved in the next iteration. The decision process is "working correctly" because it checks that all the changes are instances of implemented translation relations, and obviously the unimplemented ones aren't! We should make a log file with more granular information, and maybe adopt Jacco's approach of having a process for "accepting" unimplemented phases.

@@ -74,4 +87,11 @@ simplifyTerm opts builtinSemanticsVariant =
(Just Refl, Just Refl) -> cse builtinSemanticsVariant
_ -> pure

traceAST ast =
case eqT @fun @DefaultFun of
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall correctly, it's to convert to the Agda representation of terms, the Haskell -> Agda intermediate module uses that:

conv :: Term NamedDeBruijn DefaultUni DefaultFun a -> UTerm
.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. If it was for that function, you'd also need to check equality of uni and DefaultUni. What breaks if you remove the eqT check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I accidentally didn't use the fun type param in the SimplifierTrace type. Fixed now, thanks.

@ana-pantilie ana-pantilie enabled auto-merge (squash) September 4, 2024 18:25
@bezirg
Copy link
Contributor

bezirg commented Sep 9, 2024

the uplc/plc/pir executables are no longer supported on Windows because they now depend on the metatheory; is this a problem?

@ana-pantilie Not atm

@ana-pantilie ana-pantilie merged commit be47bd2 into master Sep 10, 2024
28 checks passed
@ana-pantilie ana-pantilie deleted the ana/add-certification-component branch September 10, 2024 17:27
kozross pushed a commit to mlabs-haskell/plutus that referenced this pull request Sep 10, 2024
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.

Build certifier infrastructure and integrate with compiler
7 participants