Skip to content

Commit

Permalink
Merge pull request #2314 from input-output-hk/lehins/my-first-commits
Browse files Browse the repository at this point in the history
Minor improvement - introduce RawSeed - 2
  • Loading branch information
nc6 committed Jun 8, 2021
2 parents ecb7275 + 8d58f9f commit 452ec4e
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 289 deletions.
Expand Up @@ -129,7 +129,8 @@ import Test.Cardano.Ledger.Generic.Updaters
import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes (C_Crypto)
import Test.Shelley.Spec.Ledger.Generator.EraGen (genesisId)
import Test.Shelley.Spec.Ledger.Utils
( applySTSTest,
( RawSeed (..),
applySTSTest,
mkKESKeyPair,
mkKeyPair,
mkVRFKeyPair,
Expand Down Expand Up @@ -176,18 +177,18 @@ scriptAddr :: forall era. (Scriptic era) => Core.Script era -> Proof era -> Addr
scriptAddr s _pf = Addr Testnet pCred sCred
where
pCred = ScriptHashObj . hashScript @era $ s
(_ssk, svk) = mkKeyPair @(Crypto era) (0, 0, 0, 0, 0)
(_ssk, svk) = mkKeyPair @(Crypto era) (RawSeed 0 0 0 0 0)
sCred = StakeRefBase . KeyHashObj . hashKey $ svk

someKeys :: forall era. Era era => Proof era -> KeyPair 'Payment (Crypto era)
someKeys _pf = KeyPair vk sk
where
(sk, vk) = mkKeyPair @(Crypto era) (1, 1, 1, 1, 1)
(sk, vk) = mkKeyPair @(Crypto era) (RawSeed 1 1 1 1 1)

someAddr :: forall era. Era era => Proof era -> Addr (Crypto era)
someAddr pf = Addr Testnet pCred sCred
where
(_ssk, svk) = mkKeyPair @(Crypto era) (0, 0, 0, 0, 2)
(_ssk, svk) = mkKeyPair @(Crypto era) (RawSeed 0 0 0 0 2)
pCred = KeyHashObj . hashKey . vKey $ someKeys pf
sCred = StakeRefBase . KeyHashObj . hashKey $ svk

Expand Down Expand Up @@ -224,7 +225,7 @@ timelockHash n pf = hashScript @era $ (timelockScript n pf)
timelockAddr :: forall era. PostShelley era => Proof era -> Addr (Crypto era)
timelockAddr pf = Addr Testnet pCred sCred
where
(_ssk, svk) = mkKeyPair @(Crypto era) (0, 0, 0, 0, 2)
(_ssk, svk) = mkKeyPair @(Crypto era) (RawSeed 0 0 0 0 2)
pCred = ScriptHashObj (timelockHash 0 pf)
sCred = StakeRefBase . KeyHashObj . hashKey $ svk

Expand Down Expand Up @@ -939,7 +940,7 @@ incorrectNetworkIDTx pf =
]

extraneousKeyHash :: CC.Crypto c => KeyHash 'Witness c
extraneousKeyHash = hashKey . snd . mkKeyPair $ (0, 0, 0, 0, 99)
extraneousKeyHash = hashKey . snd . mkKeyPair $ (RawSeed 0 0 0 0 99)

missingRequiredWitnessTxBody :: Era era => Proof era -> Core.TxBody era
missingRequiredWitnessTxBody pf =
Expand Down Expand Up @@ -1563,7 +1564,7 @@ initialBBodyState pf =
coldKeys :: CC.Crypto c => KeyPair 'BlockIssuer c
coldKeys = KeyPair vk sk
where
(sk, vk) = mkKeyPair (1, 2, 3, 2, 1)
(sk, vk) = mkKeyPair (RawSeed 1 2 3 2 1)

makeNaiveBlock ::
forall era.
Expand Down Expand Up @@ -1603,8 +1604,8 @@ makeNaiveBlock txs = Block (BHeader bhb sig) txs'
nonceNonce = mkSeed seedEta (SlotNo 0) NeutralNonce
leaderNonce = mkSeed seedL (SlotNo 0) NeutralNonce
txs' = (toTxSeq @era) . StrictSeq.fromList $ txs
(svrf, vvrf) = mkVRFKeyPair (0, 0, 0, 0, 2)
(skes, vkes) = mkKESKeyPair (0, 0, 0, 0, 3)
(svrf, vvrf) = mkVRFKeyPair (RawSeed 0 0 0 0 2)
(skes, vkes) = mkKESKeyPair (RawSeed 0 0 0 0 3)

testAlonzoBlock :: Block A
testAlonzoBlock =
Expand Down
Expand Up @@ -40,7 +40,7 @@ import qualified Shelley.Spec.Ledger.Scripts as Multi
import Shelley.Spec.Ledger.TxBody (WitVKey (..))
import Shelley.Spec.Ledger.UTxO (makeWitnessVKey)
import Test.Cardano.Ledger.Generic.Proof
import Test.Shelley.Spec.Ledger.Utils (mkKeyPair)
import Test.Shelley.Spec.Ledger.Utils (RawSeed (..), mkKeyPair)

-- ===========================================================================
-- Classes for "picking" the unique element of a type associated with an Int
Expand Down Expand Up @@ -117,7 +117,7 @@ instance CC.Crypto c => Fixed (KeyPair kr c) where
unique n = (KeyPair a b)
where
m1 = fromIntegral n
(b, a) = mkKeyPair (0, 0, 0, 0, m1)
(b, a) = mkKeyPair (RawSeed 0 0 0 0 m1)

theKeyPair :: CC.Crypto c => Int -> KeyPair kr c
theKeyPair = unique
Expand Down Expand Up @@ -285,8 +285,8 @@ instance CC.Crypto c => Fixed (PublicSecret kr kr' c) where
where
m1 = fromIntegral (2 * n)
m2 = fromIntegral (2 * n + 1)
(b, a) = mkKeyPair (m1, m1, m1, m1, m1)
(d, c) = mkKeyPair (m2, m2, m2, m2, m2)
(b, a) = mkKeyPair (RawSeed m1 m1 m1 m1 m1)
(d, c) = mkKeyPair (RawSeed m2 m2 m2 m2 m2)

-- ===============================================================
-- PrettyA instances
Expand Down
2 changes: 1 addition & 1 deletion implementation-decisions.md
Expand Up @@ -82,7 +82,7 @@ After that there are a few options:

### The decision is agreed to

THe proposal becomes the choice for concrete implementations henceforth. The PR
The proposal becomes the choice for concrete implementations henceforth. The PR
is approved and merged


Expand Down
4 changes: 2 additions & 2 deletions semantics/executable-spec/src/Data/MemoBytes.hs
Expand Up @@ -17,9 +17,9 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

-- | MemoBytes is an abstration for a datetype that encodes its own serialization.
-- | MemoBytes is an abstraction for a data type that encodes its own serialization.
-- The idea is to use a newtype around a MemoBytes non-memoizing version.
-- For example: newtype Foo = Foo(MemoBytes NonMemoizingFoo)
-- For example: newtype Foo = Foo (MemoBytes NonMemoizingFoo)
-- This way all the instances for Foo (Eq,Show,Ord,ToCBOR,FromCBOR,NoThunks,Generic)
-- can be derived for free.
module Data.MemoBytes
Expand Down
Expand Up @@ -27,19 +27,19 @@ import Cardano.Ledger.Keys
KeyRole (..),
)
import Test.Cardano.Ledger.EraBuffet (TestCrypto)
import Test.Shelley.Spec.Ledger.Utils (mkAddr, mkKeyPair)
import Test.Shelley.Spec.Ledger.Utils (RawSeed (..), mkAddr, mkKeyPair)

-- | Alice's payment key pair
alicePay :: KeyPair 'Payment TestCrypto
alicePay = KeyPair vk sk
where
(sk, vk) = mkKeyPair (0, 0, 0, 0, 0)
(sk, vk) = mkKeyPair (RawSeed 0 0 0 0 0)

-- | Alice's stake key pair
aliceStake :: KeyPair 'Staking TestCrypto
aliceStake = KeyPair vk sk
where
(sk, vk) = mkKeyPair (1, 1, 1, 1, 1)
(sk, vk) = mkKeyPair (RawSeed 1 1 1 1 1)

-- | Alice's base address
aliceAddr :: Addr TestCrypto
Expand All @@ -49,13 +49,13 @@ aliceAddr = mkAddr (alicePay, aliceStake)
bobPay :: KeyPair 'Payment TestCrypto
bobPay = KeyPair vk sk
where
(sk, vk) = mkKeyPair (2, 2, 2, 2, 2)
(sk, vk) = mkKeyPair (RawSeed 2 2 2 2 2)

-- | Bob's stake key pair
bobStake :: KeyPair 'Staking TestCrypto
bobStake = KeyPair vk sk
where
(sk, vk) = mkKeyPair (3, 3, 3, 3, 3)
(sk, vk) = mkKeyPair (RawSeed 3 3 3 3 3)

-- | Bob's address
bobAddr :: Addr TestCrypto
Expand All @@ -65,13 +65,13 @@ bobAddr = mkAddr (bobPay, bobStake)
carlPay :: KeyPair 'Payment TestCrypto
carlPay = KeyPair vk sk
where
(sk, vk) = mkKeyPair (4, 4, 4, 4, 4)
(sk, vk) = mkKeyPair (RawSeed 4 4 4 4 4)

-- | Carl's stake key pair
carlStake :: KeyPair 'Staking TestCrypto
carlStake = KeyPair vk sk
where
(sk, vk) = mkKeyPair (5, 5, 5, 5, 5)
(sk, vk) = mkKeyPair (RawSeed 5 5 5 5 5)

-- | Carl's address
carlAddr :: Addr TestCrypto
Expand All @@ -81,13 +81,13 @@ carlAddr = mkAddr (carlPay, carlStake)
dariaPay :: KeyPair 'Payment TestCrypto
dariaPay = KeyPair vk sk
where
(sk, vk) = mkKeyPair (6, 6, 6, 6, 6)
(sk, vk) = mkKeyPair (RawSeed 6 6 6 6 6)

-- | Daria's stake key pair
dariaStake :: KeyPair 'Staking TestCrypto
dariaStake = KeyPair vk sk
where
(sk, vk) = mkKeyPair (7, 7, 7, 7, 7)
(sk, vk) = mkKeyPair (RawSeed 7 7 7 7 7)

-- | Daria's address
dariaAddr :: Addr TestCrypto
Expand Down
Expand Up @@ -59,7 +59,7 @@ import Test.Shelley.Spec.Ledger.Serialisation.GoldenUtils
checkEncodingCBOR,
checkEncodingCBORAnnotated,
)
import Test.Shelley.Spec.Ledger.Utils (mkGenKey, mkKeyPair)
import Test.Shelley.Spec.Ledger.Utils (RawSeed (..), mkGenKey, mkKeyPair)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (Assertion, testCase)

