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

Commit

Permalink
Merge #3952 #3957 #3963
Browse files Browse the repository at this point in the history
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.


3957: Implement Update endpoints for the Node API r=parsonsmatt a=parsonsmatt

## Description

This PR implements the node update endpoints.

## Linked issue

There's a change to the implementation of the API. The decision is covered here:
cardano-foundation/cardano-wallet#151



3963: [DEVOPS-1184] Prevent OSX from building unncessary nix-tools r=disassembler a=disassembler

* Only require nix-tools linux passing for required jobset
* only run cross tests on windows

## Description

<!--- A brief description of this PR and the problem is trying to solve -->

## Linked issue

<!--- Put here the relevant issue from YouTrack -->



Co-authored-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Co-authored-by: parsonsmatt <parsonsmatt@gmail.com>
Co-authored-by: Samuel Leathers <samuel.leathers@iohk.io>
  • Loading branch information
4 people committed Dec 13, 2018
4 parents 2b95d61 + 7739552 + 729604b + 9b7f310 commit 837ac28
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 949 deletions.
1 change: 0 additions & 1 deletion cabal.project.freeze
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ constraints: Cabal ==2.2.0.1,
pipes-bytestring ==2.1.6,
pipes-interleave ==1.1.3,
pipes-safe ==2.2.9,
plutus-prototype ==0.1.0.0,
pretty-show ==1.7,
purescript-bridge ==0.13.0.0,
pvss ==0.2.0,
Expand Down
3 changes: 0 additions & 3 deletions chain/cardano-sl-chain.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ library
Pos.Chain.Security
Pos.Chain.Ssc
Pos.Chain.Script
Pos.Chain.Script.Examples
Pos.Chain.Txp
Pos.Chain.Update

other-modules:

Pos.Chain.Block.Block
Pos.Chain.Block.ComponentBlock
Pos.Chain.Block.Configuration
Expand Down Expand Up @@ -190,7 +188,6 @@ library
, mtl
, neat-interpolation
, parsec
, plutus-prototype
, QuickCheck
, reflection
, safecopy
Expand Down
127 changes: 1 addition & 126 deletions chain/src/Pos/Chain/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,14 @@
module Pos.Chain.Script
( Script(..)
, PlutusError(..)

, txScriptCheck

, parseValidator
, parseRedeemer

, stdlib

, isKnownScriptVersion
) where

import Universum hiding (lift)
import Universum

import Control.Exception (ArithException (..), ArrayException (..),
ErrorCall (..), PatternMatchFail (..))
import Control.Exception.Safe (Handler (..), SomeException (..),
catches, displayException)
import Control.Lens (_Left)
import Control.Monad.Error.Class (throwError)
import qualified Data.ByteArray as BA
import qualified Data.ByteString.Lazy as BSL
import qualified Data.Set as S
import qualified Elaboration.Contexts as PL
import qualified Formatting.Buildable as Buildable
import qualified Interface.Integration as PL
import qualified Interface.Prelude as PL
import Language.Haskell.TH.Syntax (Lift (..), runIO)
import qualified PlutusCore.EvaluatorTypes as PLCore
import qualified PlutusCore.Program as PL
import System.IO.Unsafe (unsafePerformIO)
import qualified Utils.Names as PL

import qualified Pos.Binary.Class as Bi
import Pos.Chain.Txp.TxWitness (TxSigData (..))
import Pos.Core.Binary ()
import Pos.Core.Common (Script (..), ScriptVersion)
import Pos.Core.Script ()

{- NOTE
Scripts are versioned. The current version is 0. All functions below work
with version 0 scripts.
Here's what would lead to script version increment:
* changing serialization in any way
* adding anything to the stdlib
-}

isKnownScriptVersion :: ScriptVersion -> Bool
isKnownScriptVersion v = v == 0

-- | Post-process loaded program to remove stdlib references that were added
-- to the environment by 'loadValidator' or 'loadRedeemer'.
stripStdlib :: PL.Program -> PL.Program
stripStdlib (PL.Program xs) = PL.Program (filter (not . std) xs)
where
stds = S.fromList (map (PL.unsourced . fst) (PL.definitions stdlib))
std (name, _) = PL.unsourced name `elem` stds

-- | Parse a script intended to serve as a validator (or “lock”) in a
-- transaction output.
parseValidator :: Text -> Either String Script
parseValidator t = do
scr <- stripStdlib <$> PL.loadValidator stdlib (toString t)
return Script {
scrScript = Bi.serialize' scr,
scrVersion = 0 }

-- | Parse a script intended to serve as a redeemer (or “proof”) in a
-- transaction input.
parseRedeemer :: Text -> Either String Script
parseRedeemer t = do
scr <- stripStdlib <$> PL.loadRedeemer stdlib (toString t)
return Script {
scrScript = Bi.serialize' scr,
scrVersion = 0 }

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

-- | Validate a transaction, given a validator and a redeemer.
txScriptCheck
:: TxSigData
-> Script -- ^ Validator
-> Script -- ^ Redeemer
-> Either PlutusError ()
txScriptCheck sigData validator redeemer = case spoon result of
Left err -> throwError (PlutusException (toText err))
Right (Left err) -> throwError err
Right (Right False) -> throwError PlutusReturnedFalse
Right (Right True) -> pass
where
result :: Either PlutusError Bool
result = do
-- TODO: when we support more than one version, complain if versions
-- don't match
valScr <- case scrVersion validator of
0 -> over _Left PlutusDecodingFailure $
Bi.decodeFull' (scrScript validator)
v -> Left (PlutusUnknownVersion v)
redScr <- case scrVersion redeemer of
0 -> over _Left PlutusDecodingFailure $
Bi.decodeFull' (scrScript redeemer)
v -> Left (PlutusUnknownVersion v)
(script, env) <- over _Left (PlutusExecutionFailure . toText) $
PL.buildValidationScript stdlib valScr redScr
let txInfo = PLCore.TransactionInfo
{ txHash = BSL.fromStrict . BA.convert $
txSigTxHash sigData }
over _Left (PlutusExecutionFailure . toText) $
PL.checkValidationResult txInfo (script, env)

stdlib :: PL.DeclContext
stdlib = case PL.loadLibrary PL.emptyDeclContext prelude of
Right x -> x
Left err -> error $ toText
("stdlib: error while parsing Plutus prelude: " ++ err)
where
prelude = $(lift . toString =<< runIO PL.preludeString)

----------------------------------------------------------------------------
-- Error catching
----------------------------------------------------------------------------

{-# INLINEABLE defaultHandles #-}
defaultHandles :: [Handler IO (Either String a)]
defaultHandles =
[ Handler $ \(x :: ArithException) -> return (Left (displayException x))
, Handler $ \(x :: ArrayException) -> return (Left (displayException x))
, Handler $ \(x :: ErrorCall) -> return (Left (displayException x))
, Handler $ \(x :: PatternMatchFail) -> return (Left (displayException x))
, Handler $ \(x :: SomeException) -> throwM x ]

{-# INLINE spoon #-}
spoon :: NFData a => a -> Either String a
spoon a = unsafePerformIO $
deepseq a (Right `fmap` return a) `catches` defaultHandles
Loading

0 comments on commit 837ac28

Please sign in to comment.