Skip to content

Commit

Permalink
Revert "Embargo the use of script addresses for now"
Browse files Browse the repository at this point in the history
This reverts commit b9abc38.
  • Loading branch information
nc6 committed Aug 10, 2020
1 parent 60e96fa commit c28ac02
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 97 deletions.
Expand Up @@ -24,11 +24,9 @@ module Shelley.Spec.Ledger.Address
BootstrapAddress (..),
bootstrapAddressAttrsSize,
getNetwork,
addrUsesScript,
RewardAcnt (..),
serialiseRewardAcnt,
deserialiseRewardAcnt,
rewardAcntUsesScript,
-- internals exported for testing
getAddr,
getKeyHash,
Expand Down Expand Up @@ -86,8 +84,6 @@ import Shelley.Spec.Ledger.Credential
PaymentCredential,
Ptr (..),
StakeReference (..),
credentialUsesScript,
stakeReferenceUsesScript,
)
import Shelley.Spec.Ledger.Crypto
import Shelley.Spec.Ledger.Keys
Expand Down Expand Up @@ -222,15 +218,6 @@ parseAddr t = do
badHex h = fail $ "Addresses are expected in hex encoding for now: " ++ show h
badFormat = fail "Address is not in the right format"

addrUsesScript :: Addr crypto -> Bool
addrUsesScript (AddrBootstrap _) = False
addrUsesScript (Addr _ pc sr) =
credentialUsesScript pc
|| stakeReferenceUsesScript sr

rewardAcntUsesScript :: RewardAcnt crypto -> Bool
rewardAcntUsesScript = credentialUsesScript . getRwdCred

byron :: Int
byron = 7

Expand Down
Expand Up @@ -17,8 +17,6 @@ module Shelley.Spec.Ledger.Credential
Ptr (..),
StakeCredential,
StakeReference (..),
credentialUsesScript,
stakeReferenceUsesScript,
)
where

Expand Down Expand Up @@ -165,12 +163,3 @@ instance
where
toCBOR (GenesisCredential kh) =
toCBOR kh

credentialUsesScript :: Credential kr crypto -> Bool
credentialUsesScript ScriptHashObj {} = True
credentialUsesScript KeyHashObj {} = False

stakeReferenceUsesScript :: StakeReference crypto -> Bool
stakeReferenceUsesScript (StakeRefBase cred) = credentialUsesScript cred
stakeReferenceUsesScript (StakeRefPtr _) = False
stakeReferenceUsesScript StakeRefNull = False
Expand Up @@ -76,17 +76,11 @@ import Shelley.Spec.Ledger.Serialization
)
import Shelley.Spec.Ledger.Slot (SlotNo)
import Shelley.Spec.Ledger.Tx (Tx (..), TxIn, TxOut (..))
import Shelley.Spec.Ledger.TxData
( PoolParams,
RewardAcnt,
TxBody (..),
unWdrl,
)
import Shelley.Spec.Ledger.TxData (PoolParams, RewardAcnt, TxBody (..), unWdrl)
import Shelley.Spec.Ledger.UTxO
( UTxO (..),
balance,
totalDeposits,
txCreatesNoScriptAddrs,
txins,
txouts,
txup,
Expand Down Expand Up @@ -137,7 +131,6 @@ instance
| UpdateFailure (PredicateFailure (PPUP crypto)) -- Subtransition Failures
| OutputBootAddrAttrsTooBig
![TxOut crypto] -- list of supplied bad transaction outputs
| ScriptsEmbargoed -- blocking use of scripts for the moment
deriving (Eq, Show, Generic)
transitionRules = [utxoInductive]
initialRules = [initialLedgerState]
Expand Down Expand Up @@ -201,8 +194,6 @@ instance
OutputBootAddrAttrsTooBig outs ->
encodeListLen 2 <> toCBOR (10 :: Word8)
<> encodeFoldable outs
ScriptsEmbargoed ->
encodeListLen 1 <> toCBOR (11 :: Word8)

instance
(Crypto crypto) =>
Expand Down Expand Up @@ -248,8 +239,6 @@ instance
10 -> do
outs <- decodeList fromCBOR
pure (2, OutputBootAddrAttrsTooBig outs)
11 ->
pure (1, ScriptsEmbargoed)
k -> invalidKey k

initialLedgerState :: InitialRule (UTXO crypto)
Expand Down Expand Up @@ -306,9 +295,6 @@ utxoInductive = do
[out | out@(TxOut (AddrBootstrap addr) _) <- outputs, bootstrapAddressAttrsSize addr > 64]
null outputsAttrsTooBig ?! OutputBootAddrAttrsTooBig outputsAttrsTooBig

-- Block use of script addresses until we fix the ScriptHash size mismatch.
txCreatesNoScriptAddrs txb ?! ScriptsEmbargoed

let maxTxSize_ = fromIntegral (_maxTxSize pp)
txSize_ = txsize tx
txSize_ <= maxTxSize_ ?! MaxTxSizeUTxO txSize_ maxTxSize_
Expand Down
Expand Up @@ -36,13 +36,12 @@ module Shelley.Spec.Ledger.UTxO
verifyWitVKey,
scriptsNeeded,
txinsScript,
txCreatesNoScriptAddrs,
)
where

