Skip to content

Commit

Permalink
Optimization refactoring: VarsInfo and BuiltinsInfo, pure conapps (#5551
Browse files Browse the repository at this point in the history
)

* Add VarInfo pass, use it everywhere

* Add BuiltinsInfo type, use it everywhere

* Strictify bindings uses VarsInfo

* LetFloatOut uses VarsInfo

* ThunkRecursions uses VarsInfo

* LetFloatIn uses VarsInfo

* Conapps are pure

* Changelog

* Update 9.6 test output

* Fix pir

* More fixups??

* Comments
  • Loading branch information
michaelpj authored and zliu41 committed Sep 23, 2023
1 parent fb2c3e9 commit 68827c1
Show file tree
Hide file tree
Showing 400 changed files with 6,347 additions and 5,760 deletions.
1 change: 1 addition & 0 deletions doc/read-the-docs-site/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ for writing Haskell code that can be compiled to Plutus Core.

explanations/index
simple-example
quick-start
extensions-flags-pragmas
tutorials/index
howtos/index
Expand Down
62 changes: 62 additions & 0 deletions doc/read-the-docs-site/quick-start.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. _quick_start:

Quick Start
=================================

This guide gets you started on setting up the dev environment for a simple Cardano smart contract, with the on-chain validator written in Plutus Tx.
There are several other options for writing on-chain validators, such as `Aiken <https://aiken-lang.org/>`_ and `OpShin <https://github.com/OpShin/opshin>`_, and you can refer to their respective documentation for how to use them.

If you have any questions regarding this guide, open an issue `here <https://github.com/input-output-hk/plutus/issues>`_.

Writing the On-Chain Validator
-------------------------------------------------

Prerequisites
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GHC and Cabal should be installed in order to follow this guide.
Plutus Tx currently supports GHC v9.2.x and v9.6.x.
Cabal v3.8+ is recommended.

Create a New Cabal Package
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First, make a new directory ``plutus-quickstart``: ::

mkdir plutus-quickstart && cd $_

Then, create a new Cabal package that builds a library, using default settings: ::

cabal init --lib --non-interactive

Declare Plutus Tx Dependencies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, declare the following packages as dependencies: ``plutus-core``, ``plutus-ledger-api``, ``plutus-tx``, and ``plutus-tx-plugin``.
These packages aren't on Hackage (the default repository Cabal looks for packages from), but on the `CHaP <https://github.com/input-output-hk/cardano-haskell-packages>`_ repository.
We need to tell Cabal to look for packages also from CHaP.
To do so, make a ``cabal.project`` file, and follow the instructions in the CHaP repository to make Cabal aware of CHaP.
Then, add the following to your ``cabal.project``: ::

packages:
./plutus-quickstart.cabal

Finally, add the aformentioned packages in the ``build-depends`` field in ``plutus-quickstart.cabal``: ::

build-depends:
, base
, plutus-core
, plutus-ledger-api
, plutus-tx
, plutus-tx-plugin

Before we can build it, some C libraries need to be installed.
Plutus Tx depends on `cardano-base <https://github.com/input-output-hk/cardano-base>`_, which in turn depends on a few cryptographic C libraries, including ``libblst``, ``libsecp256k1``, and ``libsodium``.
Cabal is not designed to manage C dependencies, so you need to either install them yourself, or manage them using another tool (such as Nix).

If you are not using Nix, follow the instructions in the cardano-base repository to install these libraries.
If you are, you can use plutus repository's dev shell: ::

nix develop github:input-output-hk/plutus

