Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 2817a37

Browse files
iohk-bors[bot]erikd
andcommitted
Merge #3952
3952: Disable existing Plutus prototype r=erikd a=erikd ## Description The code base included support for the Plutus prototype, but these were officially only for testing on a test net and that if transactions showed up on mainnet containing smart contract, there would be no guarantees about them. Testing shows that there are no smart contracts in the mainnet chain. ## Linked issue https://iohk.myjetbrains.com/youtrack/issue/CBR-493 ## QA Steps Synced the whole mainnet blockchain with this version of the code. Co-authored-by: Erik de Castro Lopo <[email protected]>
2 parents e75a758 + e4f64cc commit 2817a37

File tree

18 files changed

+22
-897
lines changed

18 files changed

+22
-897
lines changed

cabal.project.freeze

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ constraints: Cabal ==2.2.0.1,
117117
pipes-bytestring ==2.1.6,
118118
pipes-interleave ==1.1.3,
119119
pipes-safe ==2.2.9,
120-
plutus-prototype ==0.1.0.0,
121120
pretty-show ==1.7,
122121
purescript-bridge ==0.13.0.0,
123122
pvss ==0.2.0,

chain/cardano-sl-chain.cabal

-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ library
2222
Pos.Chain.Security
2323
Pos.Chain.Ssc
2424
Pos.Chain.Script
25-
Pos.Chain.Script.Examples
2625
Pos.Chain.Txp
2726
Pos.Chain.Update
2827

2928
other-modules:
30-
3129
Pos.Chain.Block.Block
3230
Pos.Chain.Block.ComponentBlock
3331
Pos.Chain.Block.Configuration
@@ -190,7 +188,6 @@ library
190188
, mtl
191189
, neat-interpolation
192190
, parsec
193-
, plutus-prototype
194191
, QuickCheck
195192
, reflection
196193
, safecopy

chain/src/Pos/Chain/Script.hs

+1-126
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,14 @@
66
module Pos.Chain.Script
77
( Script(..)
88
, PlutusError(..)
9-
10-
, txScriptCheck
11-
12-
, parseValidator
13-
, parseRedeemer
14-
15-
, stdlib
16-
17-
, isKnownScriptVersion
189
) where
1910

20-
import Universum hiding (lift)
11+
import Universum
2112

22-
import Control.Exception (ArithException (..), ArrayException (..),
23-
ErrorCall (..), PatternMatchFail (..))
24-
import Control.Exception.Safe (Handler (..), SomeException (..),
25-
catches, displayException)
26-
import Control.Lens (_Left)
27-
import Control.Monad.Error.Class (throwError)
28-
import qualified Data.ByteArray as BA
29-
import qualified Data.ByteString.Lazy as BSL
30-
import qualified Data.Set as S
31-
import qualified Elaboration.Contexts as PL
3213
import qualified Formatting.Buildable as Buildable
33-
import qualified Interface.Integration as PL
34-
import qualified Interface.Prelude as PL
35-
import Language.Haskell.TH.Syntax (Lift (..), runIO)
36-
import qualified PlutusCore.EvaluatorTypes as PLCore
37-
import qualified PlutusCore.Program as PL
38-
import System.IO.Unsafe (unsafePerformIO)
39-
import qualified Utils.Names as PL
4014

41-
import qualified Pos.Binary.Class as Bi
42-
import Pos.Chain.Txp.TxWitness (TxSigData (..))
43-
import Pos.Core.Binary ()
4415
import Pos.Core.Common (Script (..), ScriptVersion)
45-
import Pos.Core.Script ()
46-
47-
{- NOTE
48-
49-
Scripts are versioned. The current version is 0. All functions below work
50-
with version 0 scripts.
51-
52-
Here's what would lead to script version increment:
53-
* changing serialization in any way
54-
* adding anything to the stdlib
55-
-}
5616