import Cardano.Binary (FromCBOR (..), ToCBOR (..))
import Cardano.Prelude (Generic, NFData, NoUnexpectedThunks (..))
import Control.Iterate.SetAlgebra (BaseRep (MapR), Embed (..), Exp (Base), HasExp (toExp), eval, rng)
import Control.Iterate.SetAlgebra (BaseRep (MapR), Embed (..), Exp (Base), HasExp (toExp))
import Data.Foldable (toList)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
Expand All @@ -51,15 +50,11 @@ import Data.Set (Set)
import qualified Data.Set as Set
import Data.Typeable (Typeable)
import Quiet
import Shelley.Spec.Ledger.Address
( Addr (..),
addrUsesScript,
rewardAcntUsesScript,
)
import Shelley.Spec.Ledger.Address (Addr (..))
import Shelley.Spec.Ledger.BaseTypes (strictMaybeToMaybe)
import Shelley.Spec.Ledger.Coin (Coin (..))
import Shelley.Spec.Ledger.Core (Relation (..))
import Shelley.Spec.Ledger.Credential (Credential (..), credentialUsesScript)
import Shelley.Spec.Ledger.Credential (Credential (..))
import Shelley.Spec.Ledger.Crypto
import Shelley.Spec.Ledger.Delegation.Certificates
( DCert (..),
Expand All @@ -81,9 +76,7 @@ import Shelley.Spec.Ledger.PParams (PParams, Update, _keyDeposit, _poolDeposit)
import Shelley.Spec.Ledger.Scripts
import Shelley.Spec.Ledger.Tx (Tx (..))
import Shelley.Spec.Ledger.TxData
( DelegCert (..),
MIRCert (..),
PoolCert (..),
( PoolCert (..),
PoolParams (..),
TxBody (..),
TxId (..),
Expand Down Expand Up @@ -308,19 +301,3 @@ txinsScript txInps (UTxO u) = foldr add Set.empty txInps
Just (TxOut (Addr _ (ScriptHashObj _) _) _) -> Set.insert input ans
Just _ -> ans
Nothing -> ans

txCreatesNoScriptAddrs :: Crypto crypto => TxBody crypto -> Bool
txCreatesNoScriptAddrs txb =
null outputsUsingScripts
&& null stakeAddrCertsUsingScripts
&& null poolRegCertsUsingScripts
&& null mirCertsUsingScripts
where
outputsUsingScripts =
[out | out@(TxOut addr _) <- Set.toList (eval (rng (txouts txb))), addrUsesScript addr]
stakeAddrCertsUsingScripts =
[cert | cert@(DCertDeleg (RegKey sc)) <- toList (_certs txb), credentialUsesScript sc]
poolRegCertsUsingScripts =
[cert | cert@(DCertPool (RegPool pparams)) <- toList (_certs txb), rewardAcntUsesScript (_poolRAcnt pparams)]
mirCertsUsingScripts =
[cert | cert@(DCertMir mir) <- toList (_certs txb), any credentialUsesScript (Map.keys (mirRewards mir))]
Expand Up @@ -85,22 +85,16 @@ someKeyPairs c lower upper =
<$> QC.choose (lower, upper)
<*> QC.shuffle (keyPairs c)

mSigCombinedScripts :: Constants -> MultiSigPairs c
mSigCombinedScripts _ = []
mSigBaseScripts :: Crypto c => Constants -> MultiSigPairs c
mSigBaseScripts c = mkMSigScripts (keyPairs c)

{- TODO re-enable after the script embargo has been lifted
-
- mSigBaseScripts :: Crypto c => Constants -> MultiSigPairs c
- mSigBaseScripts c = mkMSigScripts (keyPairs c)
-
- mSigCombinedScripts :: Crypto c => Constants -> MultiSigPairs c
- mSigCombinedScripts c@(Constants {numBaseScripts}) =
- mkMSigCombinations . take numBaseScripts $ mSigBaseScripts c
-}
mSigCombinedScripts :: Crypto c => Constants -> MultiSigPairs c
mSigCombinedScripts c@(Constants {numBaseScripts}) =
mkMSigCombinations . take numBaseScripts $ mSigBaseScripts c

-- | Select between _lower_ and _upper_ scripts from the possible combinations
-- of the first `numBaseScripts` multi-sig scripts of `mSigScripts`.
someScripts :: Constants -> Int -> Int -> Gen (MultiSigPairs c)
someScripts :: Crypto c => Constants -> Int -> Int -> Gen (MultiSigPairs c)
someScripts c lower upper =
take
<$> QC.choose (lower, upper)
Expand Down
Expand Up @@ -32,13 +32,16 @@ import qualified Data.ByteString as BS
import Data.Foldable (toList)
import qualified Data.Map.Strict as Map
import Data.Proxy
import Data.Sequence.Strict (StrictSeq)
import Shelley.Spec.Ledger.Address (pattern Addr)
import Shelley.Spec.Ledger.BaseTypes (Globals (epochInfo), StrictMaybe (..))
import Shelley.Spec.Ledger.BlockChain
( bhbody,
bheaderSlotNo,
pattern Block,
pattern TxSeq,
)
import Shelley.Spec.Ledger.Credential (pattern ScriptHashObj)
import Shelley.Spec.Ledger.Delegation.Certificates
( isDeRegKey,
isDelegation,
Expand All @@ -60,8 +63,15 @@ import Shelley.Spec.Ledger.Tx (_body)
import Shelley.Spec.Ledger.TxData
( Wdrl (..),
_certs,
_outputs,
_txUpdate,
_wdrls,
pattern DCertDeleg,
pattern DeRegKey,
pattern Delegate,
pattern Delegation,
pattern RegKey,
pattern TxOut,
)
import Test.QuickCheck
( Property,
Expand All @@ -82,6 +92,7 @@ import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes
DPState,
LEDGER,
Tx,
TxOut,
UTxOState,
)
import Test.Shelley.Spec.Ledger.Generator.Constants (Constants (..))
Expand Down Expand Up @@ -189,8 +200,6 @@ relevantCasesAreCoveredForTrace tr = do
tl' < 10 * length (filter isRegPool certs_),
60
),
{- TODO re-enable after the script embargo has been lifted
-
( "at least 10% of transactions have script TxOuts",
0.1 < txScriptOutputsRatio (map (_outputs . _body) txs),
20
Expand All @@ -199,7 +208,6 @@ relevantCasesAreCoveredForTrace tr = do
0.1 < scriptCredentialCertsRatio certs_,
60
),
-}
( "at least 10% of transactions have a reward withdrawal",
0.1 < withdrawalRatio txs,
60
Expand All @@ -221,7 +229,6 @@ relevantCasesAreCoveredForTrace tr = do

-- | Ratio of certificates with script credentials to the number of certificates
-- that could have script credentials.
{- TODO re-enable after the script embargo has been lifted
scriptCredentialCertsRatio :: [DCert C] -> Double
scriptCredentialCertsRatio certs =
ratioInt haveScriptCerts couldhaveScriptCerts
Expand All @@ -245,7 +252,6 @@ scriptCredentialCertsRatio certs =
_ -> False
)
certs
-}

-- | Extract the certificates from the transactions
certsByTx :: [Tx C] -> [[DCert C]]
Expand Down Expand Up @@ -279,7 +285,6 @@ ratioInt x y =
fromIntegral x / fromIntegral y

-- | Transaction has script locked TxOuts
{- TODO re-enable after the script embargo has been lifted
txScriptOutputsRatio :: [StrictSeq (TxOut C)] -> Double
txScriptOutputsRatio txoutsList =
ratioInt
Expand All @@ -294,7 +299,6 @@ txScriptOutputsRatio txoutsList =
_ -> 0
)
txouts
-}

-- | Transaction has a reward withdrawal
withdrawalRatio :: [Tx C] -> Double
Expand Down

0 comments on commit c28ac02

Please sign in to comment.