diff --git a/hydra-plutus/exe/inspect-script/Main.hs b/hydra-plutus/exe/inspect-script/Main.hs index 2b7f9bca27e..4abf1d79423 100644 --- a/hydra-plutus/exe/inspect-script/Main.hs +++ b/hydra-plutus/exe/inspect-script/Main.hs @@ -9,7 +9,6 @@ import Data.ByteString.Lazy qualified as BL import Data.Text (pack) import Hydra.Cardano.Api.Prelude (unsafeHashFromBytes) import Hydra.Contract (scriptInfo) -import Hydra.Contract.Hash qualified as Hash import Hydra.Contract.Head as Head import Hydra.Contract.HeadState as Head import Hydra.Contract.HeadTokens qualified as HeadTokens @@ -84,15 +83,12 @@ main = do scripts = [ (headScript, "headScript") , (initialScript, "initialScript") - , (hashPlutusScript, "hashScript") ] headScript = Head.validatorScript initialScript = Initial.validatorScript - hashPlutusScript = Hash.validatorScript - compiledScripts = [ (Compiled Head.compiledValidator, "headScript") , (Compiled Initial.compiledValidator, "initialScript") diff --git a/hydra-plutus/hydra-plutus.cabal b/hydra-plutus/hydra-plutus.cabal index bee8e3dbe5e..eab74fdcb58 100644 --- a/hydra-plutus/hydra-plutus.cabal +++ b/hydra-plutus/hydra-plutus.cabal @@ -49,7 +49,6 @@ library Hydra.Contract.Deposit Hydra.Contract.DepositError Hydra.Contract.Error - Hydra.Contract.Hash Hydra.Contract.Head Hydra.Contract.HeadError Hydra.Contract.HeadState diff --git a/hydra-plutus/src/Hydra/Contract/Hash.hs b/hydra-plutus/src/Hydra/Contract/Hash.hs deleted file mode 100644 index f50e98af354..00000000000 --- a/hydra-plutus/src/Hydra/Contract/Hash.hs +++ /dev/null @@ -1,69 +0,0 @@ -{-# LANGUAGE TemplateHaskell #-} -{-# OPTIONS_GHC -fno-specialize #-} -{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:defer-errors #-} --- Plutus core version to compile to. In babbage era, that is Cardano protocol --- version 7 and 8, only plutus-core version 1.0.0 is available. -{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-} - --- | An experimental validator which simply hashes a bytestring stored in the --- datum using one of three supported algorithms. -module Hydra.Contract.Hash where - -import PlutusTx.Prelude - -import Hydra.Prelude qualified as Haskell - -import Hydra.Cardano.Api (PlutusScriptVersion (PlutusScriptV2)) -import Hydra.Plutus.Extras (ValidatorType, scriptValidatorHash, wrapValidator) -import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode) -import PlutusLedgerApi.V2 ( - Datum (Datum), - Redeemer (Redeemer), - ScriptContext, - ScriptHash, - ) -import PlutusTx (CompiledCode) -import PlutusTx qualified -import PlutusTx.Builtins (equalsByteString) -import PlutusTx.IsData.Class (ToData (..)) - -data HashAlgorithm - = Base - | SHA2 - | SHA3 - | Blake2b - deriving stock (Haskell.Show, Haskell.Generic, Haskell.Enum, Haskell.Bounded) - -PlutusTx.unstableMakeIsData ''HashAlgorithm - -instance Haskell.Arbitrary HashAlgorithm where - arbitrary = Haskell.genericArbitrary - -type DatumType = BuiltinByteString -type RedeemerType = HashAlgorithm - -validator :: DatumType -> RedeemerType -> ScriptContext -> Bool -validator bytes algorithm _ctx = - case algorithm of - Base -> equalsByteString bytes bytes - SHA2 -> not . equalsByteString bytes $ sha2_256 bytes - SHA3 -> not . equalsByteString bytes $ sha3_256 bytes - Blake2b -> not . equalsByteString bytes $ blake2b_256 bytes - -compiledValidator :: CompiledCode ValidatorType -compiledValidator = - $$(PlutusTx.compile [||wrap validator||]) - where - wrap = wrapValidator @DatumType @RedeemerType - -validatorScript :: SerialisedScript -validatorScript = serialiseCompiledCode compiledValidator - -validatorHash :: ScriptHash -validatorHash = scriptValidatorHash PlutusScriptV2 validatorScript - -datum :: DatumType -> Datum -datum a = Datum (toBuiltinData a) - -redeemer :: RedeemerType -> Redeemer -redeemer a = Redeemer (toBuiltinData a)