At this point, you should be able to build your project: ``cabal build plutus-quickstart`` should succeed.
26 changes: 16 additions & 10 deletions doc/read-the-docs-site/tutorials/AuctionValidator.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
{-# OPTIONS_GHC -fno-full-laziness #-}
{-# OPTIONS_GHC -fno-spec-constr #-}
{-# OPTIONS_GHC -fno-specialise #-}
{-# OPTIONS_GHC -fno-strictness #-}
{-# OPTIONS_GHC -fno-unbox-strict-fields #-}
{-# OPTIONS_GHC -fno-unbox-small-strict-fields #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-}

module AuctionValidator where

import PlutusCore.Default qualified as PLC
import PlutusCore.Version (plcVersion100)
import PlutusLedgerApi.V1 (POSIXTime, PubKeyHash, Value, adaSymbol, adaToken, singleton)
import PlutusLedgerApi.V1.Address (pubKeyHashAddress)
Expand All @@ -15,13 +26,8 @@ import PlutusLedgerApi.V2 (Datum (..), OutputDatum (..), ScriptContext (..), TxI
TxOut (..), from, to)
import PlutusLedgerApi.V2.Contexts (getContinuingOutputs)
import PlutusTx
import PlutusTx.Bool
import PlutusTx.Builtins
import PlutusTx.Lift
import PlutusTx.Maybe
import PlutusTx.Prelude qualified as PlutusTx
import PlutusTx.Show qualified as PlutusTx
import Prelude qualified as Haskell

-- BLOCK1
data AuctionParams = AuctionParams
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 272607771
| mem: 966608})
({cpu: 272400771
| mem: 965708})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 401023590
| mem: 1482914})
({cpu: 400816590
| mem: 1482014})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 293263997
| mem: 1051008})
({cpu: 293194997
| mem: 1050708})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 236684811
| mem: 830776})
({cpu: 236615811
| mem: 830476})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 266018940
| mem: 936350})
({cpu: 265811940
| mem: 935450})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 245382894
| mem: 859986})
({cpu: 245175894
| mem: 859086})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 243567317
| mem: 853384})
({cpu: 243360317
| mem: 852484})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 308484242
| mem: 1102062})
({cpu: 308346242
| mem: 1101462})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 286048512
| mem: 1020658})
({cpu: 285841512
| mem: 1019758})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 262299371
| mem: 928392})
({cpu: 262161371
| mem: 927792})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 293213547
| mem: 1044112})
({cpu: 293006547
| mem: 1043212})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 296115875
| mem: 1062456})
({cpu: 295977875
| mem: 1061856})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 354127925
| mem: 1286116})
({cpu: 353920925
| mem: 1285216})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 242020016
| mem: 850330})
({cpu: 241882016
| mem: 849730})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 261995754
| mem: 923394})
({cpu: 261857754
| mem: 922794})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 231011581
| mem: 798384})
({cpu: 230804581
| mem: 797484})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 295317489
| mem: 1066496})
({cpu: 295248489
| mem: 1066196})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 256347721
| mem: 907036})
({cpu: 256278721
| mem: 906736})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 302312189
| mem: 1091068})
({cpu: 302243189
| mem: 1090768})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 248348289
| mem: 878024})
({cpu: 248279289
| mem: 877724})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 277575578
| mem: 985806})
({cpu: 277437578
| mem: 985206})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 272607771
| mem: 966608})
({cpu: 272400771
| mem: 965708})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 289835982
| mem: 1037158})
({cpu: 289628982
| mem: 1036258})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 244633793
| mem: 852892})
({cpu: 244426793
| mem: 851992})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 240047813
| mem: 840432})
({cpu: 239909813
| mem: 839832})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 245994383
| mem: 861388})
({cpu: 245787383
| mem: 860488})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 240204315
| mem: 843728})
({cpu: 240066315
| mem: 843128})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 270516505
| mem: 954056})
({cpu: 270309505
| mem: 953156})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 257609171
| mem: 906240})
({cpu: 257402171
| mem: 905340})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 274730914
| mem: 978998})
({cpu: 274592914
| mem: 978398})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 244633793
| mem: 852892})
({cpu: 244426793
| mem: 851992})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 236229824
| mem: 832670})
({cpu: 236160824
| mem: 832370})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 262044449
| mem: 925292})
({cpu: 261906449
| mem: 924692})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 242019892
| mem: 850330})
({cpu: 241881892
| mem: 849730})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 242019892
| mem: 850330})
({cpu: 241881892
| mem: 849730})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 298609670
| mem: 1070426})
({cpu: 298402670
| mem: 1069526})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 252607972
| mem: 891042})
({cpu: 252469972
| mem: 890442})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 298229103
| mem: 1077220})
({cpu: 298160103
| mem: 1076920})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 272607771
| mem: 966608})
({cpu: 272400771
| mem: 965708})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 303339197
| mem: 1079068})
({cpu: 303132197
| mem: 1078168})
Loading

0 comments on commit 68827c1

Please sign in to comment.