57-
isKnownScriptVersion :: ScriptVersion -> Bool
58-
isKnownScriptVersion v = v == 0
59-
60-
-- | Post-process loaded program to remove stdlib references that were added
61-
-- to the environment by 'loadValidator' or 'loadRedeemer'.
62-
stripStdlib :: PL.Program -> PL.Program
63-
stripStdlib (PL.Program xs) = PL.Program (filter (not . std) xs)
64-
where
65-
stds = S.fromList (map (PL.unsourced . fst) (PL.definitions stdlib))
66-
std (name, _) = PL.unsourced name `elem` stds
67-
68-
-- | Parse a script intended to serve as a validator (or “lock”) in a
69-
-- transaction output.
70-
parseValidator :: Text -> Either String Script
71-
parseValidator t = do
72-
scr <- stripStdlib <$> PL.loadValidator stdlib (toString t)
73-
return Script {
74-
scrScript = Bi.serialize' scr,
75-
scrVersion = 0 }
76-
77-
-- | Parse a script intended to serve as a redeemer (or “proof”) in a
78-
-- transaction input.
79-
parseRedeemer :: Text -> Either String Script
80-
parseRedeemer t = do
81-
scr <- stripStdlib <$> PL.loadRedeemer stdlib (toString t)
82-
return Script {
83-
scrScript = Bi.serialize' scr,
84-
scrVersion = 0 }
8517

8618
-- | The type for errors that can appear when validating a script-protected
8719
-- transaction.
@@ -112,60 +44,3 @@ instance Buildable PlutusError where
11244
build PlutusReturnedFalse =
11345
"script execution resulted in 'failure'"
11446

115-
-- | Validate a transaction, given a validator and a redeemer.
116-
txScriptCheck
117-
:: TxSigData
118-
-> Script -- ^ Validator
119-
-> Script -- ^ Redeemer
120-
-> Either PlutusError ()
121-
txScriptCheck sigData validator redeemer = case spoon result of
122-
Left err -> throwError (PlutusException (toText err))
123-
Right (Left err) -> throwError err
124-
Right (Right False) -> throwError PlutusReturnedFalse
125-
Right (Right True) -> pass
126-
where
127-
result :: Either PlutusError Bool
128-
result = do
129-
-- TODO: when we support more than one version, complain if versions
130-
-- don't match
131-
valScr <- case scrVersion validator of
132-
0 -> over _Left PlutusDecodingFailure $
133-
Bi.decodeFull' (scrScript validator)
134-
v -> Left (PlutusUnknownVersion v)
135-
redScr <- case scrVersion redeemer of
136-
0 -> over _Left PlutusDecodingFailure $
137-
Bi.decodeFull' (scrScript redeemer)
138-
v -> Left (PlutusUnknownVersion v)
139-
(script, env) <- over _Left (PlutusExecutionFailure . toText) $
140-
PL.buildValidationScript stdlib valScr redScr
141-
let txInfo = PLCore.TransactionInfo
142-
{ txHash = BSL.fromStrict . BA.convert $
143-
txSigTxHash sigData }
144-
over _Left (PlutusExecutionFailure . toText) $
145-
PL.checkValidationResult txInfo (script, env)
146-
147-
stdlib :: PL.DeclContext
148-
stdlib = case PL.loadLibrary PL.emptyDeclContext prelude of
149-
Right x -> x
150-
Left err -> error $ toText
151-
("stdlib: error while parsing Plutus prelude: " ++ err)
152-
where
153-
prelude = $(lift . toString =<< runIO PL.preludeString)
154-
155-
----------------------------------------------------------------------------
156-
-- Error catching
157-
----------------------------------------------------------------------------
158-
159-
{-# INLINEABLE defaultHandles #-}
160-
defaultHandles :: [Handler IO (Either String a)]
161-
defaultHandles =
162-
[ Handler $ \(x :: ArithException) -> return (Left (displayException x))
163-
, Handler $ \(x :: ArrayException) -> return (Left (displayException x))
164-
, Handler $ \(x :: ErrorCall) -> return (Left (displayException x))
165-
, Handler $ \(x :: PatternMatchFail) -> return (Left (displayException x))
166-
, Handler $ \(x :: SomeException) -> throwM x ]
167-
168-
{-# INLINE spoon #-}
169-
spoon :: NFData a => a -> Either String a
170-
spoon a = unsafePerformIO $
171-
deepseq a (Right `fmap` return a) `catches` defaultHandles

0 commit comments

Comments
 (0)