Expand Down Expand Up @@ -94,20 +94,20 @@ assetName3 = BS.pack "a3"
-- ===========================================

testGKeyHash :: KeyHash 'Genesis TestCrypto
testGKeyHash = hashKey . snd . mkGenKey $ (0, 0, 0, 0, 0)
testGKeyHash = hashKey . snd . mkGenKey $ (RawSeed 0 0 0 0 0)

testAddrE :: Addr TestCrypto
testAddrE =
Addr
Testnet
(KeyHashObj . hashKey . snd $ mkKeyPair (0, 0, 0, 0, 1))
(KeyHashObj . hashKey . snd $ mkKeyPair (RawSeed 0 0 0 0 1))
StakeRefNull

testKeyHash :: KeyHash 'Staking TestCrypto
testKeyHash = hashKey . snd $ mkKeyPair (0, 0, 0, 0, 2)
testKeyHash = hashKey . snd $ mkKeyPair (RawSeed 0 0 0 0 2)

testStakeCred :: Credential 'Staking TestCrypto
testStakeCred = KeyHashObj . hashKey . snd $ mkKeyPair (0, 0, 0, 0, 3)
testStakeCred = KeyHashObj . hashKey . snd $ mkKeyPair (RawSeed 0 0 0 0 3)

testUpdate ::
forall era.
Expand Down Expand Up @@ -150,8 +150,8 @@ testUpdate =

scriptGoldenTest :: forall era. (Era era) => TestTree
scriptGoldenTest =
let kh0 = hashKey . snd . mkGenKey $ (0, 0, 0, 0, 0) :: KeyHash 'Witness (Crypto era)
kh1 = hashKey . snd . mkGenKey $ (1, 1, 1, 1, 1) :: KeyHash 'Witness (Crypto era)
let kh0 = hashKey . snd . mkGenKey $ (RawSeed 0 0 0 0 0) :: KeyHash 'Witness (Crypto era)
kh1 = hashKey . snd . mkGenKey $ (RawSeed 1 1 1 1 1) :: KeyHash 'Witness (Crypto era)
in checkEncodingCBORAnnotated
"timelock_script"
( RequireAllOf @(Crypto era)
Expand Down

0 comments on commit 452ec4e

Please sign in to comment.