├── .buildkite ├── nightly-tests.sh ├── nightly.yml └── pipeline.yml ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── custom.md └── issue_template.md ├── .gitignore ├── CODEOWNERS ├── README.md ├── bors.toml ├── cabal.project ├── cardano-ledger ├── LICENSE ├── README.md ├── Setup.hs ├── cardano-ledger.cabal ├── mainnet-genesis.json ├── src │ └── Cardano │ │ └── Chain │ │ ├── Block.hs │ │ ├── Block │ │ ├── Block.hs │ │ ├── Body.hs │ │ ├── Boundary.hs │ │ ├── Header.hs │ │ ├── Proof.hs │ │ ├── Validation.hs │ │ └── ValidationMode.hs │ │ ├── Byron │ │ ├── API.hs │ │ └── API │ │ │ ├── Common.hs │ │ │ ├── Mempool.hs │ │ │ ├── Protocol.hs │ │ │ └── Validation.hs │ │ ├── Common.hs │ │ ├── Common │ │ ├── AddrAttributes.hs │ │ ├── AddrSpendingData.hs │ │ ├── Address.hs │ │ ├── AddressHash.hs │ │ ├── Attributes.hs │ │ ├── BlockCount.hs │ │ ├── CBOR.hs │ │ ├── ChainDifficulty.hs │ │ ├── Compact.hs │ │ ├── KeyHash.hs │ │ ├── Lovelace.hs │ │ ├── LovelacePortion.hs │ │ ├── Merkle.hs │ │ ├── NetworkMagic.hs │ │ ├── TxFeePolicy.hs │ │ └── TxSizeLinear.hs │ │ ├── Constants.hs │ │ ├── Delegation.hs │ │ ├── Delegation │ │ ├── Certificate.hs │ │ ├── Map.hs │ │ ├── Payload.hs │ │ └── Validation │ │ │ ├── Activation.hs │ │ │ ├── Interface.hs │ │ │ └── Scheduling.hs │ │ ├── Epoch │ │ ├── File.hs │ │ └── Validation.hs │ │ ├── Genesis.hs │ │ ├── Genesis │ │ ├── AvvmBalances.hs │ │ ├── Config.hs │ │ ├── Data.hs │ │ ├── Delegation.hs │ │ ├── Generate.hs │ │ ├── Hash.hs │ │ ├── Initializer.hs │ │ ├── KeyHashes.hs │ │ ├── NonAvvmBalances.hs │ │ └── Spec.hs │ │ ├── MempoolPayload.hs │ │ ├── ProtocolConstants.hs │ │ ├── Slotting.hs │ │ ├── Slotting │ │ ├── EpochAndSlotCount.hs │ │ ├── EpochNumber.hs │ │ ├── EpochSlots.hs │ │ ├── SlotCount.hs │ │ └── SlotNumber.hs │ │ ├── Ssc.hs │ │ ├── UTxO.hs │ │ ├── UTxO │ │ ├── Compact.hs │ │ ├── GenesisUTxO.hs │ │ ├── Tx.hs │ │ ├── TxAux.hs │ │ ├── TxPayload.hs │ │ ├── TxProof.hs │ │ ├── TxWitness.hs │ │ ├── UTxO.hs │ │ ├── UTxOConfiguration.hs │ │ ├── Validation.hs │ │ └── ValidationMode.hs │ │ ├── Update.hs │ │ ├── Update │ │ ├── ApplicationName.hs │ │ ├── InstallerHash.hs │ │ ├── Payload.hs │ │ ├── Proof.hs │ │ ├── Proposal.hs │ │ ├── ProtocolParameters.hs │ │ ├── ProtocolParametersUpdate.hs │ │ ├── ProtocolVersion.hs │ │ ├── SoftforkRule.hs │ │ ├── SoftwareVersion.hs │ │ ├── SystemTag.hs │ │ ├── Validation │ │ │ ├── Endorsement.hs │ │ │ ├── Interface.hs │ │ │ ├── Interface │ │ │ │ └── ProtocolVersionBump.hs │ │ │ ├── Registration.hs │ │ │ └── Voting.hs │ │ └── Vote.hs │ │ └── ValidationMode.hs └── test │ ├── LICENSE │ ├── NormalFormTest.hs │ ├── Setup.hs │ ├── Test │ ├── Cardano │ │ ├── Chain │ │ │ ├── Block │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Model.hs │ │ │ │ ├── Model │ │ │ │ │ └── Examples.hs │ │ │ │ ├── Size.hs │ │ │ │ ├── Validation.hs │ │ │ │ └── ValidationMode.hs │ │ │ ├── Buildable.hs │ │ │ ├── Byron │ │ │ │ └── API.hs │ │ │ ├── Common │ │ │ │ ├── Address.hs │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Compact.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ └── Lovelace.hs │ │ │ ├── Config.hs │ │ │ ├── Delegation │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Certificate.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ └── Model.hs │ │ │ ├── Elaboration │ │ │ │ ├── Block.hs │ │ │ │ ├── Delegation.hs │ │ │ │ ├── Keys.hs │ │ │ │ ├── UTxO.hs │ │ │ │ └── Update.hs │ │ │ ├── Epoch │ │ │ │ └── File.hs │ │ │ ├── Genesis │ │ │ │ ├── Dummy.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ └── Json.hs │ │ │ ├── MempoolPayload │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Example.hs │ │ │ │ └── Gen.hs │ │ │ ├── Slotting │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ └── Properties.hs │ │ │ ├── Ssc │ │ │ │ └── CBOR.hs │ │ │ ├── UTxO │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Compact.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ ├── Model.hs │ │ │ │ └── ValidationMode.hs │ │ │ └── Update │ │ │ │ ├── CBOR.hs │ │ │ │ ├── Example.hs │ │ │ │ ├── Gen.hs │ │ │ │ └── Properties.hs │ │ └── Mirror.hs │ └── Options.hs │ ├── cardano-ledger-test.cabal │ ├── golden │ ├── cbor │ │ ├── block │ │ │ ├── BlockSignature │ │ │ ├── Body │ │ │ ├── BoundaryBlockHeader │ │ │ ├── BoundaryBody │ │ │ ├── BoundaryConsensusData │ │ │ ├── BoundaryProof │ │ │ ├── ExtraBodyData │ │ │ ├── Header │ │ │ ├── HeaderHash │ │ │ ├── Proof │ │ │ ├── StaticConfig_GCSpec │ │ │ └── ToSign │ │ ├── common │ │ │ ├── AddrSpendingData_Redeem │ │ │ ├── AddrSpendingData_VerKey │ │ │ ├── AddrType_R │ │ │ ├── AddrType_VK │ │ │ ├── Address │ │ │ ├── Address0 │ │ │ ├── Address1 │ │ │ ├── Address2 │ │ │ ├── Address3 │ │ │ ├── Address4 │ │ │ ├── Attributes │ │ │ ├── BlockCount │ │ │ ├── ChainDifficulty │ │ │ ├── KeyHash │ │ │ ├── Lovelace │ │ │ ├── LovelacePortion │ │ │ ├── MerkleRoot │ │ │ ├── MerkleTree │ │ │ ├── TxFeePolicy_Linear │ │ │ └── TxSizeLinear │ │ ├── delegation │ │ │ ├── Certificate │ │ │ └── DlgPayload │ │ ├── mempoolpayload │ │ │ ├── MempoolPayload │ │ │ ├── MempoolPayload1 │ │ │ ├── MempoolPayload2 │ │ │ └── MempoolPayload3 │ │ ├── slotting │ │ │ ├── EpochAndSlotCount │ │ │ ├── EpochNumber │ │ │ ├── EpochSlots │ │ │ └── SlotNumber │ │ ├── ssc │ │ │ ├── Commitment │ │ │ ├── CommitmentsMap │ │ │ ├── InnerSharesMap │ │ │ ├── Opening │ │ │ ├── OpeningsMap │ │ │ ├── SharesMap │ │ │ ├── SignedCommitment │ │ │ ├── SscPayload_CertificatesPayload │ │ │ ├── SscPayload_CommitmentsPayload │ │ │ ├── SscPayload_OpeningsPayload │ │ │ ├── SscPayload_SharesPayload │ │ │ ├── SscProof_CertificatesProof │ │ │ ├── SscProof_CommitmentsProof │ │ │ ├── SscProof_OpeningsProof │ │ │ ├── SscProof_SharesProof │ │ │ ├── VssCertificate │ │ │ ├── VssCertificatesHash │ │ │ └── VssCertificatesMap │ │ ├── update │ │ │ ├── ApplicationName │ │ │ ├── AttackTarget_NetworkAddressTarget │ │ │ ├── AttackTarget_PubKeyAddressTarget │ │ │ ├── BlockHeader_Boundary │ │ │ ├── CommitmentSignature │ │ │ ├── HashRaw │ │ │ ├── HashTx │ │ │ ├── InstallerHash │ │ │ ├── Payload │ │ │ ├── Proof │ │ │ ├── Proposal │ │ │ ├── ProposalBody │ │ │ ├── ProtocolParameters │ │ │ ├── ProtocolParametersUpdate │ │ │ ├── ProtocolVersion │ │ │ ├── SharesDistribution │ │ │ ├── SoftforkRule │ │ │ ├── SoftwareVersion │ │ │ ├── StaticConfig_GCSpec │ │ │ ├── StaticConfig_GCSrc │ │ │ ├── SystemTag │ │ │ ├── UpId │ │ │ └── Vote │ │ └── utxo │ │ │ ├── HashTx │ │ │ ├── Tx │ │ │ ├── TxAttributes │ │ │ ├── TxId │ │ │ ├── TxInList │ │ │ ├── TxInWitness_RedeemWitness │ │ │ ├── TxInWitness_VKWitness │ │ │ ├── TxIn_Utxo │ │ │ ├── TxOut │ │ │ ├── TxOut1 │ │ │ ├── TxOutList │ │ │ ├── TxOutList1 │ │ │ ├── TxPayload1 │ │ │ ├── TxProof │ │ │ ├── TxSig │ │ │ ├── TxSigData │ │ │ └── TxWitness │ └── json │ │ └── genesis │ │ └── GenesisData0_Legacy_HasNetworkMagic │ └── test.hs ├── ci └── check-hydra.sh ├── configuration └── log-configuration.yaml ├── crypto ├── LICENSE ├── README.md ├── Setup.hs ├── cardano-crypto-wrapper.cabal ├── src │ └── Cardano │ │ ├── Crypto.hs │ │ └── Crypto │ │ ├── Encryption.hs │ │ ├── Hashing.hs │ │ ├── Orphans.hs │ │ ├── ProtocolMagic.hs │ │ ├── Random.hs │ │ ├── Signing.hs │ │ └── Signing │ │ ├── KeyGen.hs │ │ ├── Redeem.hs │ │ ├── Redeem │ │ ├── Compact.hs │ │ ├── KeyGen.hs │ │ ├── Signature.hs │ │ ├── SigningKey.hs │ │ └── VerificationKey.hs │ │ ├── Safe.hs │ │ ├── Safe │ │ ├── KeyGen.hs │ │ ├── PassPhrase.hs │ │ └── SafeSigner.hs │ │ ├── Signature.hs │ │ ├── SigningKey.hs │ │ ├── Tag.hs │ │ └── VerificationKey.hs └── test │ ├── LICENSE │ ├── Setup.hs │ ├── Test │ └── Cardano │ │ └── Crypto │ │ ├── CBOR.hs │ │ ├── Dummy.hs │ │ ├── Example.hs │ │ ├── Gen.hs │ │ ├── Hashing.hs │ │ ├── Json.hs │ │ ├── Keys.hs │ │ ├── Limits.hs │ │ ├── Orphans.hs │ │ ├── Random.hs │ │ └── Signing │ │ ├── Redeem.hs │ │ ├── Redeem │ │ └── Compact.hs │ │ ├── Safe.hs │ │ └── Signing.hs │ ├── cardano-crypto-test.cabal │ ├── golden │ ├── AbstractHash │ ├── DecShare │ ├── EncShare │ ├── PassPhrase │ ├── RedeemSignature │ ├── RedeemSigningKey │ ├── RedeemVerificationKey │ ├── Secret │ ├── SecretProof │ ├── Signature │ ├── SigningKey │ ├── VerificationKey │ ├── VssPublicKey │ └── json │ │ ├── ProtocolMagic0_Legacy_HasNetworkMagic │ │ ├── ProtocolMagic1_Legacy_HasNetworkMagic │ │ ├── ProtocolMagic2_Legacy_HasNetworkMagic │ │ ├── ProtocolMagic_Legacy_NMMustBeJust │ │ └── ProtocolMagic_Legacy_NMMustBeNothing │ └── test.hs ├── default.nix ├── doc └── network-magic.md ├── iohk-monitoring └── static │ ├── configuration-editor.html │ ├── css │ ├── configuration-editor.css │ └── w3.css │ └── images │ ├── favicon.ico │ └── iohk-logo.png ├── lib.nix ├── local-stack.sh ├── nix ├── cardano-mainnet-mirror.nix ├── default.nix ├── haskell.nix ├── pkgs.nix ├── regenerate.sh ├── sources.json ├── sources.nix ├── stack-shell.nix ├── update-iohk-nix.sh └── util.nix ├── release.nix ├── scripts ├── brittany │ ├── brittany-all-hs │ ├── config.yaml │ └── default.nix ├── buildkite │ ├── default.nix │ ├── rebuild.hs │ ├── stack-cabal-sync.sh │ └── stack-cabal_config_check.sh └── nix │ └── stack-shell.nix ├── shell.nix ├── stack.yaml └── weekly-reports ├── 2018-12-06.md ├── 2018-12-13.md ├── 2018-12-20.md ├── 2019-01-17.md ├── 2019-01-23.md ├── 2019-01-31.md └── 2019-02-07.md /.buildkite/nightly-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | nix build -f `dirname $0`/.. haskellPackages.cardano-ledger.components.tests.cardano-ledger-test -o cardano-ledger-test 3 | cd cardano-ledger && ../cardano-ledger-test/bin/cardano-ledger-test --scenario=QualityAssurance 4 | -------------------------------------------------------------------------------- /.buildkite/nightly.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - label: 'nightly tests' 3 | command: 4 | - ".buildkite/nightly-tests.sh" 5 | agents: 6 | system: x86_64-linux 7 | -------------------------------------------------------------------------------- /.buildkite/pipeline.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | - label: 'hydra-eval-errors' 3 | command: 'nix-build ./nix -A iohkNix.hydraEvalErrors && ./result/bin/hydra-eval-errors.py' 4 | agents: 5 | system: x86_64-linux 6 | 7 | - label: 'stack rebuild' 8 | env: 9 | STACK_ROOT: "/build/cardano-ledger.stack" 10 | command: 11 | - "rm -rf /build/cardano-ledger" 12 | - "cp -R . /build/cardano-ledger" 13 | - "cd /build/cardano-ledger" 14 | - "nix-build scripts/buildkite -o stack-rebuild" 15 | - "./stack-rebuild" 16 | agents: 17 | system: x86_64-linux 18 | 19 | - label: 'stack-cabal-sync' 20 | command: 'nix-shell ./nix -A iohkNix.stack-cabal-sync-shell --run scripts/buildkite/stack-cabal-sync.sh' 21 | agents: 22 | system: x86_64-linux 23 | 24 | - label: 'check-cabal-project' 25 | command: 'nix-build ./nix -A iohkNix.checkCabalProject -o check-cabal-project.sh && ./check-cabal-project.sh' 26 | agents: 27 | system: x86_64-linux 28 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # GitHub Linguist annotations. 2 | # Hide nix/.stack.nix/*.nix 3 | # That is stuff that is generated by nix-tools stack-to-nix 4 | 5 | nix/.stack.nix/*.nix linguist-generated=true 6 | .stack-to-nix.cache linguist-generated=true 7 | nix/.stack-pkgs.nix linguist-generated=true 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Please add some context to your issue and try to make a plan with a Next Action 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Background 11 | 12 | 13 | ## Proposed Solution 14 | 15 | 16 | 17 | 18 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | labels: inbox 3 | --- 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Cabal & Stack 2 | .stack-work*/ 3 | **/dist 4 | cabal.project.local 5 | dist-newstyle 6 | .ghc.environment.* 7 | stack.yaml.lock 8 | stack-local.yaml.lock 9 | 10 | # Editors 11 | TAGS 12 | *~ 13 | \#* 14 | \.#* 15 | 16 | # Vim swap files 17 | *.sw[a-p] 18 | 19 | # Emacs auto-generated Emacs-lisp code 20 | auto/ 21 | 22 | # Nix artifacts 23 | specs/**/result 24 | result 25 | .stack-to-nix.cache 26 | 27 | # Profiler, profiteur, and profiterole artifacts 28 | *.aux 29 | *.folded 30 | *.prof 31 | *.hp 32 | *.ps 33 | *.html 34 | !iohk-monitoring/static/*.html 35 | *.profiterole.* 36 | 37 | # gitinfo2 auxiliary file 38 | gitHeadLocal.gin 39 | 40 | # Local development 41 | stack-local.yaml 42 | 43 | # Mac 44 | .DS_Store 45 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Code owners are automatically assigned to review PRs 2 | 3 | # The goal is to not have more than 2 people responsible to avoid having too 4 | # many reviewers which often leads to nobody feeling responsible to actually 5 | # perform the review. 6 | 7 | crypto/ @dnadales 8 | nix/ @nc6 9 | scripts/ @nc6 10 | src/ @dnadales 11 | test/ @dnadales 12 | -------------------------------------------------------------------------------- /bors.toml: -------------------------------------------------------------------------------- 1 | status = [ 2 | 3 | # Buildkite: stack build 4 | "buildkite/cardano-ledger", 5 | # Hydra: build for required jobset 6 | "ci/hydra:Cardano:cardano-ledger:required", 7 | ] 8 | timeout_sec = 10800 9 | required_approvals = 1 10 | delete_merged_branches = true 11 | block_labels = [ "DO NOT MERGE", "wip" ] 12 | -------------------------------------------------------------------------------- /cardano-ledger/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 IOHK 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to 8 | do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /cardano-ledger/README.md: -------------------------------------------------------------------------------- 1 | # cardano-ledger 2 | 3 | This package contains the validation rules for the Cardano Ledger. The rules 4 | define state transition systems that describe how to validate new blocks and 5 | transaction, and how to extend the ledger. They are an implementation of the 6 | formal specification defined in 7 | [`cardano-ledger-specs`](https://github.com/input-output-hk/cardano-ledger-specs). 8 | -------------------------------------------------------------------------------- /cardano-ledger/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Block.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Block 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Block.Block as X 7 | import Cardano.Chain.Block.Body as X 8 | import Cardano.Chain.Block.Boundary as X 9 | import Cardano.Chain.Block.Header as X 10 | import Cardano.Chain.Block.Proof as X 11 | import Cardano.Chain.Block.Validation as X 12 | import Cardano.Chain.Block.ValidationMode as X 13 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Block/Body.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveFunctor #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE FlexibleContexts #-} 5 | {-# LANGUAGE FlexibleInstances #-} 6 | {-# LANGUAGE OverloadedStrings #-} 7 | {-# LANGUAGE PatternSynonyms #-} 8 | {-# LANGUAGE TypeApplications #-} 9 | 10 | module Cardano.Chain.Block.Body 11 | ( Body 12 | , pattern Body 13 | , ABody(..) 14 | , bodyTxs 15 | , bodyWitnesses 16 | ) 17 | where 18 | 19 | import Cardano.Prelude 20 | 21 | import Data.Aeson (ToJSON) 22 | 23 | import Cardano.Binary 24 | (ByteSpan, FromCBOR(..), ToCBOR(..), encodeListLen, enforceSize) 25 | import qualified Cardano.Chain.Delegation.Payload as Delegation 26 | import Cardano.Chain.Ssc (SscPayload(..)) 27 | import Cardano.Chain.UTxO.Tx (Tx) 28 | import Cardano.Chain.UTxO.TxPayload (ATxPayload, TxPayload, txpTxs, txpWitnesses) 29 | import Cardano.Chain.UTxO.TxWitness (TxWitness) 30 | import qualified Cardano.Chain.Update.Payload as Update 31 | 32 | -- | 'Body' consists of payloads of all block components 33 | type Body = ABody () 34 | 35 | -- | Constructor for 'Body' 36 | pattern Body :: TxPayload -> SscPayload -> Delegation.Payload -> Update.Payload -> Body 37 | pattern Body tx ssc dlg upd = ABody tx ssc dlg upd 38 | 39 | -- | 'Body' consists of payloads of all block components 40 | data ABody a = ABody 41 | { bodyTxPayload :: !(ATxPayload a) 42 | -- ^ UTxO payload 43 | , bodySscPayload :: !SscPayload 44 | -- ^ Ssc payload 45 | , bodyDlgPayload :: !(Delegation.APayload a) 46 | -- ^ Heavyweight delegation payload (no-ttl certificates) 47 | , bodyUpdatePayload :: !(Update.APayload a) 48 | -- ^ Additional update information for the update system 49 | } deriving (Eq, Show, Generic, Functor, NFData) 50 | 51 | -- Used for debugging purposes only 52 | instance ToJSON a => ToJSON (ABody a) where 53 | 54 | instance ToCBOR Body where 55 | toCBOR bc = 56 | encodeListLen 4 57 | <> toCBOR (bodyTxPayload bc) 58 | <> toCBOR (bodySscPayload bc) 59 | <> toCBOR (bodyDlgPayload bc) 60 | <> toCBOR (bodyUpdatePayload bc) 61 | 62 | instance FromCBOR Body where 63 | fromCBOR = void <$> fromCBOR @(ABody ByteSpan) 64 | 65 | instance FromCBOR (ABody ByteSpan) where 66 | fromCBOR = do 67 | enforceSize "Body" 4 68 | ABody 69 | <$> fromCBOR 70 | <*> fromCBOR 71 | <*> fromCBOR 72 | <*> fromCBOR 73 | 74 | bodyTxs :: Body -> [Tx] 75 | bodyTxs = txpTxs . bodyTxPayload 76 | 77 | bodyWitnesses :: Body -> [TxWitness] 78 | bodyWitnesses = txpWitnesses . bodyTxPayload 79 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Block/ValidationMode.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | 3 | module Cardano.Chain.Block.ValidationMode 4 | ( BlockValidationMode (..) 5 | , toTxValidationMode 6 | ) where 7 | 8 | import Cardano.Prelude 9 | 10 | import Cardano.Chain.UTxO.ValidationMode (TxValidationMode (..)) 11 | 12 | -------------------------------------------------------------------------------- 13 | -- BlockValidationMode 14 | -------------------------------------------------------------------------------- 15 | 16 | -- | Indicates what sort of block validation should be performed. 17 | data BlockValidationMode 18 | = BlockValidation 19 | -- ^ Perform all block validations. 20 | | NoBlockValidation 21 | -- ^ Perform no block validations. 22 | deriving (Eq, Show) 23 | 24 | -- | Translate a 'BlockValidationMode' to an appropriate 'TxValidationMode'. 25 | toTxValidationMode :: BlockValidationMode -> TxValidationMode 26 | toTxValidationMode BlockValidation = TxValidation 27 | toTxValidationMode NoBlockValidation = NoTxValidation 28 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Byron/API.hs: -------------------------------------------------------------------------------- 1 | -- | Auxiliary definitions to make working with the Byron ledger easier 2 | module Cardano.Chain.Byron.API ( 3 | -- * Extract info from chain state 4 | getDelegationMap 5 | , getMaxBlockSize 6 | -- * Applying blocks 7 | , module Cardano.Chain.Byron.API.Validation 8 | -- * Applying transactions 9 | , module Cardano.Chain.Byron.API.Mempool 10 | -- * Protocol 11 | , module Cardano.Chain.Byron.API.Protocol 12 | -- * Annotations 13 | , reAnnotateBlock 14 | , reAnnotateBoundary 15 | , reAnnotateUsing 16 | -- * Headers 17 | , abobMatchesBody 18 | ) where 19 | 20 | import Cardano.Chain.Byron.API.Common 21 | import Cardano.Chain.Byron.API.Mempool 22 | import Cardano.Chain.Byron.API.Protocol 23 | import Cardano.Chain.Byron.API.Validation 24 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Byron/API/Protocol.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Byron.API.Protocol ( 2 | previewDelegationMap 3 | ) where 4 | 5 | import Cardano.Prelude 6 | 7 | import qualified Cardano.Chain.Block as CC 8 | import qualified Cardano.Chain.Delegation as Delegation 9 | import qualified Cardano.Chain.Delegation.Validation.Interface as D.Iface 10 | import qualified Cardano.Chain.Slotting as CC 11 | 12 | -- | Preview the delegation map at a slot assuming no new delegations are 13 | -- | scheduled. 14 | previewDelegationMap :: CC.SlotNumber 15 | -> CC.ChainValidationState 16 | -> Delegation.Map 17 | previewDelegationMap slot cvs = 18 | let ds = D.Iface.activateDelegations slot $ CC.cvsDelegationState cvs 19 | in D.Iface.delegationMap ds 20 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Common 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Common.AddrAttributes as X 7 | import Cardano.Chain.Common.Address as X 8 | import Cardano.Chain.Common.AddressHash as X 9 | import Cardano.Chain.Common.AddrSpendingData as X 10 | import Cardano.Chain.Common.Attributes as X 11 | import Cardano.Chain.Common.BlockCount as X 12 | import Cardano.Chain.Common.CBOR as X 13 | import Cardano.Chain.Common.ChainDifficulty as X 14 | import Cardano.Chain.Common.Compact as X 15 | import Cardano.Chain.Common.Lovelace as X 16 | import Cardano.Chain.Common.LovelacePortion as X 17 | import Cardano.Chain.Common.Merkle as X 18 | import Cardano.Chain.Common.NetworkMagic as X 19 | import Cardano.Chain.Common.KeyHash as X 20 | import Cardano.Chain.Common.TxFeePolicy as X 21 | import Cardano.Chain.Common.TxSizeLinear as X 22 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/AddressHash.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Common.AddressHash 2 | ( AddressHash 3 | , addressHash 4 | , unsafeAddressHash 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Crypto.Hash (Blake2b_224, Digest, SHA3_256) 11 | import qualified Crypto.Hash as CryptoHash 12 | 13 | import Cardano.Binary (ToCBOR, serialize) 14 | import Cardano.Crypto.Hashing (AbstractHash, abstractHashFromDigest) 15 | 16 | -- | Hash used to identify address. 17 | type AddressHash = AbstractHash Blake2b_224 18 | 19 | unsafeAddressHash :: ToCBOR a => a -> AddressHash b 20 | unsafeAddressHash = abstractHashFromDigest . secondHash . firstHash 21 | where 22 | firstHash :: ToCBOR a => a -> Digest SHA3_256 23 | firstHash = CryptoHash.hashlazy . serialize 24 | secondHash :: Digest SHA3_256 -> Digest Blake2b_224 25 | secondHash = CryptoHash.hash 26 | 27 | addressHash :: ToCBOR a => a -> AddressHash a 28 | addressHash = unsafeAddressHash 29 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/BlockCount.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE TemplateHaskell #-} 4 | 5 | module Cardano.Chain.Common.BlockCount 6 | ( BlockCount(..) 7 | ) 8 | where 9 | 10 | import Cardano.Prelude 11 | 12 | import Formatting.Buildable (Buildable) 13 | 14 | import Cardano.Binary (FromCBOR(..), ToCBOR(..)) 15 | 16 | 17 | newtype BlockCount = BlockCount 18 | { unBlockCount :: Word64 19 | } deriving (Eq, Ord, Enum, Read, Show, Buildable, Generic, NFData, NoUnexpectedThunks) 20 | 21 | instance ToCBOR BlockCount where 22 | toCBOR = toCBOR . unBlockCount 23 | encodedSizeExpr size pxy = size (unBlockCount <$> pxy) 24 | 25 | instance FromCBOR BlockCount where 26 | fromCBOR = BlockCount <$> fromCBOR 27 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/ChainDifficulty.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE OverloadedStrings #-} 4 | {-# LANGUAGE TemplateHaskell #-} 5 | 6 | module Cardano.Chain.Common.ChainDifficulty 7 | ( ChainDifficulty(..) 8 | , dropChainDifficulty 9 | ) 10 | where 11 | 12 | import Cardano.Prelude 13 | 14 | import Data.Aeson (ToJSON) 15 | import Formatting.Buildable (Buildable) 16 | 17 | import Cardano.Binary 18 | (Dropper, FromCBOR(..), ToCBOR(..), dropWord64, encodeListLen, enforceSize) 19 | 20 | 21 | -- | Chain difficulty represents necessary effort to generate a 22 | -- chain. In the simplest case it can be number of blocks in chain. 23 | newtype ChainDifficulty = ChainDifficulty 24 | { unChainDifficulty :: Word64 25 | } deriving (Show, Eq, Ord, Enum, Generic, Buildable, NFData, NoUnexpectedThunks) 26 | 27 | -- Used for debugging purposes only 28 | instance ToJSON ChainDifficulty where 29 | 30 | instance ToCBOR ChainDifficulty where 31 | toCBOR cd = encodeListLen 1 <> toCBOR (unChainDifficulty cd) 32 | 33 | encodedSizeExpr f cd = 1 + encodedSizeExpr f (unChainDifficulty <$> cd) 34 | 35 | instance FromCBOR ChainDifficulty where 36 | fromCBOR = do 37 | enforceSize "ChainDifficulty" 1 38 | ChainDifficulty <$> fromCBOR 39 | 40 | dropChainDifficulty :: Dropper s 41 | dropChainDifficulty = do 42 | enforceSize "ChainDifficulty" 1 43 | dropWord64 44 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/Compact.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE DerivingVia #-} 5 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 6 | {-# LANGUAGE OverloadedStrings #-} 7 | 8 | module Cardano.Chain.Common.Compact 9 | ( CompactAddress 10 | , toCompactAddress 11 | , fromCompactAddress 12 | ) 13 | where 14 | 15 | import Cardano.Prelude 16 | 17 | import Cardano.Binary (FromCBOR(..), ToCBOR(..), serialize', decodeFull') 18 | import qualified Data.ByteString.Short as BSS (fromShort, toShort) 19 | import Data.ByteString.Short (ShortByteString) 20 | 21 | import Cardano.Chain.Common.Address (Address(..)) 22 | 23 | -------------------------------------------------------------------------------- 24 | -- Compact Address 25 | -------------------------------------------------------------------------------- 26 | 27 | -- | A compact in-memory representation for an 'Address'. 28 | -- 29 | -- Convert using 'toCompactAddress' and 'fromCompactAddress'. 30 | -- 31 | newtype CompactAddress = CompactAddress ShortByteString 32 | deriving (Eq, Ord, Generic, Show) 33 | deriving newtype HeapWords 34 | deriving anyclass NFData 35 | deriving NoUnexpectedThunks via UseIsNormalForm ShortByteString 36 | 37 | instance FromCBOR CompactAddress where 38 | fromCBOR = CompactAddress . BSS.toShort <$> fromCBOR 39 | 40 | instance ToCBOR CompactAddress where 41 | toCBOR (CompactAddress sbs) = toCBOR (BSS.fromShort sbs) 42 | 43 | toCompactAddress :: Address -> CompactAddress 44 | toCompactAddress addr = 45 | CompactAddress (BSS.toShort (serialize' addr)) 46 | 47 | fromCompactAddress :: CompactAddress -> Address 48 | fromCompactAddress (CompactAddress addr) = 49 | case decodeFull' (BSS.fromShort addr) of 50 | Left err -> panic ("fromCompactAddress: impossible: " <> show err) 51 | Right decAddr -> decAddr 52 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/KeyHash.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE MultiParamTypeClasses #-} 5 | {-# LANGUAGE TypeSynonymInstances #-} 6 | {-# LANGUAGE UndecidableInstances #-} 7 | 8 | module Cardano.Chain.Common.KeyHash 9 | ( KeyHash (..) 10 | , hashKey 11 | ) 12 | where 13 | 14 | import Cardano.Prelude 15 | 16 | import Control.Monad.Except (MonadError) 17 | import Formatting (formatToString) 18 | import Formatting.Buildable (Buildable) 19 | import Text.JSON.Canonical 20 | (FromObjectKey(..), JSValue(..), ToObjectKey(..), toJSString) 21 | 22 | import Cardano.Binary (FromCBOR, ToCBOR) 23 | import Cardano.Chain.Common.AddressHash 24 | import Cardano.Crypto (decodeAbstractHash, hashHexF) 25 | import Cardano.Crypto.Signing (VerificationKey) 26 | 27 | 28 | -- | A 'KeyHash' refers to a 'VerificationKey' 29 | newtype KeyHash = KeyHash 30 | { unKeyHash :: AddressHash VerificationKey 31 | } deriving ( Eq 32 | , Ord 33 | , Show 34 | , NFData 35 | , Buildable 36 | , FromCBOR 37 | , ToCBOR 38 | , HeapWords 39 | , NoUnexpectedThunks 40 | ) 41 | 42 | instance Monad m => ToObjectKey m KeyHash where 43 | toObjectKey = pure . toJSString . formatToString hashHexF . unKeyHash 44 | 45 | instance MonadError SchemaError m => FromObjectKey m KeyHash where 46 | fromObjectKey = fmap (Just . KeyHash) 47 | . parseJSString decodeAbstractHash 48 | . JSString 49 | 50 | hashKey :: VerificationKey -> KeyHash 51 | hashKey = KeyHash . addressHash 52 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/NetworkMagic.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE LambdaCase #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | {-# LANGUAGE TypeApplications #-} 6 | 7 | module Cardano.Chain.Common.NetworkMagic 8 | ( NetworkMagic (..) 9 | , makeNetworkMagic 10 | ) where 11 | 12 | import Cardano.Prelude hiding ((%)) 13 | 14 | import Data.Aeson (ToJSON) 15 | import Formatting (bprint, build, (%)) 16 | import qualified Formatting.Buildable as B 17 | 18 | import Cardano.Binary (DecoderError(..), FromCBOR(..), ToCBOR(..), 19 | decodeListLen, decodeWord8, encodeListLen , matchSize) 20 | import Cardano.Crypto.ProtocolMagic (AProtocolMagic (..), 21 | RequiresNetworkMagic (..), getProtocolMagic) 22 | 23 | 24 | -------------------------------------------------------------------------------- 25 | -- NetworkMagic 26 | -------------------------------------------------------------------------------- 27 | 28 | data NetworkMagic 29 | = NetworkMainOrStage 30 | | NetworkTestnet {-# UNPACK #-} !Word32 31 | deriving (Show, Eq, Ord, Generic, NFData, NoUnexpectedThunks) 32 | 33 | instance B.Buildable NetworkMagic where 34 | build NetworkMainOrStage = "NetworkMainOrStage" 35 | build (NetworkTestnet n) = bprint ("NetworkTestnet ("%build%")") n 36 | 37 | -- Used for debugging purposes only 38 | instance ToJSON NetworkMagic where 39 | 40 | instance HeapWords NetworkMagic where 41 | heapWords NetworkMainOrStage = 0 42 | heapWords (NetworkTestnet _) = 2 43 | 44 | instance ToCBOR NetworkMagic where 45 | toCBOR = \case 46 | NetworkMainOrStage -> 47 | encodeListLen 1 <> toCBOR @Word8 0 48 | NetworkTestnet n -> 49 | encodeListLen 2 <> toCBOR @Word8 1 <> toCBOR n 50 | 51 | instance FromCBOR NetworkMagic where 52 | fromCBOR = do 53 | len <- decodeListLen 54 | tag <- decodeWord8 55 | case tag of 56 | 0 -> matchSize "NetworkMagic" 1 len $> NetworkMainOrStage 57 | 1 -> matchSize "NetworkMagic" 2 len >> NetworkTestnet <$> fromCBOR 58 | _ -> cborError $ DecoderErrorUnknownTag "NetworkMagic" tag 59 | 60 | makeNetworkMagic :: AProtocolMagic a -> NetworkMagic 61 | makeNetworkMagic pm = case getRequiresNetworkMagic pm of 62 | RequiresNoMagic -> NetworkMainOrStage 63 | RequiresMagic -> NetworkTestnet (getProtocolMagic pm) 64 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Common/TxSizeLinear.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE BangPatterns #-} 2 | {-# LANGUAGE DeriveAnyClass #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE DerivingStrategies #-} 5 | {-# LANGUAGE OverloadedStrings #-} 6 | {-# LANGUAGE TypeApplications #-} 7 | 8 | module Cardano.Chain.Common.TxSizeLinear 9 | ( TxSizeLinear(..) 10 | , txSizeLinearMinValue 11 | , calculateTxSizeLinear 12 | ) 13 | where 14 | 15 | import Cardano.Prelude 16 | 17 | import Data.Aeson (ToJSON) 18 | import Data.Fixed (Nano) 19 | import Formatting (bprint, build, sformat) 20 | import qualified Formatting.Buildable as B 21 | 22 | import Cardano.Binary 23 | ( Decoder 24 | , DecoderError(..) 25 | , FromCBOR(..) 26 | , ToCBOR(..) 27 | , encodeListLen 28 | , enforceSize 29 | ) 30 | import Cardano.Chain.Common.Lovelace 31 | ( Lovelace 32 | , LovelaceError 33 | , addLovelace 34 | , integerToLovelace 35 | , mkLovelace 36 | , scaleLovelaceRationalUp 37 | , unsafeGetLovelace 38 | ) 39 | 40 | -- | A linear equation on the transaction size. Represents the @\s -> a + b*s@ 41 | -- function where @s@ is the transaction size in bytes, @a@ and @b@ are 42 | -- constant coefficients. 43 | data TxSizeLinear = 44 | TxSizeLinear !Lovelace !Rational 45 | deriving (Eq, Ord, Show, Generic) 46 | deriving anyclass (NFData, NoUnexpectedThunks) 47 | 48 | instance B.Buildable TxSizeLinear where 49 | build (TxSizeLinear a b) = bprint (build . " + " . build . "*s") a b 50 | 51 | -- Used for debugging purposes only 52 | instance ToJSON TxSizeLinear where 53 | 54 | instance ToCBOR TxSizeLinear where 55 | -- We encode as 'Nano' for backwards compatibility 56 | toCBOR (TxSizeLinear a b) = 57 | encodeListLen 2 58 | <> toCBOR (fromIntegral (unsafeGetLovelace a) :: Nano) 59 | <> toCBOR (fromRational b :: Nano) 60 | 61 | instance FromCBOR TxSizeLinear where 62 | fromCBOR = do 63 | enforceSize "TxSizeLinear" 2 64 | !a <- wrapLovelaceError . mkLovelace . round =<< fromCBOR @Nano 65 | !b <- toRational <$> fromCBOR @Nano 66 | return $ TxSizeLinear a b 67 | where 68 | wrapLovelaceError :: Either LovelaceError Lovelace -> Decoder s Lovelace 69 | wrapLovelaceError = 70 | toCborError . first (DecoderErrorCustom "TxSizeLinear" . sformat build) 71 | 72 | calculateTxSizeLinear 73 | :: TxSizeLinear -> Natural -> Either LovelaceError Lovelace 74 | calculateTxSizeLinear (TxSizeLinear a b) sz 75 | = addLovelace a 76 | =<< flip scaleLovelaceRationalUp b 77 | <$> integerToLovelace (fromIntegral sz) 78 | 79 | txSizeLinearMinValue :: TxSizeLinear -> Lovelace 80 | txSizeLinearMinValue (TxSizeLinear a _) = a 81 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Constants.hs: -------------------------------------------------------------------------------- 1 | -- | Non-configurable constants 2 | -- For configurable constants, see Cardano.Genesis.Configuration. 3 | 4 | module Cardano.Chain.Constants 5 | ( sharedSeedLength 6 | ) 7 | where 8 | 9 | import Cardano.Prelude 10 | 11 | -------------------------------------------------------------------------------- 12 | -- Constants which are not configurable 13 | -------------------------------------------------------------------------------- 14 | 15 | -- | Length of shared seed. 16 | sharedSeedLength :: Integral a => a 17 | sharedSeedLength = 32 18 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Delegation.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Delegation 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Delegation.Certificate as X 7 | import Cardano.Chain.Delegation.Map as X 8 | import Cardano.Chain.Delegation.Payload as X 9 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Delegation/Map.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | 5 | module Cardano.Chain.Delegation.Map 6 | ( Map(..) 7 | 8 | -- * Query 9 | , memberR 10 | , notMemberR 11 | , pairMember 12 | , lookupR 13 | 14 | -- * Update 15 | , insert 16 | 17 | -- * Conversion/traversal 18 | , fromList 19 | , keysSet 20 | ) 21 | where 22 | 23 | import Cardano.Prelude hiding (Map) 24 | 25 | import Data.Bimap (Bimap) 26 | import qualified Data.Bimap as Bimap 27 | import qualified Data.Set as Set 28 | 29 | import Cardano.Binary (FromCBOR(..), ToCBOR(..)) 30 | import Cardano.Chain.Common.KeyHash (KeyHash) 31 | 32 | 33 | newtype Map = Map 34 | { unMap :: Bimap KeyHash KeyHash 35 | } deriving (Eq, Show, Generic) 36 | deriving anyclass NFData 37 | 38 | instance FromCBOR Map where 39 | fromCBOR = Map . Bimap.fromList <$> fromCBOR 40 | 41 | instance ToCBOR Map where 42 | toCBOR = toCBOR . Bimap.toList . unMap 43 | 44 | -- | A 'Bimap' contains two regular 'Map's, which are spine strict; we therefore 45 | -- have to worry about the elements only 46 | instance NoUnexpectedThunks Map where 47 | whnfNoUnexpectedThunks ctxt = noUnexpectedThunksInKeysAndValues ctxt 48 | . Bimap.toList 49 | . unMap 50 | 51 | -------------------------------------------------------------------------------- 52 | -- Query 53 | -------------------------------------------------------------------------------- 54 | 55 | memberR :: KeyHash -> Map -> Bool 56 | memberR b = Bimap.memberR b . unMap 57 | 58 | -- TODO: maybe we should call these @delegate@ and @notADelegate@ (and add also a @delegator@) function. 59 | 60 | notMemberR :: KeyHash -> Map -> Bool 61 | notMemberR b = Bimap.notMemberR b . unMap 62 | 63 | pairMember :: (KeyHash, KeyHash) -> Map -> Bool 64 | pairMember p = Bimap.pairMember p . unMap 65 | 66 | lookupR :: KeyHash -> Map -> Maybe KeyHash 67 | lookupR b = Bimap.lookupR b . unMap 68 | 69 | 70 | -------------------------------------------------------------------------------- 71 | -- Update 72 | -------------------------------------------------------------------------------- 73 | 74 | insert :: KeyHash -> KeyHash -> Map -> Map 75 | insert a b = Map . Bimap.insert a b . unMap 76 | 77 | 78 | -------------------------------------------------------------------------------- 79 | -- Conversion/traversal 80 | -------------------------------------------------------------------------------- 81 | 82 | fromList :: [(KeyHash, KeyHash)] -> Map 83 | fromList = Map . Bimap.fromList 84 | 85 | keysSet :: Map -> Set KeyHash 86 | keysSet = Set.fromList . Bimap.keys . unMap 87 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Delegation/Payload.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveFunctor #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE DerivingStrategies #-} 5 | {-# LANGUAGE FlexibleContexts #-} 6 | {-# LANGUAGE FlexibleInstances #-} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | {-# LANGUAGE TypeApplications #-} 9 | {-# LANGUAGE TypeFamilies #-} 10 | 11 | module Cardano.Chain.Delegation.Payload 12 | ( APayload(..) 13 | , Payload 14 | , unsafePayload 15 | ) 16 | where 17 | 18 | import Cardano.Prelude 19 | 20 | import Data.Aeson (ToJSON) 21 | import Formatting (bprint, int) 22 | import Formatting.Buildable (Buildable(..)) 23 | 24 | import Cardano.Binary 25 | ( Annotated(..) 26 | , ByteSpan 27 | , Decoded(..) 28 | , FromCBOR(..) 29 | , ToCBOR(..) 30 | , annotatedDecoder 31 | ) 32 | import qualified Cardano.Chain.Delegation.Certificate as Delegation 33 | 34 | 35 | -- | The delegation 'Payload' contains a list of delegation 'Certificate's 36 | data APayload a = UnsafeAPayload 37 | { getPayload :: [Delegation.ACertificate a] 38 | , getAnnotation :: a 39 | } deriving (Show, Eq, Generic, Functor) 40 | deriving anyclass NFData 41 | 42 | type Payload = APayload () 43 | 44 | unsafePayload :: [Delegation.Certificate] -> Payload 45 | unsafePayload sks = UnsafeAPayload sks () 46 | 47 | instance Decoded (APayload ByteString) where 48 | type BaseType (APayload ByteString) = Payload 49 | recoverBytes = getAnnotation 50 | 51 | instance Buildable (APayload a) where 52 | build (UnsafeAPayload psks _) = bprint 53 | ("proxy signing keys (" . int . " items): " . listJson . "\n") 54 | (length psks) 55 | psks 56 | 57 | -- Used for debugging purposes only 58 | instance ToJSON a => ToJSON (APayload a) where 59 | 60 | instance ToCBOR Payload where 61 | toCBOR = toCBOR . getPayload 62 | 63 | instance FromCBOR Payload where 64 | fromCBOR = void <$> fromCBOR @(APayload ByteSpan) 65 | 66 | instance FromCBOR (APayload ByteSpan) where 67 | fromCBOR = do 68 | (Annotated p a) <- annotatedDecoder fromCBOR 69 | pure (UnsafeAPayload p a) 70 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Delegation/Validation/Activation.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE NamedFieldPuns #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | 6 | module Cardano.Chain.Delegation.Validation.Activation 7 | ( 8 | -- * Activation 9 | State(..) 10 | , activateDelegation 11 | ) 12 | where 13 | 14 | import Cardano.Prelude hiding (State) 15 | 16 | import qualified Data.Map.Strict as M 17 | 18 | import Cardano.Binary (FromCBOR(..), ToCBOR(..), encodeListLen, enforceSize) 19 | import Cardano.Chain.Common (KeyHash) 20 | import qualified Cardano.Chain.Delegation as Delegation 21 | import Cardano.Chain.Delegation.Validation.Scheduling (ScheduledDelegation(..)) 22 | import Cardano.Chain.Slotting (SlotNumber(..)) 23 | 24 | 25 | -------------------------------------------------------------------------------- 26 | -- Activation 27 | -------------------------------------------------------------------------------- 28 | 29 | -- | Maps containing, for each delegator, the active delegation and the slot it 30 | -- became active in. 31 | data State = State 32 | { delegationMap :: !Delegation.Map 33 | , delegationSlots :: !(Map KeyHash SlotNumber) 34 | } deriving (Eq, Show, Generic, NFData, NoUnexpectedThunks) 35 | 36 | instance FromCBOR State where 37 | fromCBOR = do 38 | enforceSize "State" 2 39 | State 40 | <$> fromCBOR 41 | <*> fromCBOR 42 | 43 | instance ToCBOR State where 44 | toCBOR s = 45 | encodeListLen 2 46 | <> toCBOR (delegationMap s) 47 | <> toCBOR (delegationSlots s) 48 | 49 | -- | Activate a 'ScheduledDelegation' if its activation slot is less than the 50 | -- previous delegation slot for this delegate, otherwise discard it. This is 51 | -- an implementation of the delegation activation rule in the ledger 52 | -- specification. 53 | activateDelegation :: State -> ScheduledDelegation -> State 54 | activateDelegation as delegation 55 | | (delegate `Delegation.notMemberR` delegationMap) 56 | && (prevDelegationSlot < slot || unSlotNumber slot == 0) 57 | = State 58 | { delegationMap = Delegation.insert delegator delegate delegationMap 59 | , delegationSlots = M.insert delegator slot delegationSlots 60 | } 61 | | otherwise = as 62 | where 63 | State { delegationMap, delegationSlots } = as 64 | ScheduledDelegation slot delegator delegate = delegation 65 | 66 | prevDelegationSlot = 67 | fromMaybe (SlotNumber 0) $ M.lookup delegator delegationSlots 68 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Genesis 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Genesis.AvvmBalances as X 7 | import Cardano.Chain.Genesis.Config as X 8 | import Cardano.Chain.Genesis.Data as X 9 | import Cardano.Chain.Genesis.Delegation as X 10 | import Cardano.Chain.Genesis.Generate as X 11 | import Cardano.Chain.Genesis.Hash as X 12 | import Cardano.Chain.Genesis.Initializer as X 13 | import Cardano.Chain.Genesis.NonAvvmBalances as X 14 | import Cardano.Chain.Genesis.Spec as X 15 | import Cardano.Chain.Genesis.KeyHashes as X 16 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis/AvvmBalances.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE MultiParamTypeClasses #-} 5 | {-# LANGUAGE StandaloneDeriving #-} 6 | {-# LANGUAGE UndecidableInstances #-} 7 | 8 | module Cardano.Chain.Genesis.AvvmBalances 9 | ( GenesisAvvmBalances(..) 10 | ) 11 | where 12 | 13 | import Cardano.Prelude 14 | 15 | import Text.JSON.Canonical (FromJSON(..), ToJSON(..)) 16 | 17 | import Cardano.Chain.Common (Lovelace) 18 | import Cardano.Crypto.Signing.Redeem (CompactRedeemVerificationKey) 19 | 20 | 21 | -- | Predefined balances of AVVM (Ada Voucher Vending Machine) entries. 22 | -- People who purchased Ada at a pre-sale were issued a certificate during 23 | -- the pre-sale period. These certificates allow customers to redeem ADA. 24 | newtype GenesisAvvmBalances = GenesisAvvmBalances 25 | { unGenesisAvvmBalances :: Map CompactRedeemVerificationKey Lovelace 26 | } deriving (Show, Eq, Semigroup, NoUnexpectedThunks) 27 | 28 | instance Monad m => ToJSON m GenesisAvvmBalances where 29 | toJSON = toJSON . unGenesisAvvmBalances 30 | 31 | instance MonadError SchemaError m => FromJSON m GenesisAvvmBalances where 32 | -- | Unfortunately, because @canonical-json@ doesn't utilize operations from 33 | -- "Data.Map.Strict" but only those from "Data.Map.Lazy" (i.e. 'fromJSON' 34 | -- will return a 'Map' that is not necessarily strict in its values), we 35 | -- need to be careful in order to ensure that we're still dealing with a 36 | -- 'Map' that's strict in both its keys and values. 37 | -- 38 | -- To remedy this, we use 'forceElemsToWHNF' from "Cardano.Prelude" to 39 | -- convert the 'Map' to one that is now guaranteed to be strict in both 40 | -- its keys and values. 41 | -- 42 | -- n.b. both the strict and lazy 'Map' modules utilize the same 'Map' data 43 | -- type which is what makes something like this possible. 44 | fromJSON = fmap (GenesisAvvmBalances . forceElemsToWHNF) . fromJSON 45 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis/Hash.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE DerivingStrategies #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE Rank2Types #-} 5 | {-# LANGUAGE StandaloneDeriving #-} 6 | 7 | module Cardano.Chain.Genesis.Hash 8 | ( GenesisHash(..) 9 | ) 10 | where 11 | 12 | import Control.DeepSeq (NFData) 13 | import Data.Aeson (ToJSON) 14 | 15 | import Cardano.Prelude 16 | 17 | import Cardano.Binary (Raw, FromCBOR, ToCBOR) 18 | import Cardano.Crypto.Hashing (Hash) 19 | 20 | newtype GenesisHash = GenesisHash 21 | { unGenesisHash :: Hash Raw 22 | } deriving (Eq, Generic, NFData, FromCBOR, ToCBOR, NoUnexpectedThunks) 23 | 24 | deriving instance Show GenesisHash 25 | 26 | -- Used for debugging purposes only 27 | instance ToJSON GenesisHash where 28 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis/Initializer.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module Cardano.Chain.Genesis.Initializer 5 | ( GenesisInitializer(..) 6 | , TestnetBalanceOptions(..) 7 | , FakeAvvmOptions(..) 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import Cardano.Chain.Common (Lovelace) 14 | 15 | -- | Options determining generated genesis stakes, balances, and delegation 16 | data GenesisInitializer = GenesisInitializer 17 | { giTestBalance :: !TestnetBalanceOptions 18 | , giFakeAvvmBalance :: !FakeAvvmOptions 19 | , giAvvmBalanceFactor :: !Rational 20 | -- ^ Avvm balances will be multiplied by this factor 21 | , giUseHeavyDlg :: !Bool 22 | -- ^ Whether to use heavyweight delegation for genesis keys 23 | } deriving (Eq, Show) 24 | 25 | 26 | -- | These options determine balances of nodes specific for testnet 27 | data TestnetBalanceOptions = TestnetBalanceOptions 28 | { tboPoors :: !Word 29 | -- ^ Number of poor nodes (with small balance). 30 | , tboRichmen :: !Word 31 | -- ^ Number of rich nodes (with huge balance). 32 | , tboTotalBalance :: !Lovelace 33 | -- ^ Total balance owned by these nodes. 34 | , tboRichmenShare :: !Rational 35 | -- ^ Portion of stake owned by all richmen together. 36 | } deriving (Eq, Show) 37 | 38 | 39 | -- | These options determines balances of fake AVVM nodes which didn't really go 40 | -- through vending, but pretend they did 41 | data FakeAvvmOptions = FakeAvvmOptions 42 | { faoCount :: !Word 43 | , faoOneBalance :: !Lovelace 44 | } deriving (Eq, Show, Generic) 45 | 46 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis/KeyHashes.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE MultiParamTypeClasses #-} 5 | {-# LANGUAGE OverloadedStrings #-} 6 | {-# LANGUAGE ScopedTypeVariables #-} 7 | {-# LANGUAGE TypeApplications #-} 8 | {-# LANGUAGE UndecidableInstances #-} 9 | 10 | module Cardano.Chain.Genesis.KeyHashes 11 | ( GenesisKeyHashes(..) 12 | ) 13 | where 14 | 15 | import Cardano.Prelude 16 | 17 | import Control.Monad.Except (MonadError) 18 | import qualified Data.Set as Set 19 | import qualified Data.Map.Strict as M 20 | import Formatting (bprint) 21 | import Formatting.Buildable (Buildable(..)) 22 | import Text.JSON.Canonical (FromJSON(..), ToJSON(..)) 23 | 24 | import Cardano.Chain.Common (KeyHash) 25 | 26 | 27 | -- | The set of genesis keys, who are able to produce blocks and submit votes 28 | -- and proposals in the Byron era 29 | newtype GenesisKeyHashes = GenesisKeyHashes 30 | { unGenesisKeyHashes :: Set KeyHash 31 | } deriving (Show, Eq, Semigroup, Monoid, NoUnexpectedThunks) 32 | 33 | instance Buildable GenesisKeyHashes where 34 | build (GenesisKeyHashes m) = 35 | bprint ("GenesisKeyHashes: " . listJson) (Set.toList m) 36 | 37 | instance Monad m => ToJSON m GenesisKeyHashes where 38 | toJSON (GenesisKeyHashes stks) = 39 | toJSON . M.fromList $ zip (Set.toList stks) (repeat (1 :: Word16)) 40 | 41 | instance MonadError SchemaError m => FromJSON m GenesisKeyHashes where 42 | fromJSON = 43 | fmap (GenesisKeyHashes . M.keysSet) . fromJSON @m @(Map KeyHash Word16) 44 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Genesis/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE OverloadedStrings #-} 3 | {-# LANGUAGE TemplateHaskell #-} 4 | 5 | module Cardano.Chain.Genesis.Spec 6 | ( GenesisSpec(..) 7 | , mkGenesisSpec 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import Data.List (nub) 14 | import qualified Data.Map.Strict as M 15 | 16 | import Cardano.Chain.Common (BlockCount) 17 | import Cardano.Crypto (ProtocolMagic) 18 | import Cardano.Chain.Genesis.AvvmBalances (GenesisAvvmBalances(..)) 19 | import Cardano.Chain.Genesis.Delegation (GenesisDelegation(..)) 20 | import Cardano.Chain.Genesis.Initializer (GenesisInitializer(..)) 21 | import Cardano.Chain.Update.ProtocolParameters (ProtocolParameters) 22 | 23 | 24 | -- | Specification how to generate full 'GenesisData' 25 | data GenesisSpec = UnsafeGenesisSpec 26 | { gsAvvmDistr :: !GenesisAvvmBalances 27 | -- ^ Genesis data describes avvm utxo 28 | , gsHeavyDelegation :: !GenesisDelegation 29 | -- ^ Genesis state of heavyweight delegation. Will be concatenated with 30 | -- delegation genesis keyHashes if 'tiUseHeavyDlg' is 'True' 31 | , gsProtocolParameters :: !ProtocolParameters 32 | -- ^ Genesis 'ProtocolParameters' 33 | , gsK :: !BlockCount 34 | -- ^ The security parameter of the Ouroboros protocol 35 | , gsProtocolMagic :: !ProtocolMagic 36 | -- ^ The magic number unique to any instance of Cardano 37 | , gsInitializer :: !GenesisInitializer 38 | -- ^ Other data which depend on genesis type 39 | } deriving (Eq, Show, Generic) 40 | 41 | -- | Safe constructor for 'GenesisSpec'. Throws error if something 42 | -- goes wrong. 43 | mkGenesisSpec 44 | :: GenesisAvvmBalances 45 | -> GenesisDelegation 46 | -> ProtocolParameters 47 | -> BlockCount 48 | -> ProtocolMagic 49 | -> GenesisInitializer 50 | -> Either Text GenesisSpec 51 | mkGenesisSpec avvmDistr delega bvd k pm specType = do 52 | let avvmKeys = M.keys $ unGenesisAvvmBalances avvmDistr 53 | (length (nub avvmKeys) == length avvmKeys) 54 | `orThrowError` "mkGenesisSpec: there are duplicates in avvm balances" 55 | -- All checks passed 56 | pure $ UnsafeGenesisSpec avvmDistr delega bvd k pm specType 57 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/ProtocolConstants.hs: -------------------------------------------------------------------------------- 1 | -- | Constants derived from security parameter 2 | -- 3 | -- TODO: Find a better home for these 4 | 5 | module Cardano.Chain.ProtocolConstants 6 | ( kSlotSecurityParam 7 | , kUpdateStabilityParam 8 | , kChainQualityThreshold 9 | , kEpochSlots 10 | ) 11 | where 12 | 13 | import Cardano.Prelude 14 | 15 | import Cardano.Chain.Common.BlockCount (BlockCount(..)) 16 | import Cardano.Chain.Slotting.EpochSlots (EpochSlots(..)) 17 | import Cardano.Chain.Slotting.SlotCount (SlotCount(..)) 18 | 19 | 20 | -- | Security parameter expressed in number of slots. It uses chain quality 21 | -- property. It's basically @blkSecurityParam / chainQualityThreshold@. 22 | kSlotSecurityParam :: BlockCount -> SlotCount 23 | kSlotSecurityParam = SlotCount . (*) 2 . unBlockCount 24 | 25 | -- | Update stability parameter expressed in number of slots. This is the time 26 | -- between an protocol version update receiving its final endorsement and 27 | -- being accepted, and is set to double the security param. 28 | -- 29 | -- This extra safety margin is required because an update in the protocol 30 | -- version may trigger a hard fork, which can change "era"-level parameters 31 | -- such as slot length and the number of slots per epoch. As such, the 32 | -- consensus layer wishes to always have a margin between such an update being 33 | -- _certain to happen_ and it actually happening. 34 | -- 35 | -- For full details, you can see 36 | -- https://github.com/input-output-hk/cardano-ledger-specs/issues/1288 37 | kUpdateStabilityParam :: BlockCount -> SlotCount 38 | kUpdateStabilityParam = SlotCount . (*) 4 . unBlockCount 39 | 40 | -- | Minimal chain quality (number of blocks divided by number of 41 | -- slots) necessary for security of the system. 42 | kChainQualityThreshold :: Fractional f => BlockCount -> f 43 | kChainQualityThreshold k = realToFrac (unBlockCount k) 44 | / fromIntegral (unSlotCount $ kSlotSecurityParam k) 45 | 46 | -- | Number of slots inside one epoch 47 | kEpochSlots :: BlockCount -> EpochSlots 48 | kEpochSlots = EpochSlots . (*) 10 . unBlockCount 49 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Slotting.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Slotting 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Slotting.EpochAndSlotCount as X 7 | import Cardano.Chain.Slotting.EpochNumber as X 8 | import Cardano.Chain.Slotting.EpochSlots as X 9 | import Cardano.Chain.Slotting.SlotCount as X 10 | import Cardano.Chain.Slotting.SlotNumber as X 11 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Slotting/EpochSlots.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | {-# LANGUAGE StandaloneDeriving #-} 5 | 6 | module Cardano.Chain.Slotting.EpochSlots 7 | ( EpochSlots(..) 8 | , WithEpochSlots (..) 9 | , epochFirstSlot 10 | ) 11 | where 12 | 13 | import Cardano.Prelude 14 | 15 | import Data.Data (Data) 16 | import Formatting.Buildable (Buildable) 17 | 18 | import Cardano.Binary (FromCBOR(..), ToCBOR(..)) 19 | import Cardano.Chain.Slotting.EpochNumber 20 | import Cardano.Chain.Slotting.SlotNumber 21 | 22 | -- | The number of slots per epoch. 23 | newtype EpochSlots = EpochSlots 24 | { unEpochSlots :: Word64 25 | } deriving (Data, Eq, Ord, Read, Show, Buildable, Generic, NoUnexpectedThunks) 26 | 27 | instance ToCBOR EpochSlots where 28 | toCBOR = toCBOR . unEpochSlots 29 | 30 | instance FromCBOR EpochSlots where 31 | fromCBOR = EpochSlots <$> fromCBOR 32 | 33 | -- | Data with an accompanying slots per epoch context. 34 | data WithEpochSlots a = WithEpochSlots 35 | { epochSlots :: EpochSlots 36 | , unWithEpochSlots :: a 37 | } 38 | deriving (Show, Eq) 39 | 40 | -- | Calculate the first slot in an epoch. 41 | -- 42 | -- Note that this function will give an undetermined result if Byron is not the 43 | -- first and only era - a more robust method should use 'EpochInfo' from 44 | -- cardano-slotting. 45 | epochFirstSlot :: EpochSlots -> EpochNumber -> SlotNumber 46 | epochFirstSlot (EpochSlots n) (EpochNumber k) = SlotNumber $ n * k 47 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Slotting/SlotCount.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 5 | 6 | module Cardano.Chain.Slotting.SlotCount 7 | ( SlotCount(..) 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import Formatting.Buildable (Buildable) 14 | 15 | import Cardano.Binary (FromCBOR, ToCBOR) 16 | 17 | 18 | -- | A number of slots 19 | newtype SlotCount = SlotCount 20 | { unSlotCount :: Word64 21 | } deriving stock (Read, Show, Generic) 22 | deriving newtype (Eq, Ord, Buildable, ToCBOR, FromCBOR) 23 | deriving anyclass (NFData) 24 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Slotting/SlotNumber.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE FlexibleContexts #-} 5 | {-# LANGUAGE FlexibleInstances #-} 6 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 7 | {-# LANGUAGE MultiParamTypeClasses #-} 8 | {-# LANGUAGE UndecidableInstances #-} 9 | 10 | module Cardano.Chain.Slotting.SlotNumber 11 | ( SlotNumber(..) 12 | , addSlotCount 13 | , subSlotCount 14 | ) 15 | where 16 | 17 | import Cardano.Prelude 18 | 19 | import qualified Data.Aeson as Aeson 20 | import Formatting (bprint, int) 21 | import qualified Formatting.Buildable as B 22 | import Text.JSON.Canonical (FromJSON(..), ToJSON(..)) 23 | 24 | import Cardano.Binary (FromCBOR(..), ToCBOR(..)) 25 | import Cardano.Chain.Slotting.SlotCount (SlotCount(..)) 26 | 27 | 28 | -- | 'SlotNumber' is an absolute slot number from the beginning of time 29 | -- 30 | -- 'SlotNumber' is held in a 'Word64'. Assuming a slot every 20 seconds, 'Word64' 31 | -- is sufficient for slot indices for 10^13 years. 32 | newtype SlotNumber = SlotNumber 33 | { unSlotNumber :: Word64 34 | } deriving (Eq, Generic, Ord, Show) 35 | deriving newtype Num 36 | deriving anyclass (NFData, NoUnexpectedThunks) 37 | 38 | 39 | -- Used for debugging purposes only 40 | instance Aeson.ToJSON SlotNumber where 41 | 42 | instance ToCBOR SlotNumber where 43 | toCBOR = toCBOR . unSlotNumber 44 | encodedSizeExpr size = encodedSizeExpr size . fmap unSlotNumber 45 | 46 | instance FromCBOR SlotNumber where 47 | fromCBOR = SlotNumber <$> fromCBOR 48 | 49 | instance Monad m => ToJSON m SlotNumber where 50 | toJSON = toJSON . unSlotNumber 51 | 52 | instance MonadError SchemaError m => FromJSON m SlotNumber where 53 | fromJSON val = do 54 | number <- fromJSON val 55 | pure $ SlotNumber number 56 | 57 | instance B.Buildable SlotNumber where 58 | build s = bprint int (unSlotNumber s) 59 | 60 | -- | Increase a 'SlotNumber' by 'SlotCount' 61 | addSlotCount :: SlotCount -> SlotNumber -> SlotNumber 62 | addSlotCount (SlotCount a) (SlotNumber b) = SlotNumber $ a + b 63 | 64 | -- | Decrease a 'SlotNumber' by 'SlotCount', going no lower than 0 65 | subSlotCount :: SlotCount -> SlotNumber -> SlotNumber 66 | subSlotCount (SlotCount a) (SlotNumber b) = 67 | if a > b then SlotNumber 0 else SlotNumber (b - a) 68 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.UTxO 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.UTxO.Compact as X 7 | import Cardano.Chain.UTxO.GenesisUTxO as X 8 | import Cardano.Chain.UTxO.Tx as X 9 | import Cardano.Chain.UTxO.TxAux as X 10 | import Cardano.Chain.UTxO.TxPayload as X 11 | import Cardano.Chain.UTxO.UTxOConfiguration as X 12 | import Cardano.Chain.UTxO.TxProof as X 13 | import Cardano.Chain.UTxO.TxWitness as X 14 | import Cardano.Chain.UTxO.UTxO as X 15 | import Cardano.Chain.UTxO.Validation as X 16 | import Cardano.Chain.UTxO.ValidationMode as X 17 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO/GenesisUTxO.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.UTxO.GenesisUTxO 2 | ( genesisUtxo 3 | ) 4 | where 5 | 6 | import Cardano.Prelude 7 | 8 | import qualified Data.Map.Strict as M 9 | 10 | import Cardano.Chain.Common (Address, Lovelace, makeRedeemAddress) 11 | import Cardano.Chain.Common.NetworkMagic (NetworkMagic, makeNetworkMagic) 12 | import Cardano.Chain.Genesis (unGenesisAvvmBalances, unGenesisNonAvvmBalances) 13 | import qualified Cardano.Chain.Genesis as Genesis 14 | import Cardano.Chain.UTxO.UTxO (UTxO) 15 | import qualified Cardano.Chain.UTxO.UTxO as UTxO 16 | import Cardano.Crypto (fromCompactRedeemVerificationKey) 17 | 18 | 19 | -- | Create initial 'UTxO' from balances defined in the genesis config 20 | genesisUtxo :: Genesis.Config -> UTxO 21 | genesisUtxo config = UTxO.fromBalances balances 22 | where 23 | balances :: [(Address, Lovelace)] 24 | balances = avvmBalances <> nonAvvmBalances 25 | 26 | avvmBalances :: [(Address, Lovelace)] 27 | avvmBalances = 28 | first (makeRedeemAddress networkMagic . fromCompactRedeemVerificationKey) 29 | <$> M.toList (unGenesisAvvmBalances $ Genesis.configAvvmDistr config) 30 | 31 | networkMagic :: NetworkMagic 32 | networkMagic = makeNetworkMagic (Genesis.configProtocolMagic config) 33 | 34 | nonAvvmBalances :: [(Address, Lovelace)] 35 | nonAvvmBalances = 36 | M.toList $ unGenesisNonAvvmBalances $ Genesis.configNonAvvmBalances config 37 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO/TxPayload.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveFunctor #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE DerivingStrategies #-} 5 | {-# LANGUAGE FlexibleContexts #-} 6 | {-# LANGUAGE FlexibleInstances #-} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | {-# LANGUAGE TypeApplications #-} 9 | 10 | module Cardano.Chain.UTxO.TxPayload 11 | ( TxPayload 12 | , ATxPayload(..) 13 | , mkTxPayload 14 | , recoverHashedBytes 15 | , txpAnnotatedTxs 16 | , txpTxs 17 | , txpWitnesses 18 | , unTxPayload 19 | ) 20 | where 21 | 22 | import Cardano.Prelude 23 | 24 | import Data.Aeson (ToJSON) 25 | 26 | import Cardano.Binary (Annotated(..), ByteSpan, FromCBOR(..), ToCBOR(..)) 27 | import Cardano.Chain.UTxO.Tx (Tx) 28 | import Cardano.Chain.UTxO.TxAux (ATxAux(..), TxAux, taTx, taWitness) 29 | import Cardano.Chain.UTxO.TxWitness (TxWitness) 30 | 31 | 32 | -- | Payload of UTxO component which is part of the block body 33 | type TxPayload = ATxPayload () 34 | 35 | mkTxPayload :: [TxAux] -> TxPayload 36 | mkTxPayload = ATxPayload 37 | 38 | newtype ATxPayload a = ATxPayload 39 | { aUnTxPayload :: [ATxAux a] 40 | } deriving (Show, Eq, Generic, Functor) 41 | deriving anyclass NFData 42 | 43 | unTxPayload :: ATxPayload a -> [TxAux] 44 | unTxPayload = fmap void . aUnTxPayload 45 | 46 | -- Used for debugging purposes only 47 | instance ToJSON a => ToJSON (ATxPayload a) where 48 | 49 | instance ToCBOR TxPayload where 50 | toCBOR = toCBOR . unTxPayload 51 | 52 | instance FromCBOR TxPayload where 53 | fromCBOR = void <$> fromCBOR @(ATxPayload ByteSpan) 54 | 55 | instance FromCBOR (ATxPayload ByteSpan) where 56 | fromCBOR = ATxPayload <$> fromCBOR 57 | 58 | txpAnnotatedTxs :: ATxPayload a -> [Annotated Tx a] 59 | txpAnnotatedTxs = fmap aTaTx . aUnTxPayload 60 | 61 | txpTxs :: ATxPayload a -> [Tx] 62 | txpTxs = fmap taTx . unTxPayload 63 | 64 | txpWitnesses :: TxPayload -> [TxWitness] 65 | txpWitnesses = fmap taWitness . unTxPayload 66 | 67 | recoverHashedBytes :: ATxPayload ByteString -> Annotated [TxWitness] ByteString 68 | recoverHashedBytes (ATxPayload auxs) = 69 | let 70 | aWitnesses = aTaWitness <$> auxs 71 | prefix = "\159" :: ByteString 72 | -- This is the value of Codec.CBOR.Write.toLazyByteString encodeListLenIndef 73 | suffix = "\255" :: ByteString 74 | -- This is the value of Codec.CBOR.Write.toLazyByteString encodeBreak 75 | -- They are hard coded here because the hashed bytes included them as an 76 | -- implementation artifact 77 | hashedByted = prefix <> mconcat (annotation <$> aWitnesses) <> suffix 78 | in Annotated (unAnnotated <$> aWitnesses) hashedByted 79 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO/TxProof.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | 6 | module Cardano.Chain.UTxO.TxProof 7 | ( TxProof(..) 8 | , mkTxProof 9 | , recoverTxProof 10 | ) 11 | where 12 | 13 | import Cardano.Prelude 14 | 15 | import Data.Aeson (ToJSON) 16 | import Formatting (bprint, build) 17 | import qualified Formatting.Buildable as B 18 | 19 | import Cardano.Binary (FromCBOR(..), ToCBOR(..), encodeListLen, enforceSize) 20 | import Cardano.Chain.Common.Merkle 21 | (MerkleRoot, mkMerkleTree, mkMerkleTreeDecoded, mtRoot) 22 | import Cardano.Chain.UTxO.Tx (Tx) 23 | import Cardano.Chain.UTxO.TxPayload 24 | ( ATxPayload 25 | , TxPayload 26 | , recoverHashedBytes 27 | , txpAnnotatedTxs 28 | , txpTxs 29 | , txpWitnesses 30 | ) 31 | import Cardano.Chain.UTxO.TxWitness (TxWitness) 32 | import Cardano.Crypto (Hash, hashDecoded, serializeCborHash) 33 | 34 | 35 | data TxProof = TxProof 36 | { txpNumber :: !Word32 37 | , txpRoot :: !(MerkleRoot Tx) 38 | , txpWitnessesHash :: !(Hash [TxWitness]) 39 | } deriving (Show, Eq, Generic, NoUnexpectedThunks) 40 | deriving anyclass NFData 41 | 42 | -- Used for debugging purposes only 43 | instance ToJSON TxProof where 44 | 45 | instance B.Buildable TxProof where 46 | build proof = bprint 47 | ("") 48 | (txpNumber proof) 49 | (txpRoot proof) 50 | (txpWitnessesHash proof) 51 | 52 | instance ToCBOR TxProof where 53 | toCBOR proof = 54 | encodeListLen 3 55 | <> toCBOR (txpNumber proof) 56 | <> toCBOR (txpRoot proof) 57 | <> toCBOR (txpWitnessesHash proof) 58 | encodedSizeExpr size proof = 59 | 1 60 | + encodedSizeExpr size (txpNumber <$> proof) 61 | + encodedSizeExpr size (txpRoot <$> proof) 62 | + encodedSizeExpr size (txpWitnessesHash <$> proof) 63 | 64 | instance FromCBOR TxProof where 65 | fromCBOR = do 66 | enforceSize "TxProof" 3 67 | TxProof <$> fromCBOR <*> fromCBOR <*> fromCBOR 68 | 69 | -- | Construct 'TxProof' which proves given 'TxPayload' 70 | -- 71 | -- This will construct a Merkle tree, which can be very expensive. Use with 72 | -- care. 73 | mkTxProof :: TxPayload -> TxProof 74 | mkTxProof payload = TxProof 75 | { txpNumber = fromIntegral (length $ txpTxs payload) 76 | , txpRoot = mtRoot (mkMerkleTree $ txpTxs payload) 77 | , txpWitnessesHash = serializeCborHash $ txpWitnesses payload 78 | } 79 | 80 | recoverTxProof :: ATxPayload ByteString -> TxProof 81 | recoverTxProof payload = TxProof 82 | { txpNumber = fromIntegral (length $ txpTxs payload) 83 | , txpRoot = mtRoot (mkMerkleTreeDecoded $ txpAnnotatedTxs payload) 84 | , txpWitnessesHash = hashDecoded $ recoverHashedBytes payload 85 | } 86 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO/UTxOConfiguration.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | 4 | module Cardano.Chain.UTxO.UTxOConfiguration 5 | ( UTxOConfiguration(..) 6 | , defaultUTxOConfiguration 7 | , mkUTxOConfiguration 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import qualified Data.Set as Set 14 | 15 | import Cardano.Chain.Common.Address (Address) 16 | import Cardano.Chain.Common.Compact (CompactAddress, toCompactAddress) 17 | 18 | 19 | -- | Additional configuration for ledger validation. 20 | data UTxOConfiguration = UTxOConfiguration 21 | { -- | Set of source address which are asset-locked. Transactions which 22 | -- use these addresses as transaction inputs will be deemed invalid. 23 | tcAssetLockedSrcAddrs :: !(Set CompactAddress) 24 | } deriving (Eq,Show,Generic,NoUnexpectedThunks) 25 | 26 | defaultUTxOConfiguration :: UTxOConfiguration 27 | defaultUTxOConfiguration = 28 | UTxOConfiguration { 29 | tcAssetLockedSrcAddrs = Set.empty 30 | } 31 | 32 | mkUTxOConfiguration :: [Address] -> UTxOConfiguration 33 | mkUTxOConfiguration lockedSrcAddrs = 34 | UTxOConfiguration { 35 | tcAssetLockedSrcAddrs = Set.fromList (map toCompactAddress lockedSrcAddrs) 36 | } 37 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/UTxO/ValidationMode.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.UTxO.ValidationMode 2 | ( TxValidationMode (..) 3 | ) where 4 | 5 | import Cardano.Prelude 6 | 7 | -------------------------------------------------------------------------------- 8 | -- TxValidationMode 9 | -------------------------------------------------------------------------------- 10 | 11 | -- | Indicates what sort of transaction validation should be performed. 12 | data TxValidationMode 13 | = TxValidation 14 | -- ^ Perform all transaction validations. 15 | | TxValidationNoCrypto 16 | -- ^ Because we've already validated this transaction against some ledger 17 | -- state, we know that cryptographic validation has passed. However, we 18 | -- should still perform all of the other non-cryptographic checks since 19 | -- we're validating against a potentially dfferent ledger state. 20 | | NoTxValidation 21 | -- ^ No validations should be performed as we have already validated this 22 | -- transaction against this very same ledger state. 23 | deriving (Eq, Show) 24 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Update 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Chain.Update.ApplicationName as X 7 | import Cardano.Chain.Update.InstallerHash as X 8 | import Cardano.Chain.Update.Payload as X 9 | import Cardano.Chain.Update.Proof as X 10 | import Cardano.Chain.Update.Proposal as X 11 | import Cardano.Chain.Update.ProtocolParameters as X 12 | import Cardano.Chain.Update.ProtocolParametersUpdate as X 13 | import Cardano.Chain.Update.ProtocolVersion as X 14 | import Cardano.Chain.Update.SoftforkRule as X 15 | import Cardano.Chain.Update.SoftwareVersion as X 16 | import Cardano.Chain.Update.SystemTag as X 17 | import Cardano.Chain.Update.Vote as X 18 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update/InstallerHash.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | 6 | module Cardano.Chain.Update.InstallerHash 7 | ( InstallerHash(..) 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import Data.Aeson (ToJSON) 14 | import Formatting (bprint, build) 15 | import qualified Formatting.Buildable as B 16 | 17 | import Cardano.Binary 18 | ( FromCBOR(..) 19 | , Raw 20 | , ToCBOR(..) 21 | , dropBytes 22 | , encodeListLen 23 | , enforceSize 24 | ) 25 | import Cardano.Crypto (Hash, hashRaw) 26 | 27 | 28 | -- | The hash of the installer of the new application 29 | newtype InstallerHash = InstallerHash 30 | { unInstallerHash :: Hash Raw 31 | } deriving (Eq, Show, Generic) 32 | deriving anyclass (NFData, NoUnexpectedThunks) 33 | 34 | instance B.Buildable InstallerHash where 35 | build (InstallerHash h) = bprint ("{ installer hash: " . build . " }") h 36 | 37 | -- Used for debugging purposes only 38 | instance ToJSON InstallerHash where 39 | 40 | instance ToCBOR InstallerHash where 41 | toCBOR (InstallerHash h) = 42 | encodeListLen 4 43 | <> toCBOR emptyHash 44 | <> toCBOR h 45 | <> toCBOR emptyHash 46 | <> toCBOR emptyHash 47 | where emptyHash = hashRaw "\NUL" 48 | 49 | instance FromCBOR InstallerHash where 50 | fromCBOR = do 51 | enforceSize "InstallerHash" 4 52 | dropBytes 53 | h <- fromCBOR 54 | dropBytes 55 | dropBytes 56 | pure $ InstallerHash h 57 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update/Payload.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveFunctor #-} 3 | {-# LANGUAGE DeriveGeneric #-} 4 | {-# LANGUAGE DerivingStrategies #-} 5 | {-# LANGUAGE FlexibleContexts #-} 6 | {-# LANGUAGE FlexibleInstances #-} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | {-# LANGUAGE TypeApplications #-} 9 | {-# LANGUAGE TypeFamilies #-} 10 | 11 | module Cardano.Chain.Update.Payload 12 | ( APayload(..) 13 | , Payload 14 | , payload 15 | ) 16 | where 17 | 18 | import Cardano.Prelude 19 | 20 | import Data.Aeson (ToJSON) 21 | import Formatting (bprint) 22 | import qualified Formatting.Buildable as B 23 | 24 | import Cardano.Binary 25 | ( Annotated(..) 26 | , ByteSpan 27 | , Decoded(..) 28 | , FromCBOR(..) 29 | , ToCBOR(..) 30 | , annotatedDecoder 31 | , encodeListLen 32 | , enforceSize 33 | ) 34 | import Cardano.Chain.Update.Proposal 35 | ( AProposal 36 | , Proposal 37 | , formatMaybeProposal 38 | ) 39 | import Cardano.Chain.Update.Vote 40 | ( AVote 41 | , Vote 42 | , formatVoteShort 43 | ) 44 | 45 | 46 | -- | Update System payload 47 | data APayload a = APayload 48 | { payloadProposal :: !(Maybe (AProposal a)) 49 | , payloadVotes :: ![AVote a] 50 | , payloadAnnotation :: a 51 | } deriving (Eq, Show, Generic, Functor) 52 | deriving anyclass NFData 53 | 54 | type Payload = APayload () 55 | 56 | payload :: Maybe Proposal -> [Vote] -> Payload 57 | payload p v = APayload p v () 58 | 59 | instance Decoded (APayload ByteString) where 60 | type BaseType (APayload ByteString) = Payload 61 | recoverBytes = payloadAnnotation 62 | 63 | instance B.Buildable Payload where 64 | build p 65 | | null (payloadVotes p) 66 | = formatMaybeProposal (payloadProposal p) <> ", no votes" 67 | | otherwise 68 | = formatMaybeProposal (payloadProposal p) <> bprint 69 | ("\n votes: " . listJson) 70 | (map formatVoteShort (payloadVotes p)) 71 | 72 | -- Used for debugging purposes only 73 | instance ToJSON a => ToJSON (APayload a) where 74 | 75 | instance ToCBOR Payload where 76 | toCBOR p = 77 | encodeListLen 2 <> toCBOR (payloadProposal p) <> toCBOR (payloadVotes p) 78 | 79 | instance FromCBOR Payload where 80 | fromCBOR = void <$> fromCBOR @(APayload ByteSpan) 81 | 82 | instance FromCBOR (APayload ByteSpan) where 83 | fromCBOR = do 84 | Annotated (proposal, votes) byteSpan <- annotatedDecoder $ do 85 | enforceSize "Update.Payload" 2 86 | (,) <$> fromCBOR <*> fromCBOR 87 | pure $ APayload proposal votes byteSpan 88 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update/Proof.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Chain.Update.Proof 2 | ( Proof 3 | , mkProof 4 | , recoverProof 5 | ) 6 | where 7 | 8 | import Cardano.Chain.Update.Payload (APayload(..), Payload) 9 | import Cardano.Crypto (Hash, hashDecoded, serializeCborHash) 10 | import Cardano.Prelude 11 | 12 | 13 | -- | Proof that body of update message contains 'Update.Payload' 14 | type Proof = Hash Payload 15 | 16 | mkProof :: Payload -> Proof 17 | mkProof = serializeCborHash 18 | 19 | recoverProof :: APayload ByteString -> Proof 20 | recoverProof = hashDecoded 21 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update/ProtocolVersion.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveAnyClass #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE DerivingStrategies #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | {-# LANGUAGE TemplateHaskell #-} 6 | 7 | module Cardano.Chain.Update.ProtocolVersion 8 | ( ProtocolVersion(..) 9 | ) 10 | where 11 | 12 | import Cardano.Prelude 13 | 14 | import Data.Aeson (ToJSON) 15 | import Formatting (bprint, shown) 16 | import Formatting.Buildable (Buildable(..)) 17 | import qualified Prelude 18 | 19 | import Cardano.Binary (FromCBOR(..), ToCBOR(..), encodeListLen, enforceSize) 20 | 21 | 22 | -- | Communication protocol version 23 | data ProtocolVersion = ProtocolVersion 24 | { pvMajor :: !Word16 25 | , pvMinor :: !Word16 26 | , pvAlt :: !Word8 27 | } deriving (Eq, Generic, Ord) 28 | deriving anyclass (NFData, NoUnexpectedThunks) 29 | 30 | instance Show ProtocolVersion where 31 | show pv = 32 | intercalate "." [show (pvMajor pv), show (pvMinor pv), show (pvAlt pv)] 33 | 34 | instance Buildable ProtocolVersion where 35 | build = bprint shown 36 | 37 | -- Used for debugging purposes only 38 | instance ToJSON ProtocolVersion where 39 | 40 | instance ToCBOR ProtocolVersion where 41 | toCBOR pv = 42 | encodeListLen 3 <> toCBOR (pvMajor pv) <> toCBOR (pvMinor pv) <> toCBOR 43 | (pvAlt pv) 44 | 45 | encodedSizeExpr f pv = 1 46 | + encodedSizeExpr f (pvMajor <$> pv) 47 | + encodedSizeExpr f (pvMinor <$> pv) 48 | + encodedSizeExpr f (pvAlt <$> pv) 49 | 50 | instance FromCBOR ProtocolVersion where 51 | fromCBOR = do 52 | enforceSize "ProtocolVersion" 3 53 | ProtocolVersion <$> fromCBOR <*> fromCBOR <*> fromCBOR 54 | -------------------------------------------------------------------------------- /cardano-ledger/src/Cardano/Chain/Update/Validation/Interface/ProtocolVersionBump.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NamedFieldPuns #-} 2 | 3 | module Cardano.Chain.Update.Validation.Interface.ProtocolVersionBump 4 | ( Environment (..) 5 | , State (..) 6 | , tryBumpVersion 7 | ) 8 | where 9 | 10 | import Cardano.Prelude hiding (State) 11 | 12 | import Cardano.Chain.ProtocolConstants (kUpdateStabilityParam) 13 | import Cardano.Chain.Common.BlockCount (BlockCount) 14 | import Cardano.Chain.Slotting (SlotNumber, subSlotCount) 15 | import Cardano.Chain.Update.ProtocolParameters (ProtocolParameters) 16 | import Cardano.Chain.Update.ProtocolVersion (ProtocolVersion) 17 | import Cardano.Chain.Update.Validation.Endorsement 18 | ( CandidateProtocolUpdate(CandidateProtocolUpdate) 19 | , cpuProtocolParameters 20 | , cpuProtocolVersion 21 | , cpuSlot 22 | ) 23 | 24 | data Environment = Environment 25 | { k :: !BlockCount 26 | , epochFirstSlot :: !SlotNumber 27 | , candidateProtocolVersions :: ![CandidateProtocolUpdate] 28 | } 29 | 30 | data State = State 31 | { nextProtocolVersion :: !ProtocolVersion 32 | , nextProtocolParameters :: !ProtocolParameters 33 | } 34 | 35 | -- | Change the protocol version when an epoch change is detected, and there is 36 | -- a candidate protocol update that was confirmed at least @4 * k@ slots before 37 | -- the start of the new epoch, where @k@ is the chain security parameter. 38 | -- 39 | -- For a full history of why this is required, see 40 | -- https://github.com/input-output-hk/cardano-ledger-specs/issues/1288 41 | -- 42 | -- This corresponds to the @PVBUMP@ rules in the Byron ledger specification. 43 | tryBumpVersion 44 | :: Environment 45 | -> State 46 | -> State 47 | tryBumpVersion env st = 48 | case stableCandidates of 49 | (newestStable:_) -> 50 | let CandidateProtocolUpdate 51 | { cpuProtocolVersion 52 | , cpuProtocolParameters 53 | } = newestStable 54 | in 55 | st { nextProtocolVersion = cpuProtocolVersion 56 | , nextProtocolParameters = cpuProtocolParameters 57 | } 58 | _ -> st 59 | 60 | where 61 | Environment { k, epochFirstSlot, candidateProtocolVersions } = env 62 | 63 | stableCandidates = 64 | filter ((<= subSlotCount (kUpdateStabilityParam k) epochFirstSlot) . cpuSlot) candidateProtocolVersions 65 | -------------------------------------------------------------------------------- /cardano-ledger/test/NormalFormTest.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | This module basically just runs the mainnet epoch validation tests from 3 | "Test.Cardano.Chain.Block.Validation" but provided a 'ShouldAssertNF' value of 4 | 'AssertNF'. 5 | 6 | We've created a separate test executable for this as, in our typical CI jobs, 7 | we utilize @hpc@ (i.e. building with @ghc -fhpc@ or @stack --coverage@) for 8 | providing code coverage. @hpc@ appears to introduce thunks around our Haskell 9 | expressions for its program coverage measurement purposes which prevents us 10 | from accurately determining whether a given expression is in normal form. As a 11 | result, we have another CI job which will build and run this test executable 12 | without @hpc@. 13 | -} 14 | 15 | module Main 16 | ( main 17 | ) 18 | where 19 | 20 | import Cardano.Prelude 21 | 22 | import System.IO.Silently (hSilence) 23 | 24 | import Test.Options (ShouldAssertNF (..), mainWithTestScenario, tsGroupToTree) 25 | 26 | import qualified Test.Cardano.Chain.Block.Validation 27 | 28 | 29 | main :: IO () 30 | main = 31 | hSilence [stderr] 32 | . mainWithTestScenario 33 | . tsGroupToTree 34 | $ Test.Cardano.Chain.Block.Validation.tests AssertNF 35 | -------------------------------------------------------------------------------- /cardano-ledger/test/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Block/Model/Examples.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | {-# OPTIONS_GHC -fno-warn-unused-imports #-} 4 | {-# OPTIONS_GHC -fno-warn-missing-export-lists #-} 5 | 6 | -- | Module containing the imports needed to test that a given abstract trace 7 | -- passes the concrete validation. This is useful when debugging 8 | -- counterexamples. 9 | -- 10 | -- Usage from the ghci repl: 11 | -- 12 | -- > import Hedgehog 13 | -- > Hedgehog.check $ property $ passConcreteValidation trace0 14 | -- 15 | -- Replace @trace0@ by the trace under analysis. 16 | -- 17 | module Test.Cardano.Chain.Block.Model.Examples where 18 | 19 | import GHC.Exts 20 | import Cardano.Prelude hiding (trace, State) 21 | 22 | import Control.State.Transition 23 | import Control.State.Transition.Trace 24 | 25 | import Byron.Spec.Ledger.Core 26 | import Byron.Spec.Ledger.Delegation 27 | import Byron.Spec.Ledger.Update 28 | import Byron.Spec.Ledger.UTxO 29 | import Byron.Spec.Ledger.STS.UTXO 30 | 31 | import Byron.Spec.Chain.STS.Block 32 | import Byron.Spec.Chain.STS.Rule.Chain 33 | 34 | -- | A trace example. When debugging conformance tests you can add such a 35 | -- trace, and use it in the repl. __NOTE__: Do not commit such trace. 36 | trace0 :: Trace CHAIN 37 | trace0 = mkTrace traceEnv0 traceInitState0 traceTrans0 38 | where 39 | traceEnv0 :: Environment CHAIN 40 | traceEnv0 = panic "Add the trace environment here." 41 | 42 | traceInitState0 :: State CHAIN 43 | traceInitState0 = panic "Add the trace initial state here." 44 | 45 | traceTrans0 :: [(State CHAIN, Signal CHAIN)] 46 | traceTrans0 = panic "Add the trace transitions here." 47 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Common/Address.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DataKinds #-} 2 | {-# LANGUAGE NumDecimals #-} 3 | {-# LANGUAGE OverloadedStrings #-} 4 | {-# LANGUAGE TemplateHaskell #-} 5 | {-# LANGUAGE TypeApplications #-} 6 | 7 | module Test.Cardano.Chain.Common.Address 8 | ( tests 9 | ) 10 | where 11 | 12 | import Cardano.Prelude 13 | import Test.Cardano.Prelude 14 | 15 | import Hedgehog ((===), cover, forAll, property) 16 | 17 | import Cardano.Chain.Common (addrNetworkMagic, isRedeemAddress) 18 | 19 | import Test.Cardano.Chain.Common.Gen (genAddress, genAddressWithNM, genNetworkMagic) 20 | import Test.Options (TSGroup, TSProperty, withTestsTS) 21 | 22 | 23 | ts_prop_addressNetworkMagicIdentity :: TSProperty 24 | ts_prop_addressNetworkMagicIdentity = 25 | withTestsTS 1000 . property $ do 26 | nm <- forAll genNetworkMagic 27 | addr <- forAll (genAddressWithNM nm) 28 | nm === addrNetworkMagic addr 29 | 30 | ts_prop_isRedeemAddress :: TSProperty 31 | ts_prop_isRedeemAddress = 32 | withTestsTS 1000 . property $ do 33 | addr <- forAll genAddress 34 | cover 30 "Redeem Address" $ isRedeemAddress addr 35 | cover 30 "Pubkey Address" $ not (isRedeemAddress addr) 36 | 37 | tests :: TSGroup 38 | tests = $$discoverPropArg 39 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Common/Compact.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# LANGUAGE OverloadedStrings #-} 3 | {-# LANGUAGE TemplateHaskell #-} 4 | 5 | module Test.Cardano.Chain.Common.Compact 6 | ( tests 7 | ) 8 | where 9 | 10 | import Cardano.Prelude 11 | 12 | import Hedgehog (MonadTest, assert, forAll, property, tripping) 13 | 14 | import Cardano.Chain.Common (fromCompactAddress, toCompactAddress) 15 | 16 | import Test.Cardano.Chain.Common.Gen (genAddress) 17 | import Test.Cardano.Prelude (discoverPropArg, discoverRoundTripArg) 18 | import Test.Options (TSGroup, TSProperty, concatTSGroups, eachOfTS, withTestsTS) 19 | 20 | 21 | -------------------------------------------------------------------------------- 22 | -- Compact Address 23 | -------------------------------------------------------------------------------- 24 | 25 | ts_roundTripCompactAddress :: TSProperty 26 | ts_roundTripCompactAddress = 27 | eachOfTS 1000 genAddress (trippingCompact toCompactAddress fromCompactAddress) 28 | 29 | ts_prop_heapWordsSavingsCompactAddress :: TSProperty 30 | ts_prop_heapWordsSavingsCompactAddress = withTestsTS 1000 $ property $ do 31 | addr <- forAll genAddress 32 | let compactAddr = toCompactAddress addr 33 | assert $ heapWords compactAddr < heapWords addr 34 | 35 | 36 | -------------------------------------------------------------------------------- 37 | -- Tripping util 38 | -------------------------------------------------------------------------------- 39 | 40 | trippingCompact 41 | :: (HasCallStack, MonadTest m, Show a, Show b, Eq a) 42 | => (a -> b) -> (b -> a) -> a -> m () 43 | trippingCompact toCompact fromCompact x = 44 | tripping x toCompact (Identity . fromCompact) 45 | 46 | 47 | -------------------------------------------------------------------------------- 48 | -- Main test export 49 | -------------------------------------------------------------------------------- 50 | 51 | tests :: TSGroup 52 | tests = concatTSGroups [$$discoverPropArg, $$discoverRoundTripArg] 53 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Common/Example.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | {-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-} 4 | 5 | module Test.Cardano.Chain.Common.Example 6 | ( exampleAddress 7 | , exampleAddress1 8 | , exampleAddress2 9 | , exampleAddress3 10 | , exampleAddress4 11 | , exampleAttributes 12 | , exampleAddrSpendingData_VerKey 13 | , exampleChainDifficulty 14 | , exampleKeyHash 15 | ) 16 | where 17 | 18 | import Cardano.Prelude 19 | 20 | import Cardano.Chain.Common 21 | ( AddrAttributes(..) 22 | , HDAddressPayload(..) 23 | , AddrSpendingData(..) 24 | , Address 25 | , Attributes 26 | , ChainDifficulty(..) 27 | , NetworkMagic(..) 28 | , KeyHash 29 | , makeAddress 30 | , mkAttributes 31 | , hashKey 32 | ) 33 | 34 | import Test.Cardano.Crypto.CBOR (getBytes) 35 | import Test.Cardano.Crypto.Example 36 | (exampleVerificationKey, exampleVerificationKeys, exampleRedeemVerificationKey) 37 | 38 | 39 | exampleAttributes :: Attributes () 40 | exampleAttributes = mkAttributes () 41 | 42 | exampleAddrSpendingData_VerKey :: AddrSpendingData 43 | exampleAddrSpendingData_VerKey = VerKeyASD exampleVerificationKey 44 | 45 | exampleAddress :: Address 46 | exampleAddress = makeAddress exampleAddrSpendingData_VerKey attrs 47 | where 48 | attrs = AddrAttributes hap nm 49 | hap = Just (HDAddressPayload (getBytes 32 32)) 50 | nm = NetworkMainOrStage 51 | 52 | exampleAddress1 :: Address 53 | exampleAddress1 = makeAddress easd attrs 54 | where 55 | easd = VerKeyASD vk 56 | [vk] = exampleVerificationKeys 24 1 57 | attrs = AddrAttributes hap nm 58 | hap = Nothing :: Maybe HDAddressPayload 59 | nm = NetworkMainOrStage 60 | 61 | exampleAddress2 :: Address 62 | exampleAddress2 = makeAddress easd attrs 63 | where 64 | easd = RedeemASD exampleRedeemVerificationKey 65 | attrs = AddrAttributes hap nm 66 | hap = Just (HDAddressPayload (getBytes 15 32)) 67 | nm = NetworkMainOrStage 68 | 69 | exampleAddress3 :: Address 70 | exampleAddress3 = makeAddress easd attrs 71 | where 72 | easd = VerKeyASD vk 73 | [vk] = exampleVerificationKeys 20 1 74 | attrs = AddrAttributes hap nm 75 | hap = Just (HDAddressPayload (getBytes 17 32)) 76 | nm = NetworkTestnet 9973261 77 | 78 | exampleAddress4 :: Address 79 | exampleAddress4 = makeAddress easd attrs 80 | where 81 | easd = exampleAddrSpendingData_VerKey 82 | attrs = AddrAttributes Nothing nm 83 | nm = NetworkTestnet 11111911 84 | 85 | exampleChainDifficulty :: ChainDifficulty 86 | exampleChainDifficulty = ChainDifficulty 9999 87 | 88 | exampleKeyHash :: KeyHash 89 | exampleKeyHash = hashKey exampleVerificationKey 90 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Config.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | module Test.Cardano.Chain.Config 4 | ( readMainetCfg 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Cardano.Binary (Raw) 11 | import qualified Cardano.Chain.Genesis as Genesis 12 | import Cardano.Crypto.Hashing (Hash, decodeHash) 13 | import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic(..)) 14 | 15 | -- | Read the test mainnet configuration file from the @test@ directory. 16 | -- 17 | -- An error is thrown if it is not possible to elaborate a genesis 18 | -- configuration from the genesis file. 19 | -- 20 | -- We use `RequiresNoMagic`, as it indicates mainnet 21 | readMainetCfg :: MonadIO m => m Genesis.Config 22 | readMainetCfg = do 23 | let 24 | genHash = either 25 | (panic . show . Genesis.GenesisHashDecodeError) 26 | identity 27 | (decodeHash 28 | "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb" 29 | ) :: Hash Raw 30 | 31 | either (panic . show) identity <$> runExceptT 32 | (Genesis.mkConfigFromFile RequiresNoMagic "mainnet-genesis.json" genHash) 33 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Delegation/CBOR.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Chain.Delegation.CBOR 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | import Test.Cardano.Prelude 10 | 11 | import Data.List ((!!)) 12 | 13 | import Hedgehog (Property) 14 | 15 | import Cardano.Chain.Delegation (unsafePayload) 16 | 17 | import Test.Cardano.Binary.Helpers.GoldenRoundTrip 18 | (goldenTestCBOR, roundTripsCBORBuildable, roundTripsCBORShow) 19 | import Test.Cardano.Chain.Delegation.Example (exampleCertificates) 20 | import Test.Cardano.Chain.Delegation.Gen 21 | (genCertificate, genError, genPayload) 22 | import Test.Cardano.Crypto.Gen (feedPM) 23 | import Test.Options (TSGroup, TSProperty, concatTSGroups, eachOfTS) 24 | 25 | 26 | -------------------------------------------------------------------------------- 27 | -- Certificate 28 | -------------------------------------------------------------------------------- 29 | 30 | goldenCertificate :: Property 31 | goldenCertificate = goldenTestCBOR 32 | cert 33 | "test/golden/cbor/delegation/Certificate" 34 | where cert = exampleCertificates !! 0 35 | 36 | ts_roundTripCertificateCBOR :: TSProperty 37 | ts_roundTripCertificateCBOR = 38 | eachOfTS 200 (feedPM genCertificate) roundTripsCBORBuildable 39 | 40 | 41 | -------------------------------------------------------------------------------- 42 | -- DlgPayload 43 | -------------------------------------------------------------------------------- 44 | 45 | goldenDlgPayload :: Property 46 | goldenDlgPayload = goldenTestCBOR dp "test/golden/cbor/delegation/DlgPayload" 47 | where dp = unsafePayload (take 4 exampleCertificates) 48 | 49 | ts_roundTripDlgPayloadCBOR :: TSProperty 50 | ts_roundTripDlgPayloadCBOR = 51 | eachOfTS 100 (feedPM genPayload) roundTripsCBORBuildable 52 | 53 | 54 | -------------------------------------------------------------------------------- 55 | -- Error 56 | -------------------------------------------------------------------------------- 57 | 58 | ts_roundTripErrorCBOR :: TSProperty 59 | ts_roundTripErrorCBOR = 60 | eachOfTS 100 genError roundTripsCBORShow 61 | 62 | 63 | tests :: TSGroup 64 | tests = concatTSGroups [const $$discoverGolden, $$discoverRoundTripArg] 65 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Delegation/Certificate.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module Test.Cardano.Chain.Delegation.Certificate 5 | ( tests 6 | ) 7 | where 8 | 9 | import Cardano.Prelude 10 | 11 | import qualified Data.ByteString.Lazy as BSL 12 | 13 | import Hedgehog (Group, Property, assert, discover, forAll, property) 14 | import qualified Hedgehog.Gen as Gen 15 | 16 | import Cardano.Binary (decodeFull, serialize, slice) 17 | import Cardano.Chain.Delegation 18 | (ACertificate(delegateVK), Certificate, isValid, signCertificate) 19 | 20 | import Test.Cardano.Chain.Slotting.Gen (genEpochNumber) 21 | import qualified Test.Cardano.Crypto.Dummy as Dummy 22 | import Test.Cardano.Crypto.Gen (genSafeSigner, genVerificationKey) 23 | 24 | 25 | -------------------------------------------------------------------------------- 26 | -- Test Group 27 | -------------------------------------------------------------------------------- 28 | 29 | tests :: Group 30 | tests = $$discover 31 | 32 | -------------------------------------------------------------------------------- 33 | -- Certificate Properties 34 | -------------------------------------------------------------------------------- 35 | 36 | -- | Can validate 'Certificate's produced by 'signCertificate' 37 | prop_certificateCorrect :: Property 38 | prop_certificateCorrect = property $ do 39 | cert <- 40 | forAll 41 | $ signCertificate Dummy.protocolMagicId 42 | <$> genVerificationKey 43 | <*> genEpochNumber 44 | <*> genSafeSigner 45 | 46 | let aCert = annotateCert cert 47 | 48 | assert $ isValid Dummy.annotatedProtocolMagicId aCert 49 | 50 | -- | Cannot validate 'Certificate's with incorrect verification keys 51 | prop_certificateIncorrect :: Property 52 | prop_certificateIncorrect = property $ do 53 | cert <- 54 | forAll 55 | $ signCertificate Dummy.protocolMagicId 56 | <$> genVerificationKey 57 | <*> genEpochNumber 58 | <*> genSafeSigner 59 | badDelegateVK <- forAll $ Gen.filter (/= delegateVK cert) genVerificationKey 60 | 61 | let 62 | badCert = cert { delegateVK = badDelegateVK } 63 | aBadCert = annotateCert badCert 64 | 65 | assert . not $ isValid Dummy.annotatedProtocolMagicId aBadCert 66 | 67 | annotateCert :: Certificate -> ACertificate ByteString 68 | annotateCert cert = 69 | fmap (BSL.toStrict . slice bytes) 70 | . fromRight 71 | (panic "prop_certificateCorrect: Round trip broken for Certificate") 72 | $ decodeFull bytes 73 | where bytes = serialize cert 74 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Delegation/Example.hs: -------------------------------------------------------------------------------- 1 | module Test.Cardano.Chain.Delegation.Example 2 | ( exampleCertificates 3 | ) 4 | where 5 | 6 | import Cardano.Prelude 7 | 8 | import Data.List (zipWith4) 9 | 10 | import Cardano.Chain.Delegation (Certificate, signCertificate) 11 | import Cardano.Chain.Slotting (EpochNumber(..)) 12 | import Cardano.Crypto (ProtocolMagicId(..)) 13 | 14 | import Test.Cardano.Crypto.Example (exampleVerificationKeys, staticSafeSigners) 15 | 16 | 17 | staticProtocolMagics :: [ProtocolMagicId] 18 | staticProtocolMagics = ProtocolMagicId <$> [0 .. 5] 19 | 20 | exampleCertificates :: [Certificate] 21 | exampleCertificates = zipWith4 22 | signCertificate 23 | staticProtocolMagics 24 | (exampleVerificationKeys 1 6) 25 | exampleEpochIndices 26 | staticSafeSigners 27 | where exampleEpochIndices = EpochNumber <$> [5, 1, 3, 27, 99, 247] 28 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Elaboration/Keys.hs: -------------------------------------------------------------------------------- 1 | module Test.Cardano.Chain.Elaboration.Keys 2 | ( elaborateKeyPair 3 | , elaborateVKey 4 | , elaborateVKeyGenesis 5 | , elaborateVKeyGenesisHash 6 | -- * Abstract verification-key elaboration functions 7 | , vKeyPair 8 | , vKeyToSKey 9 | , vKeyToSafeSigner 10 | ) 11 | where 12 | 13 | import Cardano.Prelude 14 | 15 | import qualified Data.ByteString as BS 16 | import Data.ByteString.Builder (integerDec, toLazyByteString) 17 | import qualified Data.ByteString.Lazy as BSL 18 | 19 | import Cardano.Chain.Common (KeyHash, hashKey) 20 | import Cardano.Crypto.Signing (VerificationKey, SigningKey, deterministicKeyGen, noPassSafeSigner, SafeSigner) 21 | import Byron.Spec.Ledger.Core 22 | ( KeyPair 23 | , Owner(Owner) 24 | , VKey(VKey) 25 | , VKeyGenesis(VKeyGenesis) 26 | , keyPair 27 | , owner 28 | , sKey 29 | ) 30 | 31 | elaborateKeyPair :: KeyPair -> (VerificationKey, SigningKey) 32 | elaborateKeyPair kp = deterministicKeyGen $ padSeed seed 33 | where 34 | Owner o = owner $ sKey kp 35 | padSeed s = 36 | let padLength = max 0 (32 - BS.length s) in BS.replicate padLength 0 <> s 37 | seed = BSL.toStrict . toLazyByteString . integerDec $ fromIntegral o 38 | 39 | vKeyPair :: VKey -> KeyPair 40 | vKeyPair (VKey o) = keyPair o 41 | 42 | elaborateVKey :: VKey -> VerificationKey 43 | elaborateVKey = fst . elaborateKeyPair . vKeyPair 44 | 45 | vKeyToSKey :: VKey -> SigningKey 46 | vKeyToSKey = snd . elaborateKeyPair . vKeyPair 47 | 48 | vKeyToSafeSigner :: VKey -> SafeSigner 49 | vKeyToSafeSigner = noPassSafeSigner . vKeyToSKey 50 | 51 | elaborateVKeyGenesis :: VKeyGenesis -> VerificationKey 52 | elaborateVKeyGenesis (VKeyGenesis vk) = elaborateVKey vk 53 | 54 | elaborateVKeyGenesisHash :: VKeyGenesis -> KeyHash 55 | elaborateVKeyGenesisHash = hashKey . elaborateVKeyGenesis 56 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Epoch/File.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Chain.Epoch.File 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Control.Monad.Trans.Resource (ResIO, runResourceT) 11 | import Data.Maybe (isJust) 12 | import Hedgehog (Group, Property, (===), discover) 13 | import qualified Hedgehog as H 14 | import Streaming (Of((:>))) 15 | import qualified Streaming as S 16 | import System.Environment (lookupEnv) 17 | 18 | import Cardano.Chain.Epoch.File (ParseError, mainnetEpochSlots, parseEpochFilesWithBoundary) 19 | 20 | import Test.Cardano.Mirror (mainnetEpochFiles) 21 | 22 | 23 | tests :: Group 24 | tests = $$discover 25 | 26 | prop_deserializeEpochs :: Property 27 | prop_deserializeEpochs = H.withTests 1 $ H.property $ do 28 | menv <- liftIO $ lookupEnv "CARDANO_MAINNET_MIRROR" 29 | H.assert $ isJust menv 30 | 31 | files <- take 10 <$> liftIO mainnetEpochFiles 32 | H.assert $ not (null files) 33 | -- TODO: the property cannot take any parameters (if we want discoverPrefix 34 | -- to work). Now the question is whether it is OK to use an hardcoded value 35 | -- for the number of slots per epoch, and if so in which module should we 36 | -- store this constant? 37 | let stream = parseEpochFilesWithBoundary mainnetEpochSlots files 38 | result <- (liftIO . runResourceT . runExceptT . S.run) (S.maps discard stream) 39 | result === Right () 40 | where 41 | discard :: Of a m -> ExceptT ParseError ResIO m 42 | discard (_ :> rest) = pure rest 43 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/MempoolPayload/Example.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | module Test.Cardano.Chain.MempoolPayload.Example 4 | ( exampleMempoolPayload 5 | , exampleMempoolPayload1 6 | , exampleMempoolPayload2 7 | , exampleMempoolPayload3 8 | ) 9 | where 10 | 11 | import Data.List ((!!)) 12 | 13 | import Cardano.Chain.MempoolPayload (AMempoolPayload (..), MempoolPayload) 14 | 15 | import Test.Cardano.Chain.Delegation.Example as Delegation 16 | (exampleCertificates) 17 | import Test.Cardano.Chain.Update.Example as Update 18 | (exampleProposal, exampleVote) 19 | import Test.Cardano.Chain.UTxO.Example (exampleTxAux) 20 | 21 | 22 | exampleMempoolPayload :: MempoolPayload 23 | exampleMempoolPayload = MempoolTx exampleTxAux 24 | 25 | exampleMempoolPayload1 :: MempoolPayload 26 | exampleMempoolPayload1 = MempoolDlg (Delegation.exampleCertificates !! 0) 27 | 28 | exampleMempoolPayload2 :: MempoolPayload 29 | exampleMempoolPayload2 = MempoolUpdateProposal Update.exampleProposal 30 | 31 | exampleMempoolPayload3 :: MempoolPayload 32 | exampleMempoolPayload3 = MempoolUpdateVote Update.exampleVote 33 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/MempoolPayload/Gen.hs: -------------------------------------------------------------------------------- 1 | module Test.Cardano.Chain.MempoolPayload.Gen 2 | ( genMempoolPayload 3 | ) 4 | where 5 | 6 | import Cardano.Prelude 7 | 8 | import Hedgehog 9 | import qualified Hedgehog.Gen as Gen 10 | 11 | import Cardano.Chain.MempoolPayload (AMempoolPayload (..), MempoolPayload) 12 | import Cardano.Crypto (ProtocolMagicId) 13 | 14 | import Test.Cardano.Chain.Delegation.Gen as Delegation (genCertificate) 15 | import Test.Cardano.Chain.Update.Gen as Update (genProposal, genVote) 16 | import Test.Cardano.Chain.UTxO.Gen (genTxAux) 17 | 18 | genMempoolPayload :: ProtocolMagicId -> Gen MempoolPayload 19 | genMempoolPayload pmi = Gen.choice 20 | [ MempoolTx <$> genTxAux pmi 21 | , MempoolDlg <$> Delegation.genCertificate pmi 22 | , MempoolUpdateProposal <$> Update.genProposal pmi 23 | , MempoolUpdateVote <$> Update.genVote pmi 24 | ] 25 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Chain/Slotting/Example.hs: -------------------------------------------------------------------------------- 1 | module Test.Cardano.Chain.Slotting.Example 2 | ( exampleEpochNumber 3 | , exampleEpochAndSlotCount 4 | , exampleSlotNumber 5 | ) 6 | where 7 | 8 | import Cardano.Chain.Slotting 9 | ( EpochNumber(..) 10 | , EpochSlots(..) 11 | , EpochAndSlotCount(..) 12 | , SlotCount(..) 13 | , SlotNumber 14 | , toSlotNumber 15 | ) 16 | 17 | 18 | exampleEpochNumber :: EpochNumber 19 | exampleEpochNumber = EpochNumber 14 20 | 21 | exampleSlotNumber :: EpochSlots -> SlotNumber 22 | exampleSlotNumber es = toSlotNumber es exampleEpochAndSlotCount 23 | 24 | exampleEpochAndSlotCount :: EpochAndSlotCount 25 | exampleEpochAndSlotCount = EpochAndSlotCount (EpochNumber 11) (SlotCount 47) 26 | -------------------------------------------------------------------------------- /cardano-ledger/test/Test/Cardano/Mirror.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | 3 | module Test.Cardano.Mirror 4 | ( mainnetEpochFiles 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Data.List (sort) 11 | import System.Directory (doesDirectoryExist, getDirectoryContents) 12 | import System.Environment (lookupEnv) 13 | import System.Exit (exitFailure) 14 | import System.FilePath ((), isExtensionOf) 15 | 16 | 17 | -- Failing here (with 'exitFailure') is fine because this function is only ever 18 | -- used to test maiinnet validaton. It is never used in production code. 19 | mainnetEpochFiles :: IO [FilePath] 20 | mainnetEpochFiles = lookupEnv "CARDANO_MAINNET_MIRROR" >>= \case 21 | Nothing -> do 22 | putStrLn "mainnetEpochFiles: CARDANO_MAINNET_MIRROR variable is not set" 23 | exitFailure 24 | Just fpath -> do 25 | exists <- doesDirectoryExist fpath 26 | if exists 27 | then 28 | sort 29 | . fmap (fpath ) 30 | . filter ("epoch" `isExtensionOf`) 31 | <$> getDirectoryContents fpath 32 | else do 33 | putStrLn 34 | $ "mainnetEpochFiles: directory '" 35 | ++ fpath 36 | ++ "' does not exist." 37 | exitFailure 38 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/BlockSignature: -------------------------------------------------------------------------------- 1 | 000: 820282840558406269376936644c586b 2 | 010: 756573565a394a6648676a726374734c 3 | 020: 4674324e766f76586e6368734f765830 4 | 030: 3559364c6f686c544e74356d6b504668 5 | 040: 556f587531455a58404a30754b446269 6 | 050: 376936644c586b756573565a394a6648 7 | 060: 676a726374734c4674324e766f76586e 8 | 070: 6368734f7658303559364c6f686c544e 9 | 080: 74356d6b504668556f58406e0bd66eb8 10 | 090: 1c0dab1c9ef346719663f56cbba23b46 11 | 0a0: ee08d00daae844426c993b4f259d9d03 12 | 0b0: abc95f131dfb9e96e4f65cc2487386a6 13 | 0c0: e44f1c876eb3664c26080858404582df 14 | 0d0: 4a86f9264aa23dc5b1a7c858144780a4 15 | 0e0: ea4cdf70aed811c74d0c88c729aa1465 16 | 0f0: e675ce7cd015db95f876f4dfa67681c1 17 | 100: be7c9dc6b8fd52d32d039a0e05 18 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/BoundaryBlockHeader: -------------------------------------------------------------------------------- 1 | 00: 85005820f7077d40c94a36e7df95b6f9 2 | 10: 9a86f08bcf06ea3b24e68dd3039333fa 3 | 20: 5314177558204965a00c5a47c3877339 4 | 30: 85445c24dc988b36e4fcd8db638ec28a 5 | 40: 23ae4773ca60820b810081a0 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/BoundaryBody: -------------------------------------------------------------------------------- 1 | 00: 9f581cb4c0e0810a8cd4f5b9249c4190 2 | 10: 0704b35ed186205c708a40b5abac9058 3 | 20: 1c3ecac862f1e7a998327e20d2d23da9 4 | 30: a1993948bee60dbd83d5df5ac5581c67 5 | 40: f342be03ba63cecff19b3da527582f24 6 | 50: 385184478e183c1d2fb38fff 7 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/BoundaryConsensusData: -------------------------------------------------------------------------------- 1 | 820e8119270f -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/BoundaryProof: -------------------------------------------------------------------------------- 1 | 00: 58204965a00c5a47c387733985445c24 2 | 10: dc988b36e4fcd8db638ec28a23ae4773 3 | 20: ca60 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/ExtraBodyData: -------------------------------------------------------------------------------- 1 | 81a0 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/Header: -------------------------------------------------------------------------------- 1 | 000: 85075820125bbf1daefc2897d8db4899 2 | 010: 9d09b4eae439f0dfed83bc43246ca039 3 | 020: fa4b121384830158205e46ceb20538af 4 | 030: eeb45cb8f7030512af34b4ff363a8c7e 5 | 040: 94d441a257500ffab75820e32c9549bc 6 | 050: 3acbe0e848b2d7ad26331b7d84975803 7 | 060: 64cb2bc6c8bda9aa0975b882035820d3 8 | 070: 6a2619a672494604e11bb447cbcf5231 9 | 080: e9f2ba25c2169177edc941bd50ad6c58 10 | 090: 20b5f2d3cb5a94d3e7dc9d812ebf5600 11 | 0a0: 3e4f9fb02296034f5d5bcd073811ebe6 12 | 0b0: b35820adfd9b4aa5620d4b0a0587186e 13 | 0c0: 6828efa789b2582eef698523a308d6f3 14 | 0d0: edd94084820b182f5840626937693664 15 | 0e0: 4c586b756573565a394a6648676a7263 16 | 0f0: 74734c4674324e766f76586e6368734f 17 | 100: 7658303559364c6f686c544e74356d6b 18 | 110: 504668556f587531455a8119270f8202 19 | 120: 82840558406269376936644c586b7565 20 | 130: 73565a394a6648676a726374734c4674 21 | 140: 324e766f76586e6368734f7658303559 22 | 150: 364c6f686c544e74356d6b504668556f 23 | 160: 587531455a58404a30754b4462693769 24 | 170: 36644c586b756573565a394a6648676a 25 | 180: 726374734c4674324e766f76586e6368 26 | 190: 734f7658303559364c6f686c544e7435 27 | 1a0: 6d6b504668556f58406e0bd66eb81c0d 28 | 1b0: ab1c9ef346719663f56cbba23b46ee08 29 | 1c0: d00daae844426c993b4f259d9d03abc9 30 | 1d0: 5f131dfb9e96e4f65cc2487386a6e44f 31 | 1e0: 1c876eb3664c260808584093cd386a61 32 | 1f0: 4bf6523c3844aa3c4c714ab4e272ff0b 33 | 200: 3b9bfa8c254156b49bcb846544649bdd 34 | 210: e77fd336cf9e48214601de8ae92abe11 35 | 220: 3ab844e3322b183f7a890e8483010101 36 | 230: 8266476f6c64656e1863a058204ba92a 37 | 240: a320c60acc9ad7b9a64f2eda55c4d2ec 38 | 250: 28e604faf186708b4f0c4e8edf 39 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/HeaderHash: -------------------------------------------------------------------------------- 1 | 00: 5820125bbf1daefc2897d8db48999d09 2 | 10: b4eae439f0dfed83bc43246ca039fa4b 3 | 20: 1213 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/Proof: -------------------------------------------------------------------------------- 1 | 00: 8483182058205e46ceb20538afeeb45c 2 | 10: b8f7030512af34b4ff363a8c7e94d441 3 | 20: a257500ffab75820e32c9549bc3acbe0 4 | 30: e848b2d7ad26331b7d8497580364cb2b 5 | 40: c6c8bda9aa0975b882035820d36a2619 6 | 50: a672494604e11bb447cbcf5231e9f2ba 7 | 60: 25c2169177edc941bd50ad6c5820b5f2 8 | 70: d3cb5a94d3e7dc9d812ebf56003e4f9f 9 | 80: b02296034f5d5bcd073811ebe6b35820 10 | 90: adfd9b4aa5620d4b0a0587186e6828ef 11 | a0: a789b2582eef698523a308d6f3edd940 12 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/StaticConfig_GCSpec: -------------------------------------------------------------------------------- 1 | { 2 | "spec": { 3 | "blockVersionData": { 4 | "txFeePolicy": { 5 | "txSizeLinear": { 6 | "a": 999, 7 | "b": 77 8 | } 9 | }, 10 | "maxTxSize": 999, 11 | "updateProposalThd": 9.9e-14, 12 | "scriptVersion": 999, 13 | "maxBlockSize": 999, 14 | "heavyDelThd": 9.9e-14, 15 | "updateImplicit": 99, 16 | "maxHeaderSize": 999, 17 | "updateVoteThd": 9.9e-14, 18 | "slotDuration": 9.99e-4, 19 | "maxProposalSize": 999, 20 | "softforkRule": { 21 | "minThd": 9.9e-14, 22 | "thdDecrement": 9.9e-14, 23 | "initThd": 9.9e-14 24 | }, 25 | "mpcThd": 9.9e-14, 26 | "unlockStakeEpoch": 99 27 | }, 28 | "k": { 29 | "getBlockCount": 37 30 | }, 31 | "avvmDistr": { 32 | "U4lgqRZyawnwXJ1NSpIrhbThGs_MFDRnPZUBm3qaUtI=": 36524597913081152, 33 | "dtXbK7ASFLEa611AHt7SDk_48fVbNja-Tj7PgbE7tPE=": 37343863242999412 34 | }, 35 | "protocolMagic": 1783847074, 36 | "initializer": { 37 | "useHeavyDlg": false, 38 | "avvmBalanceFactor": 0.366832547637728, 39 | "seed": 0, 40 | "testBalance": { 41 | "totalBalance": 10953275486128625, 42 | "richmenShare": 0.366832547637728, 43 | "useHDAddresses": true, 44 | "richmen": 1.4071205313513960321e19, 45 | "poors": 2448641325904532856 46 | }, 47 | "fakeAvvmBalance": { 48 | "oneBalance": 15087947214890024, 49 | "count": 1.7853231730478779264e19 50 | } 51 | }, 52 | "heavyDelegation": { 53 | "ed41bf35f4cd2109bdee27b0439942f6de3f55f0ac8d170de7136d3d": { 54 | "pskDelegateVK": "3cppv+rBTAEzBNqIrAMu5jKBqwNsGxuRiOSxdLMD9D5VFjsXjpmbn9UGN7Ltq4yFioeaw8S9PmEAlUGaGWllcw==", 55 | "pskOmega": 68300481033, 56 | "pskCert": "bae5422af5405e3803154a4ad986da5d14cf624d6701c5c78a79ec73777f74e13973af83752114d9f18166085997fc81e432cab7fee99a275d8bf138ad04e103", 57 | "pskIssuerVK": "4qF3OiqC0QwwiQy/hOzL3Bqq7pIElkJNNuhoA52ctRkhsl7+Az2bANTwLM2c2rzsMyq7xv34g8pb86iv9KrCfg==" 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/block/ToSign: -------------------------------------------------------------------------------- 1 | 000: 855820125bbf1daefc2897d8db48999d 2 | 010: 09b4eae439f0dfed83bc43246ca039fa 3 | 020: 4b12138483182058205e46ceb20538af 4 | 030: eeb45cb8f7030512af34b4ff363a8c7e 5 | 040: 94d441a257500ffab75820e32c9549bc 6 | 050: 3acbe0e848b2d7ad26331b7d84975803 7 | 060: 64cb2bc6c8bda9aa0975b882035820d3 8 | 070: 6a2619a672494604e11bb447cbcf5231 9 | 080: e9f2ba25c2169177edc941bd50ad6c58 10 | 090: 20b5f2d3cb5a94d3e7dc9d812ebf5600 11 | 0a0: 3e4f9fb02296034f5d5bcd073811ebe6 12 | 0b0: b35820adfd9b4aa5620d4b0a0587186e 13 | 0c0: 6828efa789b2582eef698523a308d6f3 14 | 0d0: edd940820b182f8119270f8483010101 15 | 0e0: 8266476f6c64656e1863a058204ba92a 16 | 0f0: a320c60acc9ad7b9a64f2eda55c4d2ec 17 | 100: 28e604faf186708b4f0c4e8edf 18 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/AddrSpendingData_Redeem: -------------------------------------------------------------------------------- 1 | 00: 82025820538960a916726b09f05c9d4d 2 | 10: 4a922b85b4e11acfcc1434673d95019b 3 | 20: 7a9a52d2 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/AddrSpendingData_VerKey: -------------------------------------------------------------------------------- 1 | 00: 820058404b6d7977346c445345355334 2 | 10: 6653483665744e6f756958657a437945 3 | 20: 6a4b63337447346a61306b466a4f3871 4 | 30: 7a616932365a4d5055454a6645793135 5 | 40: 6f78356b 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/AddrType_R: -------------------------------------------------------------------------------- 1 | 02 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/AddrType_VK: -------------------------------------------------------------------------------- 1 | 00 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address: -------------------------------------------------------------------------------- 1 | 00: 82d818584683581cabeaaa8f95c4529b 2 | 10: b494e648c2e8e3522713f466a9dec1f1 3 | 20: decea1b7a101582258207447346a6130 4 | 30: 6b466a4f38717a616932365a4d505545 5 | 40: 4a66457931356f78356b001a03f38741 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address0: -------------------------------------------------------------------------------- 1 | 00: 82d818584683581cabeaaa8f95c4529b 2 | 10: b494e648c2e8e3522713f466a9dec1f1 3 | 20: decea1b7a101582258207447346a6130 4 | 30: 6b466a4f38717a616932365a4d505545 5 | 40: 4a66457931356f78356b001a03f38741 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address1: -------------------------------------------------------------------------------- 1 | 00: 82d818582183581caa5372095aaa680d 2 | 10: 19d4ca496983a145709c3be18b0d4c83 3 | 20: cb7bdc5ea0001a32dc988e 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address2: -------------------------------------------------------------------------------- 1 | 00: 82d818584683581cc6cbc43f74945040 2 | 10: c7a5ed1b0584f7a081dbecfbbcf7a360 3 | 20: 3cfea23ca101582258203665744e6f75 4 | 30: 6958657a4379456a4b63337447346a61 5 | 40: 306b466a4f38717a6169021a2b5c6320 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address3: -------------------------------------------------------------------------------- 1 | 00: 82d818584d83581cbc89030e8b697017 2 | 10: d0725b2c68c3623d77b6a061f46a3d41 3 | 20: 92604e80a20158225820744e6f756958 4 | 30: 657a4379456a4b63337447346a61306b 5 | 40: 466a4f38717a6169323602451a00982e 6 | 50: 0d001a159aca79 7 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Address4: -------------------------------------------------------------------------------- 1 | 00: 82d818582883581c823c60afca103d49 2 | 10: 81978d40b400bdaeb937ae91e2e36f45 3 | 20: 89d6938ba102451a00a98de7001acd66 4 | 30: a453 5 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Attributes: -------------------------------------------------------------------------------- 1 | a0 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/BlockCount: -------------------------------------------------------------------------------- 1 | 1903e7 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/ChainDifficulty: -------------------------------------------------------------------------------- 1 | 8119270f -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/KeyHash: -------------------------------------------------------------------------------- 1 | 00: 581cb4c0e0810a8cd4f5b9249c419007 2 | 10: 04b35ed186205c708a40b5abac90 3 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/Lovelace: -------------------------------------------------------------------------------- 1 | 192604 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/LovelacePortion: -------------------------------------------------------------------------------- 1 | 1925e6 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/MerkleRoot: -------------------------------------------------------------------------------- 1 | 00: 5820c4df3798353de80db323417c513b 2 | 10: 0d647fdac1944f959211b4db35d4bd86 3 | 20: ca28 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/MerkleTree: -------------------------------------------------------------------------------- 1 | 00: 9f582096b23a356c80ba706dbf08c0c2 2 | 10: b205576a6affd6f43b43ba8b7dc53d03 3 | 20: 555938ff 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/TxFeePolicy_Linear: -------------------------------------------------------------------------------- 1 | 00: 8200d81853821b000000170cdc1e001b 2 | 10: 000000b4e8cf1a00 3 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/common/TxSizeLinear: -------------------------------------------------------------------------------- 1 | 00: 821b000000170cdc1e001b000000b4e8 2 | 10: cf1a00 3 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/delegation/Certificate: -------------------------------------------------------------------------------- 1 | 00: 840558404a30754b446269376936644c 2 | 10: 586b756573565a394a6648676a726374 3 | 20: 734c4674324e766f76586e6368734f76 4 | 30: 58303559364c6f686c544e74356d6b50 5 | 40: 4668556f58404b6d7977346c44534535 6 | 50: 53346653483665744e6f756958657a43 7 | 60: 79456a4b63337447346a61306b466a4f 8 | 70: 38717a616932365a4d5055454a664579 9 | 80: 31356f78356b5840feccc189c702707f 10 | 90: 3a71d772559cebaee1a60c0eb99a9c28 11 | a0: f3ad22b6a69db65cdc913016f20133f4 12 | b0: f52f8074b75f7f678cf165f411a53609 13 | c0: 2404c536762f470a 14 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/delegation/DlgPayload: -------------------------------------------------------------------------------- 1 | 000: 9f840558404a30754b44626937693664 2 | 010: 4c586b756573565a394a6648676a7263 3 | 020: 74734c4674324e766f76586e6368734f 4 | 030: 7658303559364c6f686c544e74356d6b 5 | 040: 504668556f58404b6d7977346c445345 6 | 050: 3553346653483665744e6f756958657a 7 | 060: 4379456a4b63337447346a61306b466a 8 | 070: 4f38717a616932365a4d5055454a6645 9 | 080: 7931356f78356b5840feccc189c70270 10 | 090: 7f3a71d772559cebaee1a60c0eb99a9c 11 | 0a0: 28f3ad22b6a69db65cdc913016f20133 12 | 0b0: f4f52f8074b75f7f678cf165f411a536 13 | 0c0: 092404c536762f470a8401584030754b 14 | 0d0: 446269376936644c586b756573565a39 15 | 0e0: 4a6648676a726374734c4674324e766f 16 | 0f0: 76586e6368734f7658303559364c6f68 17 | 100: 6c544e74356d6b504668556f5858406d 18 | 110: 7977346c445345355334665348366574 19 | 120: 4e6f756958657a4379456a4b63337447 20 | 130: 346a61306b466a4f38717a616932365a 21 | 140: 4d5055454a66457931356f78356b4a58 22 | 150: 40806df93d403ae6f4f59017a2f54df5 23 | 160: 2415841f560347627e57752a01b7018b 24 | 170: 57b48f2371e41f06dbd0d24e0d6ab0ba 25 | 180: b19a7042618e32cb06a1e8fe49571e1d 26 | 190: 0a84035840754b446269376936644c58 27 | 1a0: 6b756573565a394a6648676a72637473 28 | 1b0: 4c4674324e766f76586e6368734f7658 29 | 1c0: 303559364c6f686c544e74356d6b5046 30 | 1d0: 68556f587558407977346c4453453553 31 | 1e0: 346653483665744e6f756958657a4379 32 | 1f0: 456a4b63337447346a61306b466a4f38 33 | 200: 717a616932365a4d5055454a66457931 34 | 210: 356f78356b4a3058402a30d99cd24480 35 | 220: 0a5787392fb28983b4cc87037eea6daf 36 | 230: 56131521f7d36a69590182e1781830b1 37 | 240: b87a2925d76f21e29ceb66cf5d337363 38 | 250: cb065a0acecc79480a84181b58404b44 39 | 260: 6269376936644c586b756573565a394a 40 | 270: 6648676a726374734c4674324e766f76 41 | 280: 586e6368734f7658303559364c6f686c 42 | 290: 544e74356d6b504668556f5875315840 43 | 2a0: 77346c4453453553346653483665744e 44 | 2b0: 6f756958657a4379456a4b6333744734 45 | 2c0: 6a61306b466a4f38717a616932365a4d 46 | 2d0: 5055454a66457931356f78356b4a3075 47 | 2e0: 584053d9597483ff6546b67971190786 48 | 2f0: aa053d406c158146e9b6f3eee6567091 49 | 300: 7899394c257bb5f80a413b6e7df19cb7 50 | 310: 0ddf871a8bb521ec8f4bbb5190bd40df 51 | 320: 5006ff 52 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/mempoolpayload/MempoolPayload: -------------------------------------------------------------------------------- 1 | 00: 820082839f8200d81858258258204ba8 2 | 10: 39c420b3d2bd439530f891cae9a5d4c4 3 | 20: d812044630dac72e8e0962feeecc182f 4 | 30: ff9f8282d818582183581caa5372095a 5 | 40: aa680d19d4ca496983a145709c3be18b 6 | 50: 0d4c83cb7bdc5ea0001a32dc988e182f 7 | 60: ffa0818200d81858858258404b6d7977 8 | 70: 346c4453453553346653483665744e6f 9 | 80: 756958657a4379456a4b63337447346a 10 | 90: 61306b466a4f38717a616932365a4d50 11 | a0: 55454a66457931356f78356b5840688a 12 | b0: ad857bc7ff30fc6862da1be281f420c6 13 | c0: 5271b76ab19782ff40e2955af88819c3 14 | d0: 8e5c79138f28073abae152c882258b44 15 | e0: 20a0c1c9fdd26c98812697fc3e00 16 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/mempoolpayload/MempoolPayload1: -------------------------------------------------------------------------------- 1 | 00: 8201840558404a30754b446269376936 2 | 10: 644c586b756573565a394a6648676a72 3 | 20: 6374734c4674324e766f76586e636873 4 | 30: 4f7658303559364c6f686c544e74356d 5 | 40: 6b504668556f58404b6d7977346c4453 6 | 50: 453553346653483665744e6f75695865 7 | 60: 7a4379456a4b63337447346a61306b46 8 | 70: 6a4f38717a616932365a4d5055454a66 9 | 80: 457931356f78356b5840feccc189c702 10 | 90: 707f3a71d772559cebaee1a60c0eb99a 11 | a0: 9c28f3ad22b6a69db65cdc913016f201 12 | b0: 33f4f52f8074b75f7f678cf165f411a5 13 | c0: 36092404c536762f470a 14 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/mempoolpayload/MempoolPayload2: -------------------------------------------------------------------------------- 1 | 000: 820287830101018e811903e7811903e7 2 | 010: 811903e7811903e7811903e7811903e7 3 | 020: 81186381186381186381186381186381 4 | 030: 83186318631863818200d81853821b00 5 | 040: 0000e8990a46001b00000011ed8ec200 6 | 050: 8118638266476f6c64656e1863a5704b 7 | 060: 6d7977346c4453453553346653483684 8 | 070: 582003170a2e7597b7b7e3d84c05391d 9 | 080: 139a62b157e78786d8c082f29dcf4c11 10 | 090: 13145820acf524d17db14b997165a12f 11 | 0a0: 448fd7dddce6b48bb135ef317d5cfabd 12 | 0b0: 98f3318d582003170a2e7597b7b7e3d8 13 | 0c0: 4c05391d139a62b157e78786d8c082f2 14 | 0d0: 9dcf4c111314582003170a2e7597b7b7 15 | 0e0: e3d84c05391d139a62b157e78786d8c0 16 | 0f0: 82f29dcf4c1113147053346653483665 17 | 100: 744e6f756958657a4384582003170a2e 18 | 110: 7597b7b7e3d84c05391d139a62b157e7 19 | 120: 8786d8c082f29dcf4c1113145820cec0 20 | 130: 2b41a5c236069cb3fd3fa658a013e230 21 | 140: 873c2013f783c0504037dc8595875820 22 | 150: 03170a2e7597b7b7e3d84c05391d139a 23 | 160: 62b157e78786d8c082f29dcf4c111314 24 | 170: 582003170a2e7597b7b7e3d84c05391d 25 | 180: 139a62b157e78786d8c082f29dcf4c11 26 | 190: 13147063337447346a61306b466a4f38 27 | 1a0: 717a6184582003170a2e7597b7b7e3d8 28 | 1b0: 4c05391d139a62b157e78786d8c082f2 29 | 1c0: 9dcf4c1113145820e8f357c2f4b5521a 30 | 1d0: e3d23f142abbc681de7dab0f974c1c69 31 | 1e0: 4743e3023d01e29e582003170a2e7597 32 | 1f0: b7b7e3d84c05391d139a62b157e78786 33 | 200: d8c082f29dcf4c111314582003170a2e 34 | 210: 7597b7b7e3d84c05391d139a62b157e7 35 | 220: 8786d8c082f29dcf4c111314706a4f38 36 | 230: 717a616932365a4d5055454a66845820 37 | 240: 03170a2e7597b7b7e3d84c05391d139a 38 | 250: 62b157e78786d8c082f29dcf4c111314 39 | 260: 582060c59bb5bd4926bd84a9bbb9e68d 40 | 270: 90837eef0a70561cd9d1a44b6dcc9507 41 | 280: 994d582003170a2e7597b7b7e3d84c05 42 | 290: 391d139a62b157e78786d8c082f29dcf 43 | 2a0: 4c111314582003170a2e7597b7b7e3d8 44 | 2b0: 4c05391d139a62b157e78786d8c082f2 45 | 2c0: 9dcf4c11131470756958657a4379456a 46 | 2d0: 4b63337447346a84582003170a2e7597 47 | 2e0: b7b7e3d84c05391d139a62b157e78786 48 | 2f0: d8c082f29dcf4c1113145820b8d7c33e 49 | 300: c93a110b459cf5a88edd42165bea75a1 50 | 310: 91080e5ef6d75d114df4d81a58200317 51 | 320: 0a2e7597b7b7e3d84c05391d139a62b1 52 | 330: 57e78786d8c082f29dcf4c1113145820 53 | 340: 03170a2e7597b7b7e3d84c05391d139a 54 | 350: 62b157e78786d8c082f29dcf4c111314 55 | 360: a058404a30754b446269376936644c58 56 | 370: 6b756573565a394a6648676a72637473 57 | 380: 4c4674324e766f76586e6368734f7658 58 | 390: 303559364c6f686c544e74356d6b5046 59 | 3a0: 68556f5840d2af445e7f0f788c9fbd97 60 | 3b0: c18bcd57ecda6661c6c25f8ab75cb859 61 | 3c0: 33f11adb0cedd8a196c8cee2fece7896 62 | 3d0: 10ab20a455ea3cba55e0b383e43d260f 63 | 3e0: e008f3d507 64 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/mempoolpayload/MempoolPayload3: -------------------------------------------------------------------------------- 1 | 00: 82038458404a30754b44626937693664 2 | 10: 4c586b756573565a394a6648676a7263 3 | 20: 74734c4674324e766f76586e6368734f 4 | 30: 7658303559364c6f686c544e74356d6b 5 | 40: 504668556f582072231b8d18d55f6637 6 | 50: 591c2d71fc47a4279cb466fa5059d2eb 7 | 60: bc7c8a1220faecf55840a2dc60724619 8 | 70: 07e681d69bd9e44a885d8d0c76815bfb 9 | 80: a35de178169daaa3927a22d8bf8faeb8 10 | 90: 9094ca9c0f7fda72d816d0072f3a46ee 11 | a0: f82aa19fd9aa83f5fe09 12 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/slotting/EpochAndSlotCount: -------------------------------------------------------------------------------- 1 | 820b182f -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/slotting/EpochNumber: -------------------------------------------------------------------------------- 1 | 0e -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/slotting/EpochSlots: -------------------------------------------------------------------------------- 1 | 1a00073e7b -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/slotting/SlotNumber: -------------------------------------------------------------------------------- 1 | 191389 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/InnerSharesMap: -------------------------------------------------------------------------------- 1 | 000: a4581c1ab7daa1282e1a13d384c5ad64 2 | 010: dee9882bcbf9130e468ed10f27e4d39f 3 | 020: 5863586102ab1997e96af26054b0695f 4 | 030: 94c4429dc87b8aac37c4032da36cae2e 5 | 040: 984a70d29460c1ddeb5de41c9094d0e1 6 | 050: 0e651e22c0c36bcd1b3fdc1240c3f09f 7 | 060: 1b9640a43f415c616fb57bd70b3be61e 8 | 070: 56253f155c7f1a82c98fdabaaeb9ba84 9 | 080: d9f08a6bd6ff581c9190e3e62897bb93 10 | 090: 82465a9f23d9c67cdeb5fdf2b884872a 11 | 0a0: 8f6566df9f58635861034737a48d3ab6 12 | 0b0: 143941a80957ff86e3bb0a892d6d7871 13 | 0c0: 9b57528ac219117c831a73276312fc75 14 | 0d0: e81ce4380455d24a99a415a640adeac4 15 | 0e0: 793046e1e82e5021ece3853cd80c9a3e 16 | 0f0: 0e6443a41bc1eb2decf5ff4d18f85a74 17 | 100: 88d95f7a7f00e8a20a26ff581cae7a5c 18 | 110: c39b05327f0639b381365a647ae15f34 19 | 120: 7bc3e7a8176164ba409f58635861038c 20 | 130: c39619077b95b4e9241455713b8fc18c 21 | 140: b2c7204adaa22cec1a3d7bb633ff686b 22 | 150: b3a7085468c1f37a7f5e6f4fc9e79aa2 23 | 160: d748ffcfe57a5b534cb592ecb978fb07 24 | 170: 21de4f91c6c4690ab23998efca4b75ef 25 | 180: d410820f3b47dced4cb459e6f36f45ff 26 | 190: 581cb4c0e0810a8cd4f5b9249c419007 27 | 1a0: 04b35ed186205c708a40b5abac909f58 28 | 1b0: 63586103d2dd7f247ff1e155b6f39834 29 | 1c0: 3caec1daf7c074889aca7f1240833a94 30 | 1d0: 2f01c15e7c0347c25b299168829d4053 31 | 1e0: a905f995e8f58f0f35d458d205e14e9e 32 | 1f0: 1b9e44554688b71d8c1cee3d31c5071a 33 | 200: fa53e95c307056d188cc890cbf107715 34 | 210: 32b15d35ff 35 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/Opening: -------------------------------------------------------------------------------- 1 | 00: 58235821026a8923b61ed176f49b726f 2 | 10: d5c1c06d0ce7433e3be82030a5c85e54 3 | 20: 8d0b0a3082 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/OpeningsMap: -------------------------------------------------------------------------------- 1 | 00: a1581cb4c0e0810a8cd4f5b9249c4190 2 | 10: 0704b35ed186205c708a40b5abac9058 3 | 20: 235821026a8923b61ed176f49b726fd5 4 | 30: c1c06d0ce7433e3be82030a5c85e548d 5 | 40: 0b0a3082 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SharesMap: -------------------------------------------------------------------------------- 1 | 000: a1581cb4c0e0810a8cd4f5b9249c4190 2 | 010: 0704b35ed186205c708a40b5abac90a4 3 | 020: 581c1ab7daa1282e1a13d384c5ad64de 4 | 030: e9882bcbf9130e468ed10f27e4d39f58 5 | 040: 63586102ab1997e96af26054b0695f94 6 | 050: c4429dc87b8aac37c4032da36cae2e98 7 | 060: 4a70d29460c1ddeb5de41c9094d0e10e 8 | 070: 651e22c0c36bcd1b3fdc1240c3f09f1b 9 | 080: 9640a43f415c616fb57bd70b3be61e56 10 | 090: 253f155c7f1a82c98fdabaaeb9ba84d9 11 | 0a0: f08a6bd6ff581c9190e3e62897bb9382 12 | 0b0: 465a9f23d9c67cdeb5fdf2b884872a8f 13 | 0c0: 6566df9f58635861034737a48d3ab614 14 | 0d0: 3941a80957ff86e3bb0a892d6d78719b 15 | 0e0: 57528ac219117c831a73276312fc75e8 16 | 0f0: 1ce4380455d24a99a415a640adeac479 17 | 100: 3046e1e82e5021ece3853cd80c9a3e0e 18 | 110: 6443a41bc1eb2decf5ff4d18f85a7488 19 | 120: d95f7a7f00e8a20a26ff581cae7a5cc3 20 | 130: 9b05327f0639b381365a647ae15f347b 21 | 140: c3e7a8176164ba409f58635861038cc3 22 | 150: 9619077b95b4e9241455713b8fc18cb2 23 | 160: c7204adaa22cec1a3d7bb633ff686bb3 24 | 170: a7085468c1f37a7f5e6f4fc9e79aa2d7 25 | 180: 48ffcfe57a5b534cb592ecb978fb0721 26 | 190: de4f91c6c4690ab23998efca4b75efd4 27 | 1a0: 10820f3b47dced4cb459e6f36f45ff58 28 | 1b0: 1cb4c0e0810a8cd4f5b9249c41900704 29 | 1c0: b35ed186205c708a40b5abac909f5863 30 | 1d0: 586103d2dd7f247ff1e155b6f398343c 31 | 1e0: aec1daf7c074889aca7f1240833a942f 32 | 1f0: 01c15e7c0347c25b299168829d4053a9 33 | 200: 05f995e8f58f0f35d458d205e14e9e1b 34 | 210: 9e44554688b71d8c1cee3d31c5071afa 35 | 220: 53e95c307056d188cc890cbf10771532 36 | 230: b15d35ff 37 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscPayload_CertificatesPayload: -------------------------------------------------------------------------------- 1 | 000: 8203d90102848458235821024cec5c69 2 | 010: f73122f2dcd6b6f6921655960d3a622e 3 | 020: 002e8a318f6ea4a5cced31c0187a5840 4 | 030: 5c0835d30c015dc9ee745fdf09120aa0 5 | 040: c335766112d1cd1c88fd72e18b7306d0 6 | 050: 27651047a268254d71ec8a8608368b6d 7 | 060: e25d56cad17d65a415489c85df94d602 8 | 070: 5840644c586b756573565a394a664867 9 | 080: 6a726374734c4674324e766f76586e63 10 | 090: 68734f7658303559364c6f686c544e74 11 | 0a0: 356d6b504668556f587531455a534a54 12 | 0b0: 49798458235821034b619e132ab6433b 13 | 0c0: 9a0aa57b1593a7bdea20a58c7d442876 14 | 0d0: 40ce1740dc4f79b9187a584072034302 15 | 0e0: 04e0d8adbdf0fc778a461864757fbdc3 16 | 0f0: 8a34121181edbb69e9d9a15ac06f4079 17 | 100: 72a1c9a19ea0bfe451317018c89d4a7f 18 | 110: d38352083092e63270d1c90e58404674 19 | 120: 324e766f76586e6368734f7658303559 20 | 130: 364c6f686c544e74356d6b504668556f 21 | 140: 587531455a534a544979336654553533 22 | 150: 62343132723441457573443774638458 23 | 160: 235821035df64b0745b7a8c0d92b7f45 24 | 170: 68c7870f9a3eb380da5831d71d86de04 25 | 180: 4cfa4d4d187a5840a886c42070ac836a 26 | 190: 292800ed75f5acabf9a9d768ed91ae80 27 | 1a0: c2fcf065e5f66377f5dca619e4d100fa 28 | 1b0: cf4d8778c4472da22232617ab4740ff7 29 | 1c0: 1acdc5eb0c4fed0b58404a30754b4462 30 | 1d0: 69376936644c586b756573565a394a66 31 | 1e0: 48676a726374734c4674324e766f7658 32 | 1f0: 6e6368734f7658303559364c6f686c54 33 | 200: 4e74356d6b504668556f845823582103 34 | 210: 7250bc3932b5b5f6c42774eef3c06ea7 35 | 220: b7f13686e83d6ff9ec316459a6373682 36 | 230: 187a584024319a81ec9754e293e99e20 37 | 240: 03706f86b1bc98c318abac8c1e3488cc 38 | 250: 7b24ef80e6c3569f948e8f51fe66848c 39 | 260: 609d38294e814809976997396e968039 40 | 270: 4d8e920058404a6648676a726374734c 41 | 280: 4674324e766f76586e6368734f765830 42 | 290: 3559364c6f686c544e74356d6b504668 43 | 2a0: 556f587531455a534a54497933665455 44 | 2b0: 353362343132 45 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscPayload_OpeningsPayload: -------------------------------------------------------------------------------- 1 | 000: 8301a1581cb4c0e0810a8cd4f5b9249c 2 | 010: 41900704b35ed186205c708a40b5abac 3 | 020: 9058235821026a8923b61ed176f49b72 4 | 030: 6fd5c1c06d0ce7433e3be82030a5c85e 5 | 040: 548d0b0a3082d9010284845823582102 6 | 050: 4cec5c69f73122f2dcd6b6f692165596 7 | 060: 0d3a622e002e8a318f6ea4a5cced31c0 8 | 070: 187a58405c0835d30c015dc9ee745fdf 9 | 080: 09120aa0c335766112d1cd1c88fd72e1 10 | 090: 8b7306d027651047a268254d71ec8a86 11 | 0a0: 08368b6de25d56cad17d65a415489c85 12 | 0b0: df94d6025840644c586b756573565a39 13 | 0c0: 4a6648676a726374734c4674324e766f 14 | 0d0: 76586e6368734f7658303559364c6f68 15 | 0e0: 6c544e74356d6b504668556f58753145 16 | 0f0: 5a534a5449798458235821034b619e13 17 | 100: 2ab6433b9a0aa57b1593a7bdea20a58c 18 | 110: 7d44287640ce1740dc4f79b9187a5840 19 | 120: 7203430204e0d8adbdf0fc778a461864 20 | 130: 757fbdc38a34121181edbb69e9d9a15a 21 | 140: c06f407972a1c9a19ea0bfe451317018 22 | 150: c89d4a7fd38352083092e63270d1c90e 23 | 160: 58404674324e766f76586e6368734f76 24 | 170: 58303559364c6f686c544e74356d6b50 25 | 180: 4668556f587531455a534a5449793366 26 | 190: 54553533623431327234414575734437 27 | 1a0: 74638458235821035df64b0745b7a8c0 28 | 1b0: d92b7f4568c7870f9a3eb380da5831d7 29 | 1c0: 1d86de044cfa4d4d187a5840a886c420 30 | 1d0: 70ac836a292800ed75f5acabf9a9d768 31 | 1e0: ed91ae80c2fcf065e5f66377f5dca619 32 | 1f0: e4d100facf4d8778c4472da22232617a 33 | 200: b4740ff71acdc5eb0c4fed0b58404a30 34 | 210: 754b446269376936644c586b75657356 35 | 220: 5a394a6648676a726374734c4674324e 36 | 230: 766f76586e6368734f7658303559364c 37 | 240: 6f686c544e74356d6b504668556f8458 38 | 250: 235821037250bc3932b5b5f6c42774ee 39 | 260: f3c06ea7b7f13686e83d6ff9ec316459 40 | 270: a6373682187a584024319a81ec9754e2 41 | 280: 93e99e2003706f86b1bc98c318abac8c 42 | 290: 1e3488cc7b24ef80e6c3569f948e8f51 43 | 2a0: fe66848c609d38294e81480997699739 44 | 2b0: 6e9680394d8e920058404a6648676a72 45 | 2c0: 6374734c4674324e766f76586e636873 46 | 2d0: 4f7658303559364c6f686c544e74356d 47 | 2e0: 6b504668556f587531455a534a544979 48 | 2f0: 33665455353362343132 49 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscProof_CertificatesProof: -------------------------------------------------------------------------------- 1 | 00: 820358209fbbb2f0eff7472fe19e462f 2 | 10: d88c495ac90f9ad58c4dd6cb20451571 3 | 20: 0b0fe132 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscProof_CommitmentsProof: -------------------------------------------------------------------------------- 1 | 00: 83005820006a4a2b269afe61e8947016 2 | 10: 40d1ca59639d92af3095814f9836143b 3 | 20: d5d40b9658209fbbb2f0eff7472fe19e 4 | 30: 462fd88c495ac90f9ad58c4dd6cb2045 5 | 40: 15710b0fe132 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscProof_OpeningsProof: -------------------------------------------------------------------------------- 1 | 00: 83015820e75dc94529c2f52566e90bdf 2 | 10: 77ed9498399f8055601459f19334dbba 3 | 20: 13bc9f3a58209fbbb2f0eff7472fe19e 4 | 30: 462fd88c495ac90f9ad58c4dd6cb2045 5 | 40: 15710b0fe132 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/SscProof_SharesProof: -------------------------------------------------------------------------------- 1 | 00: 83025820a527895dddc33efd501bb971 2 | 10: 7682036653eeb6c6c1c403225e13db44 3 | 20: 6c24404d58209fbbb2f0eff7472fe19e 4 | 30: 462fd88c495ac90f9ad58c4dd6cb2045 5 | 40: 15710b0fe132 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/VssCertificate: -------------------------------------------------------------------------------- 1 | 00: 845823582103e5bb5c7fcea0440ba972 2 | 10: f98efffc38927db6c79d5b92d9ea41ec 3 | 20: f8ca10c32a310b58408a71f0f263c8c3 4 | 30: d8cc25a013b47d1a9535e8521fcdee95 5 | 40: 4ef552c894f482f7f9ad0ea977259ca4 6 | 50: 9a4dde3cd74421ccf2902fb4d02b3507 7 | 60: b040447f0bd724300e5840644c586b75 8 | 70: 6573565a394a6648676a726374734c46 9 | 80: 74324e766f76586e6368734f76583035 10 | 90: 59364c6f686c544e74356d6b50466855 11 | a0: 6f587531455a534a544979 12 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/VssCertificatesHash: -------------------------------------------------------------------------------- 1 | 00: 58209fbbb2f0eff7472fe19e462fd88c 2 | 10: 495ac90f9ad58c4dd6cb204515710b0f 3 | 20: e132 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/ssc/VssCertificatesMap: -------------------------------------------------------------------------------- 1 | 000: d90102848458235821024cec5c69f731 2 | 010: 22f2dcd6b6f6921655960d3a622e002e 3 | 020: 8a318f6ea4a5cced31c0187a58405c08 4 | 030: 35d30c015dc9ee745fdf09120aa0c335 5 | 040: 766112d1cd1c88fd72e18b7306d02765 6 | 050: 1047a268254d71ec8a8608368b6de25d 7 | 060: 56cad17d65a415489c85df94d6025840 8 | 070: 644c586b756573565a394a6648676a72 9 | 080: 6374734c4674324e766f76586e636873 10 | 090: 4f7658303559364c6f686c544e74356d 11 | 0a0: 6b504668556f587531455a534a544979 12 | 0b0: 8458235821034b619e132ab6433b9a0a 13 | 0c0: a57b1593a7bdea20a58c7d44287640ce 14 | 0d0: 1740dc4f79b9187a58407203430204e0 15 | 0e0: d8adbdf0fc778a461864757fbdc38a34 16 | 0f0: 121181edbb69e9d9a15ac06f407972a1 17 | 100: c9a19ea0bfe451317018c89d4a7fd383 18 | 110: 52083092e63270d1c90e58404674324e 19 | 120: 766f76586e6368734f7658303559364c 20 | 130: 6f686c544e74356d6b504668556f5875 21 | 140: 31455a534a5449793366545535336234 22 | 150: 31327234414575734437746384582358 23 | 160: 21035df64b0745b7a8c0d92b7f4568c7 24 | 170: 870f9a3eb380da5831d71d86de044cfa 25 | 180: 4d4d187a5840a886c42070ac836a2928 26 | 190: 00ed75f5acabf9a9d768ed91ae80c2fc 27 | 1a0: f065e5f66377f5dca619e4d100facf4d 28 | 1b0: 8778c4472da22232617ab4740ff71acd 29 | 1c0: c5eb0c4fed0b58404a30754b44626937 30 | 1d0: 6936644c586b756573565a394a664867 31 | 1e0: 6a726374734c4674324e766f76586e63 32 | 1f0: 68734f7658303559364c6f686c544e74 33 | 200: 356d6b504668556f8458235821037250 34 | 210: bc3932b5b5f6c42774eef3c06ea7b7f1 35 | 220: 3686e83d6ff9ec316459a6373682187a 36 | 230: 584024319a81ec9754e293e99e200370 37 | 240: 6f86b1bc98c318abac8c1e3488cc7b24 38 | 250: ef80e6c3569f948e8f51fe66848c609d 39 | 260: 38294e814809976997396e9680394d8e 40 | 270: 920058404a6648676a726374734c4674 41 | 280: 324e766f76586e6368734f7658303559 42 | 290: 364c6f686c544e74356d6b504668556f 43 | 2a0: 587531455a534a544979336654553533 44 | 2b0: 62343132 45 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/ApplicationName: -------------------------------------------------------------------------------- 1 | 66476f6c64656e -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/AttackTarget_NetworkAddressTarget: -------------------------------------------------------------------------------- 1 | {"Network":"ggv:32313"} -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/AttackTarget_PubKeyAddressTarget: -------------------------------------------------------------------------------- 1 | {"PubKey":"cae922c720ea93e5ead49b4652fb24caf4948e31eee378a4c4513f11"} -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/BlockHeader_Boundary: -------------------------------------------------------------------------------- 1 | 00: 820085005820f7077d40c94a36e7df95 2 | 10: b6f99a86f08bcf06ea3b24e68dd30393 3 | 20: 33fa5314177558204965a00c5a47c387 4 | 30: 733985445c24dc988b36e4fcd8db638e 5 | 40: c28a23ae4773ca60820b810081a0 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/CommitmentSignature: -------------------------------------------------------------------------------- 1 | 00: 58407803232dd492dacd3c0f7c5401a5 2 | 10: 77a4bfa2891cf5c9da07134ac2414522 3 | 20: c51b397e183602768910747ca3f2e065 4 | 30: f14a625b278cc2d8b3bca5bae84bbab6 5 | 40: bb03 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/HashRaw: -------------------------------------------------------------------------------- 1 | 00: 582096b23a356c80ba706dbf08c0c2b2 2 | 10: 05576a6affd6f43b43ba8b7dc53d0355 3 | 20: 5938 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/HashTx: -------------------------------------------------------------------------------- 1 | 00: 58204ba839c420b3d2bd439530f891ca 2 | 10: e9a5d4c4d812044630dac72e8e0962fe 3 | 20: eecc 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/InstallerHash: -------------------------------------------------------------------------------- 1 | 00: 84582003170a2e7597b7b7e3d84c0539 2 | 10: 1d139a62b157e78786d8c082f29dcf4c 3 | 20: 1113145820cec02b41a5c236069cb3fd 4 | 30: 3fa658a013e230873c2013f783c05040 5 | 40: 37dc859587582003170a2e7597b7b7e3 6 | 50: d84c05391d139a62b157e78786d8c082 7 | 60: f29dcf4c111314582003170a2e7597b7 8 | 70: b7e3d84c05391d139a62b157e78786d8 9 | 80: c082f29dcf4c111314 10 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/Proof: -------------------------------------------------------------------------------- 1 | 00: 5820adfd9b4aa5620d4b0a0587186e68 2 | 10: 28efa789b2582eef698523a308d6f3ed 3 | 20: d940 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/Proposal: -------------------------------------------------------------------------------- 1 | 000: 87830101018e811903e7811903e78119 2 | 010: 03e7811903e7811903e7811903e78118 3 | 020: 63811863811863811863811863818318 4 | 030: 6318631863818200d81853821b000000 5 | 040: e8990a46001b00000011ed8ec2008118 6 | 050: 638266476f6c64656e1863a5704b6d79 7 | 060: 77346c44534535533466534836845820 8 | 070: 03170a2e7597b7b7e3d84c05391d139a 9 | 080: 62b157e78786d8c082f29dcf4c111314 10 | 090: 5820acf524d17db14b997165a12f448f 11 | 0a0: d7dddce6b48bb135ef317d5cfabd98f3 12 | 0b0: 318d582003170a2e7597b7b7e3d84c05 13 | 0c0: 391d139a62b157e78786d8c082f29dcf 14 | 0d0: 4c111314582003170a2e7597b7b7e3d8 15 | 0e0: 4c05391d139a62b157e78786d8c082f2 16 | 0f0: 9dcf4c1113147053346653483665744e 17 | 100: 6f756958657a4384582003170a2e7597 18 | 110: b7b7e3d84c05391d139a62b157e78786 19 | 120: d8c082f29dcf4c1113145820cec02b41 20 | 130: a5c236069cb3fd3fa658a013e230873c 21 | 140: 2013f783c0504037dc85958758200317 22 | 150: 0a2e7597b7b7e3d84c05391d139a62b1 23 | 160: 57e78786d8c082f29dcf4c1113145820 24 | 170: 03170a2e7597b7b7e3d84c05391d139a 25 | 180: 62b157e78786d8c082f29dcf4c111314 26 | 190: 7063337447346a61306b466a4f38717a 27 | 1a0: 6184582003170a2e7597b7b7e3d84c05 28 | 1b0: 391d139a62b157e78786d8c082f29dcf 29 | 1c0: 4c1113145820e8f357c2f4b5521ae3d2 30 | 1d0: 3f142abbc681de7dab0f974c1c694743 31 | 1e0: e3023d01e29e582003170a2e7597b7b7 32 | 1f0: e3d84c05391d139a62b157e78786d8c0 33 | 200: 82f29dcf4c111314582003170a2e7597 34 | 210: b7b7e3d84c05391d139a62b157e78786 35 | 220: d8c082f29dcf4c111314706a4f38717a 36 | 230: 616932365a4d5055454a668458200317 37 | 240: 0a2e7597b7b7e3d84c05391d139a62b1 38 | 250: 57e78786d8c082f29dcf4c1113145820 39 | 260: 60c59bb5bd4926bd84a9bbb9e68d9083 40 | 270: 7eef0a70561cd9d1a44b6dcc9507994d 41 | 280: 582003170a2e7597b7b7e3d84c05391d 42 | 290: 139a62b157e78786d8c082f29dcf4c11 43 | 2a0: 1314582003170a2e7597b7b7e3d84c05 44 | 2b0: 391d139a62b157e78786d8c082f29dcf 45 | 2c0: 4c11131470756958657a4379456a4b63 46 | 2d0: 337447346a84582003170a2e7597b7b7 47 | 2e0: e3d84c05391d139a62b157e78786d8c0 48 | 2f0: 82f29dcf4c1113145820b8d7c33ec93a 49 | 300: 110b459cf5a88edd42165bea75a19108 50 | 310: 0e5ef6d75d114df4d81a582003170a2e 51 | 320: 7597b7b7e3d84c05391d139a62b157e7 52 | 330: 8786d8c082f29dcf4c11131458200317 53 | 340: 0a2e7597b7b7e3d84c05391d139a62b1 54 | 350: 57e78786d8c082f29dcf4c111314a058 55 | 360: 404a30754b446269376936644c586b75 56 | 370: 6573565a394a6648676a726374734c46 57 | 380: 74324e766f76586e6368734f76583035 58 | 390: 59364c6f686c544e74356d6b50466855 59 | 3a0: 6f5840d2af445e7f0f788c9fbd97c18b 60 | 3b0: cd57ecda6661c6c25f8ab75cb85933f1 61 | 3c0: 1adb0cedd8a196c8cee2fece789610ab 62 | 3d0: 20a455ea3cba55e0b383e43d260fe008 63 | 3e0: f3d507 64 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/ProposalBody: -------------------------------------------------------------------------------- 1 | 000: 85830101018e811903e7811903e78119 2 | 010: 03e7811903e7811903e7811903e78118 3 | 020: 63811863811863811863811863818318 4 | 030: 6318631863818200d81853821b000000 5 | 040: e8990a46001b00000011ed8ec2008118 6 | 050: 638266476f6c64656e1863a5704b6d79 7 | 060: 77346c44534535533466534836845820 8 | 070: 03170a2e7597b7b7e3d84c05391d139a 9 | 080: 62b157e78786d8c082f29dcf4c111314 10 | 090: 5820acf524d17db14b997165a12f448f 11 | 0a0: d7dddce6b48bb135ef317d5cfabd98f3 12 | 0b0: 318d582003170a2e7597b7b7e3d84c05 13 | 0c0: 391d139a62b157e78786d8c082f29dcf 14 | 0d0: 4c111314582003170a2e7597b7b7e3d8 15 | 0e0: 4c05391d139a62b157e78786d8c082f2 16 | 0f0: 9dcf4c1113147053346653483665744e 17 | 100: 6f756958657a4384582003170a2e7597 18 | 110: b7b7e3d84c05391d139a62b157e78786 19 | 120: d8c082f29dcf4c1113145820cec02b41 20 | 130: a5c236069cb3fd3fa658a013e230873c 21 | 140: 2013f783c0504037dc85958758200317 22 | 150: 0a2e7597b7b7e3d84c05391d139a62b1 23 | 160: 57e78786d8c082f29dcf4c1113145820 24 | 170: 03170a2e7597b7b7e3d84c05391d139a 25 | 180: 62b157e78786d8c082f29dcf4c111314 26 | 190: 7063337447346a61306b466a4f38717a 27 | 1a0: 6184582003170a2e7597b7b7e3d84c05 28 | 1b0: 391d139a62b157e78786d8c082f29dcf 29 | 1c0: 4c1113145820e8f357c2f4b5521ae3d2 30 | 1d0: 3f142abbc681de7dab0f974c1c694743 31 | 1e0: e3023d01e29e582003170a2e7597b7b7 32 | 1f0: e3d84c05391d139a62b157e78786d8c0 33 | 200: 82f29dcf4c111314582003170a2e7597 34 | 210: b7b7e3d84c05391d139a62b157e78786 35 | 220: d8c082f29dcf4c111314706a4f38717a 36 | 230: 616932365a4d5055454a668458200317 37 | 240: 0a2e7597b7b7e3d84c05391d139a62b1 38 | 250: 57e78786d8c082f29dcf4c1113145820 39 | 260: 60c59bb5bd4926bd84a9bbb9e68d9083 40 | 270: 7eef0a70561cd9d1a44b6dcc9507994d 41 | 280: 582003170a2e7597b7b7e3d84c05391d 42 | 290: 139a62b157e78786d8c082f29dcf4c11 43 | 2a0: 1314582003170a2e7597b7b7e3d84c05 44 | 2b0: 391d139a62b157e78786d8c082f29dcf 45 | 2c0: 4c11131470756958657a4379456a4b63 46 | 2d0: 337447346a84582003170a2e7597b7b7 47 | 2e0: e3d84c05391d139a62b157e78786d8c0 48 | 2f0: 82f29dcf4c1113145820b8d7c33ec93a 49 | 300: 110b459cf5a88edd42165bea75a19108 50 | 310: 0e5ef6d75d114df4d81a582003170a2e 51 | 320: 7597b7b7e3d84c05391d139a62b157e7 52 | 330: 8786d8c082f29dcf4c11131458200317 53 | 340: 0a2e7597b7b7e3d84c05391d139a62b1 54 | 350: 57e78786d8c082f29dcf4c111314a0 55 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/ProtocolParameters: -------------------------------------------------------------------------------- 1 | 00: 8e1903e71903e71903e71903e71903e7 2 | 10: 1903e718631863186318631863831863 3 | 20: 186318638200d81853821b000000e899 4 | 30: 0a46001b00000011ed8ec2001863 5 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/ProtocolParametersUpdate: -------------------------------------------------------------------------------- 1 | 00: 8e811903e7811903e7811903e7811903 2 | 10: e7811903e7811903e781186381186381 3 | 20: 18638118638118638183186318631863 4 | 30: 818200d81853821b000000e8990a4600 5 | 40: 1b00000011ed8ec200811863 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/ProtocolVersion: -------------------------------------------------------------------------------- 1 | 83010101 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/SharesDistribution: -------------------------------------------------------------------------------- 1 | 00: a1581c5125b558daa14b5338e904cc2a 2 | 10: 75a8b7b3a4738de9cb28a6819576db19 3 | 20: 0539 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/SoftforkRule: -------------------------------------------------------------------------------- 1 | 83186318631863 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/SoftwareVersion: -------------------------------------------------------------------------------- 1 | 8266476f6c64656e1863 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/StaticConfig_GCSpec: -------------------------------------------------------------------------------- 1 | {"spec":{"avvmDistr":{"dtXbK7ASFLEa611AHt7SDk_48fVbNja-Tj7PgbE7tPE=":37343863242999412,"U4lgqRZyawnwXJ1NSpIrhbThGs_MFDRnPZUBm3qaUtI=":36524597913081152},"ftsSeed":"RTVTNGZTSDZldE5vdWlYZXpDeUVqS2MzdEc0amEwa0Y=","heavyDelegation":{"ed41bf35f4cd2109bdee27b0439942f6de3f55f0ac8d170de7136d3d":{"pskDelegatePk":"3cppv+rBTAEzBNqIrAMu5jKBqwNsGxuRiOSxdLMD9D5VFjsXjpmbn9UGN7Ltq4yFioeaw8S9PmEAlUGaGWllcw==","pskOmega":68300481033,"pskCert":"bae5422af5405e3803154a4ad986da5d14cf624d6701c5c78a79ec73777f74e13973af83752114d9f18166085997fc81e432cab7fee99a275d8bf138ad04e103","pskIssuerPk":"4qF3OiqC0QwwiQy/hOzL3Bqq7pIElkJNNuhoA52ctRkhsl7+Az2bANTwLM2c2rzsMyq7xv34g8pb86iv9KrCfg=="}},"blockVersionData":{"scriptVersion":999,"slotDuration":999,"maxBlockSize":999,"maxHeaderSize":999,"maxTxSize":999,"maxProposalSize":999,"mpcThd":9.9e-14,"heavyDelThd":9.9e-14,"updateVoteThd":9.9e-14,"updateProposalThd":9.9e-14,"updateImplicit":99,"softforkRule":{"initThd":9.9e-14,"minThd":9.9e-14,"thdDecrement":9.9e-14},"txFeePolicy":{"txSizeLinear":{"a":9.99e-7,"b":7.7e-8}},"unlockStakeEpoch":99},"protocolConstants":{"k":37,"protocolMagic":1783847074,"vssMaxTTL":1477558317,"vssMinTTL":744040476},"initializer":{"testBalance":{"poors":2448641325904532856,"richmen":14071205313513960321,"totalBalance":10953275486128625216,"richmenShare":4.2098713311249885,"useHDAddresses":true},"fakeAvvmBalance":{"count":17853231730478779264,"oneBalance":15087947214890024355},"avvmBalanceFactor":0.366832547637728,"useHeavyDlg":false,"seed":0}}} -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/StaticConfig_GCSrc: -------------------------------------------------------------------------------- 1 | {"src":{"file":"dRaMwdYsH3QA3dChe","hash":"bc9a1c2d86ddf023a39d8ae0abaf209fe4a95a3741cb99ecc0f011b48a5b69b9"}} -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/SystemTag: -------------------------------------------------------------------------------- 1 | 00: 704b6d7977346c445345355334665348 2 | 10: 36 3 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/UpId: -------------------------------------------------------------------------------- 1 | 00: 582072231b8d18d55f6637591c2d71fc 2 | 10: 47a4279cb466fa5059d2ebbc7c8a1220 3 | 20: faec 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/update/Vote: -------------------------------------------------------------------------------- 1 | 00: 8458404a30754b446269376936644c58 2 | 10: 6b756573565a394a6648676a72637473 3 | 20: 4c4674324e766f76586e6368734f7658 4 | 30: 303559364c6f686c544e74356d6b5046 5 | 40: 68556f582072231b8d18d55f6637591c 6 | 50: 2d71fc47a4279cb466fa5059d2ebbc7c 7 | 60: 8a1220faecf55840a2dc6072461907e6 8 | 70: 81d69bd9e44a885d8d0c76815bfba35d 9 | 80: e178169daaa3927a22d8bf8faeb89094 10 | 90: ca9c0f7fda72d816d0072f3a46eef82a 11 | a0: a19fd9aa83f5fe09 12 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/HashTx: -------------------------------------------------------------------------------- 1 | 00: 58204ba839c420b3d2bd439530f891ca 2 | 10: e9a5d4c4d812044630dac72e8e0962fe 3 | 20: eecc 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/Tx: -------------------------------------------------------------------------------- 1 | 00: 839f8200d81858258258204ba839c420 2 | 10: b3d2bd439530f891cae9a5d4c4d81204 3 | 20: 4630dac72e8e0962feeecc182fff9f82 4 | 30: 82d818582183581caa5372095aaa680d 5 | 40: 19d4ca496983a145709c3be18b0d4c83 6 | 50: cb7bdc5ea0001a32dc988e182fffa0 7 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxAttributes: -------------------------------------------------------------------------------- 1 | a0 -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxId: -------------------------------------------------------------------------------- 1 | 00: 58204ba839c420b3d2bd439530f891ca 2 | 10: e9a5d4c4d812044630dac72e8e0962fe 3 | 20: eecc 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxInList: -------------------------------------------------------------------------------- 1 | 00: 9f8200d81858258258204ba839c420b3 2 | 10: d2bd439530f891cae9a5d4c4d8120446 3 | 20: 30dac72e8e0962feeecc182fff 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxInWitness_RedeemWitness: -------------------------------------------------------------------------------- 1 | 00: 8202d8185865825820538960a916726b 2 | 10: 09f05c9d4d4a922b85b4e11acfcc1434 3 | 20: 673d95019b7a9a52d258407d1479e7fd 4 | 30: d86a35eed51654fe5b3a76d12184eb5d 5 | 40: 9be8a455981479369537393b99b1cdaf 6 | 50: 2ec70c8fa60bd25dfd71fa206ef686a2 7 | 60: 8b195fe78583648e8fb10b 8 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxInWitness_VKWitness: -------------------------------------------------------------------------------- 1 | 00: 8200d81858858258404b6d7977346c44 2 | 10: 53453553346653483665744e6f756958 3 | 20: 657a4379456a4b63337447346a61306b 4 | 30: 466a4f38717a616932365a4d5055454a 5 | 40: 66457931356f78356b5840688aad857b 6 | 50: c7ff30fc6862da1be281f420c65271b7 7 | 60: 6ab19782ff40e2955af88819c38e5c79 8 | 70: 138f28073abae152c882258b4420a0c1 9 | 80: c9fdd26c98812697fc3e00 10 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxIn_Utxo: -------------------------------------------------------------------------------- 1 | 00: 8200d81858258258204ba839c420b3d2 2 | 10: bd439530f891cae9a5d4c4d812044630 3 | 20: dac72e8e0962feeecc182f 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxOut: -------------------------------------------------------------------------------- 1 | 00: 8282d818582183581caa5372095aaa68 2 | 10: 0d19d4ca496983a145709c3be18b0d4c 3 | 20: 83cb7bdc5ea0001a32dc988e182f 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxOut1: -------------------------------------------------------------------------------- 1 | 00: 8282d818582583581cec106f4355a6f2 2 | 10: b276aa9cf9f21a06cfac2400035bef6e 3 | 20: 1dc19eab42a10242184a001a7017fe5d 4 | 30: 182f 5 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxOutList: -------------------------------------------------------------------------------- 1 | 00: 9f8282d818582183581caa5372095aaa 2 | 10: 680d19d4ca496983a145709c3be18b0d 3 | 20: 4c83cb7bdc5ea0001a32dc988e182fff 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxOutList1: -------------------------------------------------------------------------------- 1 | 00: 9f8282d818582183581caa5372095aaa 2 | 10: 680d19d4ca496983a145709c3be18b0d 3 | 20: 4c83cb7bdc5ea0001a32dc988e182fff 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxPayload1: -------------------------------------------------------------------------------- 1 | 000: 9f82839f8200d81858258258204ba839 2 | 010: c420b3d2bd439530f891cae9a5d4c4d8 3 | 020: 12044630dac72e8e0962feeecc182fff 4 | 030: 9f8282d818582183581caa5372095aaa 5 | 040: 680d19d4ca496983a145709c3be18b0d 6 | 050: 4c83cb7bdc5ea0001a32dc988e182fff 7 | 060: a0818200d81858858258404b6d797734 8 | 070: 6c4453453553346653483665744e6f75 9 | 080: 6958657a4379456a4b63337447346a61 10 | 090: 306b466a4f38717a616932365a4d5055 11 | 0a0: 454a66457931356f78356b5840688aad 12 | 0b0: 857bc7ff30fc6862da1be281f420c652 13 | 0c0: 71b76ab19782ff40e2955af88819c38e 14 | 0d0: 5c79138f28073abae152c882258b4420 15 | 0e0: a0c1c9fdd26c98812697fc3e0082839f 16 | 0f0: 8200d81858258258204ba839c420b3d2 17 | 100: bd439530f891cae9a5d4c4d812044630 18 | 110: dac72e8e0962feeecc182f8200d81858 19 | 120: 258258204ba839c420b3d2bd439530f8 20 | 130: 91cae9a5d4c4d812044630dac72e8e09 21 | 140: 62feeecc184aff9f8282d81858218358 22 | 150: 1caa5372095aaa680d19d4ca496983a1 23 | 160: 45709c3be18b0d4c83cb7bdc5ea0001a 24 | 170: 32dc988e182f8282d818582583581cec 25 | 180: 106f4355a6f2b276aa9cf9f21a06cfac 26 | 190: 2400035bef6e1dc19eab42a10242184a 27 | 1a0: 001a7017fe5d182fffa0818200d81858 28 | 1b0: 858258404b6d7977346c445345355334 29 | 1c0: 6653483665744e6f756958657a437945 30 | 1d0: 6a4b63337447346a61306b466a4f3871 31 | 1e0: 7a616932365a4d5055454a6645793135 32 | 1f0: 6f78356b5840688aad857bc7ff30fc68 33 | 200: 62da1be281f420c65271b76ab19782ff 34 | 210: 40e2955af88819c38e5c79138f28073a 35 | 220: bae152c882258b4420a0c1c9fdd26c98 36 | 230: 812697fc3e00ff 37 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxProof: -------------------------------------------------------------------------------- 1 | 00: 83182058205e46ceb20538afeeb45cb8 2 | 10: f7030512af34b4ff363a8c7e94d441a2 3 | 20: 57500ffab75820e32c9549bc3acbe0e8 4 | 30: 48b2d7ad26331b7d8497580364cb2bc6 5 | 40: c8bda9aa0975b8 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxSig: -------------------------------------------------------------------------------- 1 | 00: 5840688aad857bc7ff30fc6862da1be2 2 | 10: 81f420c65271b76ab19782ff40e2955a 3 | 20: f88819c38e5c79138f28073abae152c8 4 | 30: 82258b4420a0c1c9fdd26c98812697fc 5 | 40: 3e00 6 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxSigData: -------------------------------------------------------------------------------- 1 | 00: 58204ba839c420b3d2bd439530f891ca 2 | 10: e9a5d4c4d812044630dac72e8e0962fe 3 | 20: eecc 4 | -------------------------------------------------------------------------------- /cardano-ledger/test/golden/cbor/utxo/TxWitness: -------------------------------------------------------------------------------- 1 | 00: 818200d81858858258404b6d7977346c 2 | 10: 4453453553346653483665744e6f7569 3 | 20: 58657a4379456a4b63337447346a6130 4 | 30: 6b466a4f38717a616932365a4d505545 5 | 40: 4a66457931356f78356b5840688aad85 6 | 50: 7bc7ff30fc6862da1be281f420c65271 7 | 60: b76ab19782ff40e2955af88819c38e5c 8 | 70: 79138f28073abae152c882258b4420a0 9 | 80: c1c9fdd26c98812697fc3e00 10 | -------------------------------------------------------------------------------- /ci/check-hydra.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | eval "$(nix-build -A check-hydra lib.nix --no-out-link)" 4 | -------------------------------------------------------------------------------- /configuration/log-configuration.yaml: -------------------------------------------------------------------------------- 1 | # global filter; messages must have at least this severity to pass: 2 | minSeverity: Debug 3 | 4 | # global file rotation settings: 5 | rotation: 6 | rpLogLimitBytes: 5000000 7 | rpKeepFilesNum: 10 8 | rpMaxAgeHours: 24 9 | 10 | # these backends are initialized: 11 | setupBackends: 12 | - AggregationBK 13 | - EKGViewBK 14 | - KatipBK 15 | - EditorBK 16 | 17 | # if not indicated otherwise, then messages are passed to these backends: 18 | defaultBackends: 19 | - KatipBK 20 | 21 | # if wanted, the GUI is listening on this port: 22 | hasGUI: 12787 23 | 24 | # if wanted, the EKG interface is listening on this port: 25 | hasEKG: 12788 26 | 27 | # here we set up outputs of logging in 'katip': 28 | setupScribes: 29 | - scKind: StdoutSK 30 | scName: stdout 31 | scFormat: ScText 32 | scRotation: null 33 | 34 | # if not indicated otherwise, then log output is directed to this: 35 | defaultScribes: 36 | - - StdoutSK 37 | - stdout 38 | 39 | # more options which can be passed as key-value pairs: 40 | options: 41 | cfokey: 42 | value: "Release-1.0.0" 43 | mapSubtrace: 44 | '#messagecounters.aggregation': 45 | subtrace: NoTrace 46 | '#messagecounters.ekgview': 47 | subtrace: NoTrace 48 | '#messagecounters.katip': 49 | subtrace: NoTrace 50 | '#messagecounters.switchboard': 51 | subtrace: NoTrace 52 | benchmark: 53 | contents: 54 | - MonotonicClock 55 | #- GhcRtsStats 56 | subtrace: ObservableTrace 57 | '#ekgview': 58 | contents: 59 | - - tag: Contains 60 | contents: 'cardano.epoch-validation.benchmark' 61 | - - tag: Contains 62 | contents: 'diff.Clock.monoclock.basic' 63 | subtrace: FilterTrace 64 | 'cardano.epoch-validation.utxo-stats': 65 | # Change the `subtrace` value to `Neutral` in order to log 66 | # `UTxO`-related messages during epoch validation. 67 | subtrace: NoTrace 68 | mapBackends: 69 | cardano.epoch-validation.benchmark: 70 | - AggregationBK 71 | '#aggregation.cardano.epoch-validation.benchmark': 72 | - EKGViewBK 73 | 74 | -------------------------------------------------------------------------------- /crypto/README.md: -------------------------------------------------------------------------------- 1 | # cardano-crypto-wrapper 2 | 3 | The cryptographic primitives used in Cardano 4 | 5 | * Cryptographic hashing, using the [cryptonite] library. 6 | 7 | * Secure generation of cryptographically random numbers and `ByteString`s. 8 | 9 | * Hierarchical derivation functionality for Hierarchical Deterministic key 10 | creation, for the wallet. 11 | 12 | * Cryptographic signing and signature checking. 13 | 14 | * `To/FromCBOR` (see the `cardano-binary` package) instances for the 15 | cryptographic data types. 16 | 17 | [cryptonite]: https://hackage.haskell.org/package/cryptonite 18 | -------------------------------------------------------------------------------- /crypto/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Crypto.Hashing as X 7 | import Cardano.Crypto.ProtocolMagic as X 8 | import Cardano.Crypto.Random as X 9 | import Cardano.Crypto.Signing as X 10 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Encryption.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE ViewPatterns #-} 4 | 5 | -- | Wrapper over AES. `encode` and `decode` use AES256 CTR mode with IV = 0. 6 | -- Decryption functions are used in wallet. Encryption is not used anywhere. 7 | 8 | module Cardano.Crypto.Encryption 9 | ( AesKey(..) 10 | , aesEncrypt 11 | , aesDecrypt 12 | ) 13 | where 14 | 15 | import Cardano.Prelude hiding (init) 16 | 17 | import Crypto.Cipher.AES (AES256) 18 | import Crypto.Cipher.Types (BlockCipher(..), cipherInit, ctrCombine, nullIV) 19 | import Crypto.Error (CryptoError, eitherCryptoError) 20 | 21 | 22 | -------------------------------------------------------------------------------- 23 | -- AES 24 | -------------------------------------------------------------------------------- 25 | 26 | -- | Key to encrypt data 27 | newtype AesKey = AesKey 28 | { fromAESKey :: ByteString 29 | } deriving (Show, Eq, Generic) 30 | 31 | aesEncrypt :: ByteString -> AesKey -> Either CryptoError ByteString 32 | aesEncrypt input (fromAESKey -> sk) = 33 | ctrCombine <$> init <*> pure nullIV <*> pure input 34 | where 35 | -- FIXME: return either here 36 | init :: Either CryptoError AES256 37 | init = eitherCryptoError $ cipherInit sk 38 | 39 | aesDecrypt :: ByteString -> AesKey -> Either CryptoError ByteString 40 | aesDecrypt = aesEncrypt -- encryption/decryption is symmetric 41 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Crypto.Signing.KeyGen as X 7 | import Cardano.Crypto.Signing.VerificationKey as X 8 | import Cardano.Crypto.Signing.Redeem as X 9 | import Cardano.Crypto.Signing.Safe as X 10 | import Cardano.Crypto.Signing.SigningKey as X 11 | import Cardano.Crypto.Signing.Signature as X 12 | import Cardano.Crypto.Signing.Tag as X 13 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/KeyGen.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.KeyGen 2 | ( keyGen 3 | , deterministicKeyGen 4 | ) 5 | where 6 | 7 | import Cardano.Prelude 8 | 9 | import qualified Cardano.Crypto.Wallet as CC 10 | import Crypto.Random (MonadRandom, getRandomBytes) 11 | import Data.ByteArray (ScrubbedBytes) 12 | import qualified Data.ByteString as BS 13 | 14 | import Cardano.Crypto.Signing.VerificationKey (VerificationKey(..)) 15 | import Cardano.Crypto.Signing.SigningKey (SigningKey(..)) 16 | 17 | 18 | -- TODO: this is just a placeholder for actual (not ready yet) derivation 19 | -- of keypair from seed in cardano-crypto API 20 | createKeypairFromSeed :: BS.ByteString -> (CC.XPub, CC.XPrv) 21 | createKeypairFromSeed seed = 22 | let prv = CC.generate seed (mempty :: ScrubbedBytes) in (CC.toXPub prv, prv) 23 | 24 | -- | Generate a key pair. It's recommended to run it with 'runSecureRandom' 25 | -- from "Cardano.Crypto.Random" because the OpenSSL generator is probably safer 26 | -- than the default IO generator. 27 | keyGen :: MonadRandom m => m (VerificationKey, SigningKey) 28 | keyGen = do 29 | seed <- getRandomBytes 32 30 | let (vk, sk) = createKeypairFromSeed seed 31 | return (VerificationKey vk, SigningKey sk) 32 | 33 | -- | Create key pair deterministically from 32 bytes. 34 | deterministicKeyGen :: BS.ByteString -> (VerificationKey, SigningKey) 35 | deterministicKeyGen seed = 36 | bimap VerificationKey SigningKey (createKeypairFromSeed seed) 37 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Redeem.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.Redeem 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Crypto.Signing.Redeem.Compact as X 7 | import Cardano.Crypto.Signing.Redeem.KeyGen as X 8 | import Cardano.Crypto.Signing.Redeem.VerificationKey as X 9 | import Cardano.Crypto.Signing.Redeem.SigningKey as X 10 | import Cardano.Crypto.Signing.Redeem.Signature as X 11 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Redeem/KeyGen.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.Redeem.KeyGen 2 | ( redeemKeyGen 3 | , redeemDeterministicKeyGen 4 | ) 5 | where 6 | 7 | import Cardano.Prelude 8 | 9 | import Control.Monad (fail) 10 | import Crypto.Error (maybeCryptoError) 11 | import qualified Crypto.PubKey.Ed25519 as Ed25519 12 | import Crypto.Random (MonadRandom) 13 | import qualified Data.ByteArray as BA 14 | import qualified Data.ByteString as BS 15 | 16 | import Cardano.Crypto.Signing.Redeem.VerificationKey (RedeemVerificationKey(..)) 17 | import Cardano.Crypto.Signing.Redeem.SigningKey (RedeemSigningKey(..)) 18 | 19 | 20 | -- | Generate a key pair. It's recommended to run it with 'runSecureRandom' from 21 | -- "Cardano.Crypto.Random" because the OpenSSL generator is probably safer 22 | -- than the default IO generator. 23 | redeemKeyGen :: MonadRandom m => m (RedeemVerificationKey, RedeemSigningKey) 24 | redeemKeyGen = do 25 | sk <- Ed25519.generateSecretKey 26 | return (RedeemVerificationKey $ Ed25519.toPublic sk, RedeemSigningKey sk) 27 | 28 | -- | Create key pair deterministically from 32 bytes 29 | redeemDeterministicKeyGen 30 | :: BS.ByteString -> Maybe (RedeemVerificationKey, RedeemSigningKey) 31 | redeemDeterministicKeyGen seed = 32 | case maybeCryptoError $ Ed25519.secretKey (BA.convert seed :: BA.Bytes) of 33 | Just r -> Just (RedeemVerificationKey $ Ed25519.toPublic r, RedeemSigningKey r) 34 | Nothing -> 35 | fail "Cardano.Crypto.Signing.Redeem.hs redeemDeterministicKeyGen failed" 36 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Redeem/SigningKey.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE DerivingVia #-} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | 6 | module Cardano.Crypto.Signing.Redeem.SigningKey 7 | ( RedeemSigningKey(..) 8 | , redeemToVerification 9 | ) 10 | where 11 | 12 | import Cardano.Prelude 13 | 14 | import qualified Crypto.PubKey.Ed25519 as Ed25519 15 | import Formatting (bprint) 16 | import qualified Formatting.Buildable as B 17 | 18 | import Cardano.Binary (FromCBOR, ToCBOR) 19 | import Cardano.Crypto.Signing.Redeem.VerificationKey 20 | (RedeemVerificationKey(..), redeemVKB64F) 21 | 22 | 23 | -- | Wrapper around 'Ed25519.SecretKey'. 24 | newtype RedeemSigningKey = 25 | RedeemSigningKey Ed25519.SecretKey 26 | deriving (Eq, Show, Generic, NFData, FromCBOR, ToCBOR) 27 | deriving NoUnexpectedThunks via UseIsNormalForm RedeemSigningKey 28 | 29 | -- Note that there is deliberately no Ord instance. The crypto libraries 30 | -- encourage using key /hashes/ not keys for things like sets, map etc. 31 | 32 | instance B.Buildable RedeemSigningKey where 33 | build = bprint ("redeem_sec_of_vk:" . redeemVKB64F) . redeemToVerification 34 | 35 | -- | Verification key derivation function. 36 | redeemToVerification :: RedeemSigningKey -> RedeemVerificationKey 37 | redeemToVerification (RedeemSigningKey k) = RedeemVerificationKey (Ed25519.toPublic k) 38 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Safe.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.Safe 2 | ( module X 3 | ) 4 | where 5 | 6 | import Cardano.Crypto.Signing.Safe.KeyGen as X 7 | import Cardano.Crypto.Signing.Safe.PassPhrase as X 8 | import Cardano.Crypto.Signing.Safe.SafeSigner as X 9 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Safe/KeyGen.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.Safe.KeyGen 2 | ( safeDeterministicKeyGen 3 | , safeKeyGen 4 | ) 5 | where 6 | 7 | import Cardano.Prelude 8 | 9 | import qualified Cardano.Crypto.Wallet as CC 10 | import Crypto.Random (MonadRandom, getRandomBytes) 11 | import qualified Data.ByteString as BS 12 | 13 | import Cardano.Crypto.Signing.VerificationKey (VerificationKey(..)) 14 | import Cardano.Crypto.Signing.SigningKey (SigningKey(..)) 15 | import Cardano.Crypto.Signing.Safe.PassPhrase (PassPhrase(..)) 16 | 17 | 18 | safeCreateKeypairFromSeed :: BS.ByteString -> PassPhrase -> (CC.XPub, CC.XPrv) 19 | safeCreateKeypairFromSeed seed (PassPhrase pp) = 20 | let prv = CC.generate seed pp in (CC.toXPub prv, prv) 21 | 22 | -- NB. It's recommended to run it with 'runSecureRandom' from 23 | -- "Cardano.Crypto.Random" because the OpenSSL generator is probably safer than 24 | -- the default IO generator. 25 | safeKeyGen :: (MonadRandom m) => PassPhrase -> m (VerificationKey, SigningKey) 26 | safeKeyGen pp = do 27 | seed <- getRandomBytes 32 28 | pure $ safeDeterministicKeyGen seed pp 29 | 30 | safeDeterministicKeyGen 31 | :: BS.ByteString -> PassPhrase -> (VerificationKey, SigningKey) 32 | safeDeterministicKeyGen seed pp = 33 | bimap VerificationKey SigningKey (safeCreateKeypairFromSeed seed pp) 34 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Safe/PassPhrase.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 2 | {-# LANGUAGE OverloadedStrings #-} 3 | {-# LANGUAGE TypeApplications #-} 4 | 5 | module Cardano.Crypto.Signing.Safe.PassPhrase 6 | ( PassPhrase(..) 7 | , emptyPassphrase 8 | , passphraseLength 9 | ) 10 | where 11 | 12 | import Cardano.Prelude 13 | 14 | import Data.ByteArray (ByteArray, ByteArrayAccess, ScrubbedBytes) 15 | import qualified Data.ByteArray as ByteArray 16 | import qualified Data.ByteString as BS 17 | import Data.Default (Default(..)) 18 | import Formatting (int, sformat) 19 | import Formatting.Buildable (Buildable(..)) 20 | import qualified Prelude 21 | 22 | import Cardano.Binary (FromCBOR(..), ToCBOR(..)) 23 | 24 | 25 | newtype PassPhrase = 26 | PassPhrase ScrubbedBytes 27 | deriving (Eq, Ord, Semigroup, Monoid, NFData, ByteArray, ByteArrayAccess) 28 | 29 | passphraseLength :: Int 30 | passphraseLength = 32 31 | 32 | -- | Empty passphrase used in development 33 | emptyPassphrase :: PassPhrase 34 | emptyPassphrase = PassPhrase mempty 35 | 36 | instance Show PassPhrase where 37 | show _ = "" 38 | 39 | instance Buildable PassPhrase where 40 | build _ = "" 41 | 42 | instance Default PassPhrase where 43 | def = emptyPassphrase 44 | 45 | instance ToCBOR PassPhrase where 46 | toCBOR pp = toCBOR (ByteArray.convert pp :: ByteString) 47 | 48 | instance FromCBOR PassPhrase where 49 | fromCBOR = do 50 | bs <- fromCBOR @ByteString 51 | let bl = BS.length bs 52 | -- Currently passphrase may be either 32-byte long or empty (for 53 | -- unencrypted keys). 54 | toCborError $ if bl == 0 || bl == passphraseLength 55 | then Right $ ByteArray.convert bs 56 | else Left $ sformat 57 | ("put@PassPhrase: expected length 0 or " . int . ", not " . int) 58 | passphraseLength 59 | bl 60 | 61 | {-instance Monoid PassPhrase where 62 | mempty = PassPhrase mempty 63 | mappend (PassPhrase p1) (PassPhrase p2) = PassPhrase (p1 `mappend` p2)-} 64 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/Safe/SafeSigner.hs: -------------------------------------------------------------------------------- 1 | module Cardano.Crypto.Signing.Safe.SafeSigner 2 | ( SafeSigner(..) 3 | , noPassSafeSigner 4 | , safeToVerification 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Cardano.Crypto.Signing.VerificationKey (VerificationKey(..)) 11 | import Cardano.Crypto.Signing.SigningKey (SigningKey(..), toVerification) 12 | import Cardano.Crypto.Signing.Safe.PassPhrase (PassPhrase, emptyPassphrase) 13 | 14 | 15 | -- | SafeSigner datatype to encapsulate sensitive data 16 | data SafeSigner = SafeSigner !SigningKey !PassPhrase 17 | deriving (Show) 18 | 19 | noPassSafeSigner :: SigningKey -> SafeSigner 20 | noPassSafeSigner sk = SafeSigner sk emptyPassphrase 21 | 22 | safeToVerification :: SafeSigner -> VerificationKey 23 | safeToVerification (SafeSigner sk _) = toVerification sk 24 | 25 | -------------------------------------------------------------------------------- /crypto/src/Cardano/Crypto/Signing/SigningKey.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DerivingVia #-} 2 | {-# LANGUAGE TypeApplications #-} 3 | {-# LANGUAGE OverloadedStrings #-} 4 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 5 | 6 | module Cardano.Crypto.Signing.SigningKey 7 | ( SigningKey(..) 8 | , toVerification 9 | , toCBORXPrv 10 | , fromCBORXPrv 11 | ) 12 | where 13 | 14 | import Cardano.Prelude 15 | 16 | import Formatting.Buildable 17 | import qualified Cardano.Crypto.Wallet as CC 18 | import qualified GHC.Show 19 | import Formatting (bprint) 20 | 21 | import Cardano.Binary (Decoder, Encoding, FromCBOR(..), ToCBOR(..)) 22 | import Cardano.Crypto.Signing.VerificationKey (VerificationKey(..), shortVerificationKeyHexF) 23 | 24 | 25 | -- | Wrapper around 'CC.XPrv'. 26 | newtype SigningKey = SigningKey 27 | { unSigningKey :: CC.XPrv 28 | } deriving newtype (NFData) 29 | deriving NoUnexpectedThunks via UseIsNormalForm CC.XPrv 30 | 31 | -- Note that there is deliberately no Eq instance. The cardano-crypto library 32 | -- does not define one for XPrv. 33 | 34 | -- Note that there is deliberately no Ord instance. The crypto libraries 35 | -- encourage using key /hashes/ not keys for things like sets, map etc. 36 | 37 | -- | Generate a verification key from a signing key. Fast (it just drops some bytes 38 | -- off the signing key). 39 | toVerification :: SigningKey -> VerificationKey 40 | toVerification (SigningKey k) = VerificationKey (CC.toXPub k) 41 | 42 | instance Show SigningKey where 43 | show sk = "" 44 | 45 | instance Buildable SigningKey where 46 | build = bprint ("sec:" . shortVerificationKeyHexF) . toVerification 47 | 48 | toCBORXPrv :: CC.XPrv -> Encoding 49 | toCBORXPrv a = toCBOR $ CC.unXPrv a 50 | 51 | fromCBORXPrv :: Decoder s CC.XPrv 52 | fromCBORXPrv = toCborError . CC.xprv =<< fromCBOR @ByteString 53 | 54 | instance ToCBOR SigningKey where 55 | toCBOR (SigningKey a) = toCBORXPrv a 56 | 57 | instance FromCBOR SigningKey where 58 | fromCBOR = fmap SigningKey fromCBORXPrv 59 | -------------------------------------------------------------------------------- /crypto/test/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Dummy.hs: -------------------------------------------------------------------------------- 1 | -- | Dummy values used in tests (replacing `configuration.yaml`) 2 | 3 | module Test.Cardano.Crypto.Dummy 4 | ( annotatedProtocolMagicId 5 | , aProtocolMagic 6 | , protocolMagic 7 | , protocolMagicId 8 | ) 9 | where 10 | 11 | import Cardano.Prelude 12 | 13 | import Cardano.Binary (Annotated(..), serialize') 14 | import Cardano.Crypto 15 | ( AProtocolMagic(..) 16 | , ProtocolMagic 17 | , ProtocolMagicId(..) 18 | , RequiresNetworkMagic(..) 19 | ) 20 | 21 | aProtocolMagic :: AProtocolMagic ByteString 22 | aProtocolMagic = AProtocolMagic annotatedProtocolMagicId RequiresMagic 23 | 24 | protocolMagic :: ProtocolMagic 25 | protocolMagic = AProtocolMagic (Annotated protocolMagicId ()) RequiresMagic 26 | 27 | annotatedProtocolMagicId :: Annotated ProtocolMagicId ByteString 28 | annotatedProtocolMagicId = 29 | Annotated protocolMagicId (serialize' protocolMagicId) 30 | 31 | protocolMagicId :: ProtocolMagicId 32 | protocolMagicId = ProtocolMagicId 55550001 33 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Hashing.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module Test.Cardano.Crypto.Hashing 5 | ( tests 6 | ) 7 | where 8 | 9 | import Cardano.Prelude 10 | 11 | import Formatting (sformat) 12 | 13 | import Hedgehog 14 | ( Gen 15 | , Property 16 | , checkParallel 17 | , discover 18 | , forAll 19 | , property 20 | , withTests 21 | , (/==) 22 | , (===) 23 | ) 24 | import qualified Hedgehog.Gen as Gen 25 | import qualified Hedgehog.Range as Range 26 | 27 | import Cardano.Binary (ToCBOR) 28 | import Cardano.Crypto (decodeAbstractHash, hashHexF, serializeCborHash) 29 | 30 | 31 | -------------------------------------------------------------------------------- 32 | -- Main Test Action 33 | -------------------------------------------------------------------------------- 34 | 35 | tests :: IO Bool 36 | tests = checkParallel $$discover 37 | 38 | 39 | -------------------------------------------------------------------------------- 40 | -- Hashing Properties 41 | -------------------------------------------------------------------------------- 42 | 43 | prop_hashInequalityBool :: Property 44 | prop_hashInequalityBool = hashInequality Gen.bool 45 | 46 | prop_hashInequalityUnitList :: Property 47 | prop_hashInequalityUnitList = 48 | hashInequality $ Gen.list (Range.constant 0 50) (pure ()) 49 | 50 | prop_hashInequalityListOfList :: Property 51 | prop_hashInequalityListOfList = hashInequality $ Gen.list 52 | (Range.constant 0 10) 53 | (Gen.list (Range.constant 0 20) (Gen.maybe $ Gen.int Range.constantBounded)) 54 | 55 | 56 | -- | A golden test so that tests fail if the hash function changes 57 | prop_goldenHash :: Property 58 | prop_goldenHash = 59 | withTests 1 60 | . property 61 | $ sformat hashHexF (serializeCborHash (1 :: Word64)) 62 | === "ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25" 63 | 64 | 65 | -- | Check that 'decodeAbstractHash' correctly decodes hash values 66 | prop_decodeAbstractHash :: Property 67 | prop_decodeAbstractHash = property $ do 68 | a <- serializeCborHash <$> forAll (Gen.int Range.constantBounded) 69 | decodeAbstractHash (sformat hashHexF a) === Right a 70 | 71 | 72 | -------------------------------------------------------------------------------- 73 | -- Helpers 74 | -------------------------------------------------------------------------------- 75 | 76 | -- | Check that hashing two different @a@ values gives different hashes 77 | hashInequality :: (Eq a, Show a, ToCBOR a) => Gen a -> Property 78 | hashInequality genA = property $ do 79 | a <- forAll genA 80 | b <- forAll $ Gen.filter (/= a) genA 81 | serializeCborHash a /== serializeCborHash b 82 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Json.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Crypto.Json 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | import Test.Cardano.Prelude 10 | 11 | import Hedgehog (Property) 12 | import qualified Hedgehog as H 13 | 14 | import Test.Cardano.Crypto.Example 15 | ( exampleProtocolMagic3 16 | , exampleProtocolMagic4 17 | ) 18 | 19 | -------------------------------------------------------------------------------- 20 | -- ProtocolMagic 21 | -------------------------------------------------------------------------------- 22 | 23 | -- Legacy JSON encoding where requiresNetworkMagic was 24 | -- encoded as "NMMustBeNothing" or "NMMustBeJust" 25 | 26 | goldenProtocolMagic3AesonDec_NMMustBeJust :: Property 27 | goldenProtocolMagic3AesonDec_NMMustBeJust = goldenTestJSONDec 28 | exampleProtocolMagic3 29 | "test/golden/json/ProtocolMagic_Legacy_NMMustBeJust" 30 | 31 | goldenProtocolMagic4AesonDec_NMMustBeNothing :: Property 32 | goldenProtocolMagic4AesonDec_NMMustBeNothing = goldenTestJSONDec 33 | exampleProtocolMagic4 34 | "test/golden/json/ProtocolMagic_Legacy_NMMustBeNothing" 35 | 36 | tests :: IO Bool 37 | tests = H.checkSequential $$discoverGolden 38 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Keys.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module Test.Cardano.Crypto.Keys 5 | ( tests 6 | ) 7 | where 8 | 9 | import Cardano.Prelude 10 | 11 | import Formatting (sformat) 12 | 13 | import Hedgehog 14 | import qualified Hedgehog.Gen as Gen 15 | import qualified Hedgehog.Range as Range 16 | 17 | import Cardano.Crypto.Signing 18 | ( deterministicKeyGen 19 | , fullVerificationKeyF 20 | , parseFullVerificationKey 21 | , redeemDeterministicKeyGen 22 | , redeemToVerification 23 | , safeDeterministicKeyGen 24 | , toVerification 25 | ) 26 | 27 | import Test.Cardano.Crypto.Gen (genPassPhrase, genVerificationKey) 28 | 29 | 30 | -------------------------------------------------------------------------------- 31 | -- Main Test Action 32 | -------------------------------------------------------------------------------- 33 | 34 | tests :: IO Bool 35 | tests = checkParallel $$discover 36 | 37 | 38 | -------------------------------------------------------------------------------- 39 | -- Key Properties 40 | -------------------------------------------------------------------------------- 41 | 42 | -- | Derived 'VerificationKey' is the same as generated one 43 | prop_pubKeyDerivedGenerated :: Property 44 | prop_pubKeyDerivedGenerated = property $ do 45 | seed <- forAll $ Gen.bytes (Range.singleton 32) 46 | let (vk, sk) = deterministicKeyGen seed 47 | vk === toVerification sk 48 | 49 | prop_pubKeyParsing :: Property 50 | prop_pubKeyParsing = property $ do 51 | vk <- forAll genVerificationKey 52 | parseFullVerificationKey (sformat fullVerificationKeyF vk) === Right vk 53 | 54 | -- | Derived 'RedeemVerificationKey' is the same as generated one 55 | prop_redeemVerKeyDerivedGenerated :: Property 56 | prop_redeemVerKeyDerivedGenerated = property $ do 57 | seed <- forAll $ Gen.bytes (Range.singleton 32) 58 | let 59 | (vk, sk) = 60 | fromMaybe (panic "redeem keygen failed") $ redeemDeterministicKeyGen seed 61 | vk === redeemToVerification sk 62 | 63 | -- | Derived 'VerificationKey' is the same as generated one 64 | prop_safeVerKeyDerivedGenerated :: Property 65 | prop_safeVerKeyDerivedGenerated = property $ do 66 | pp <- forAll genPassPhrase 67 | seed <- forAll $ Gen.bytes (Range.singleton 32) 68 | let (vk, sk) = safeDeterministicKeyGen seed pp 69 | vk === toVerification sk 70 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Orphans.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE StandaloneDeriving #-} 2 | {-# OPTIONS_GHC -fno-warn-orphans #-} 3 | 4 | module Test.Cardano.Crypto.Orphans 5 | () 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import qualified Data.ByteArray as BA 11 | import qualified Crypto.PubKey.Ed25519 as Ed25519 12 | import Cardano.Crypto 13 | ( SigningKey(..) 14 | ) 15 | import Cardano.Crypto.Hashing (serializeCborHash) 16 | 17 | 18 | -- Note that we /only/ provide these Eq and Ord instances for test suites. 19 | -- The crypto libraries encourage using key /hashes/ not keys for things 20 | -- like sets, map etc. 21 | 22 | 23 | instance Eq SigningKey where 24 | a == b = serializeCborHash a == serializeCborHash b 25 | 26 | instance Ord Ed25519.PublicKey where 27 | compare x1 x2 = compare (toByteString x1) (toByteString x2) 28 | 29 | instance Ord Ed25519.SecretKey where 30 | compare x1 x2 = compare (toByteString x1) (toByteString x2) 31 | 32 | instance Ord Ed25519.Signature where 33 | compare x1 x2 = compare (toByteString x1) (toByteString x2) 34 | 35 | toByteString :: (BA.ByteArrayAccess bin) => bin -> ByteString 36 | toByteString = BA.convert 37 | 38 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Random.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Crypto.Random 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import qualified Data.ByteString as BS 11 | 12 | import Hedgehog (Property, checkParallel, discover, property, withTests, (===)) 13 | 14 | import Cardano.Crypto.Random (deterministic, randomNumber) 15 | 16 | 17 | tests :: IO Bool 18 | tests = checkParallel $$discover 19 | 20 | prop_randomNumberDeterminism :: Property 21 | prop_randomNumberDeterminism = withTests 1 . property $ do 22 | let seed = BS.pack [1 .. 40] 23 | deterministic seed (randomNumber 1) === 0 24 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Signing/Redeem.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Crypto.Signing.Redeem 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | 10 | import Hedgehog 11 | (Gen, Property, assert, checkParallel, discover, forAll, property) 12 | import qualified Hedgehog.Gen as Gen 13 | import qualified Hedgehog.Range as Range 14 | 15 | import Cardano.Crypto.Signing (SignTag(..)) 16 | import Cardano.Crypto.Signing.Redeem 17 | (redeemSign, redeemToVerification, verifyRedeemSig) 18 | 19 | import qualified Test.Cardano.Crypto.Dummy as Dummy 20 | import Test.Cardano.Crypto.Gen 21 | (genRedeemKeypair, genRedeemVerificationKey, genRedeemSigningKey) 22 | 23 | 24 | -------------------------------------------------------------------------------- 25 | -- Main Test Action 26 | -------------------------------------------------------------------------------- 27 | 28 | tests :: IO Bool 29 | tests = checkParallel $$discover 30 | 31 | 32 | -------------------------------------------------------------------------------- 33 | -- Redeem Signature Properties 34 | -------------------------------------------------------------------------------- 35 | 36 | -- | Signing and verification with a redeem keys works 37 | prop_redeemSign :: Property 38 | prop_redeemSign = property $ do 39 | (vk, sk) <- forAll genRedeemKeypair 40 | a <- forAll genData 41 | 42 | assert 43 | $ verifyRedeemSig Dummy.protocolMagicId SignForTestingOnly vk a 44 | $ redeemSign Dummy.protocolMagicId SignForTestingOnly sk a 45 | 46 | -- | Signing fails when the wrong 'RedeemVerificationKey' is used 47 | prop_redeemSignDifferentKey :: Property 48 | prop_redeemSignDifferentKey = property $ do 49 | sk <- forAll genRedeemSigningKey 50 | vk <- forAll $ Gen.filter (/= redeemToVerification sk) genRedeemVerificationKey 51 | a <- forAll genData 52 | 53 | assert 54 | . not 55 | $ verifyRedeemSig Dummy.protocolMagicId SignForTestingOnly vk a 56 | $ redeemSign Dummy.protocolMagicId SignForTestingOnly sk a 57 | 58 | -- | Signing fails when then wrong signature data is used 59 | prop_redeemSignDifferentData :: Property 60 | prop_redeemSignDifferentData = property $ do 61 | (vk, sk) <- forAll genRedeemKeypair 62 | a <- forAll genData 63 | b <- forAll $ Gen.filter (/= a) genData 64 | 65 | assert 66 | . not 67 | $ verifyRedeemSig Dummy.protocolMagicId SignForTestingOnly vk b 68 | $ redeemSign Dummy.protocolMagicId SignForTestingOnly sk a 69 | 70 | genData :: Gen [Int32] 71 | genData = Gen.list (Range.constant 0 50) (Gen.int32 Range.constantBounded) 72 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Signing/Redeem/Compact.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Crypto.Signing.Redeem.Compact 4 | ( tests 5 | ) 6 | where 7 | 8 | import Cardano.Prelude 9 | import Test.Cardano.Prelude 10 | 11 | import Hedgehog (MonadTest, Property, checkParallel, tripping) 12 | 13 | import Cardano.Crypto.Signing.Redeem 14 | (fromCompactRedeemVerificationKey, toCompactRedeemVerificationKey) 15 | 16 | import Test.Cardano.Crypto.Gen (genRedeemVerificationKey) 17 | 18 | -------------------------------------------------------------------------------- 19 | -- Compact RedeemVerificationKey 20 | -------------------------------------------------------------------------------- 21 | 22 | roundTripCompactRedeemVerificationKey :: Property 23 | roundTripCompactRedeemVerificationKey = 24 | eachOf 25 | 1000 26 | genRedeemVerificationKey 27 | (trippingCompact toCompactRedeemVerificationKey fromCompactRedeemVerificationKey) 28 | 29 | ------------------------------------------------------------------------------- 30 | -- Tripping util 31 | ------------------------------------------------------------------------------- 32 | 33 | trippingCompact 34 | :: (HasCallStack, MonadTest m, Show a, Show b, Eq a) 35 | => (a -> b) -> (b -> a) -> a -> m () 36 | trippingCompact toCompact fromCompact x = 37 | tripping x toCompact (Identity . fromCompact) 38 | 39 | ------------------------------------------------------------------------------- 40 | -- Main test export 41 | ------------------------------------------------------------------------------- 42 | 43 | tests :: IO Bool 44 | tests = checkParallel $$discoverRoundTrip 45 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Signing/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | {-# LANGUAGE TemplateHaskell #-} 3 | 4 | module Test.Cardano.Crypto.Signing.Safe 5 | ( tests 6 | ) 7 | where 8 | 9 | import Cardano.Prelude 10 | 11 | import Hedgehog 12 | (Property, checkParallel, discover, forAll, property, (===)) 13 | 14 | import Cardano.Crypto.Signing 15 | ( noPassSafeSigner 16 | , safeToVerification 17 | , toVerification 18 | ) 19 | 20 | import Test.Cardano.Crypto.Gen (genSigningKey) 21 | 22 | 23 | -------------------------------------------------------------------------------- 24 | -- Main Test Action 25 | -------------------------------------------------------------------------------- 26 | 27 | tests :: IO Bool 28 | tests = checkParallel $$discover 29 | 30 | 31 | -------------------------------------------------------------------------------- 32 | -- Safe Signing Properties 33 | -------------------------------------------------------------------------------- 34 | 35 | -- | Making a 'SafeSigner' from a 'SigningKey' preserves the 'VerificationKey' 36 | -- 37 | -- Since SafeSigner was simplified, this is a completely trivial property. 38 | -- 39 | -- Definitions: 40 | -- 41 | -- > safeToVerification (SafeSigner sk _) = toVerification sk 42 | -- > noPassSafeSigner sk = SafeSigner sk emptyPassphrase 43 | -- 44 | -- Theorem: 45 | -- 46 | -- > safeToVerification (noPassSafeSigner sk) = toVerification sk 47 | -- 48 | -- Proof: 49 | -- 50 | -- > safeToVerification (noPassSafeSigner sk) 51 | -- > 52 | -- > = { by expanding definition of noPassSafeSigner } 53 | -- > 54 | -- > safeToVerification (SafeSigner sk emptyPassphrase) 55 | -- > 56 | -- > = { by expanding definition of safeToVerification } 57 | -- > 58 | -- > toVerification sk 59 | -- 60 | prop_safeSignerPreservesVerificationKey :: Property 61 | prop_safeSignerPreservesVerificationKey = property $ do 62 | sk <- forAll genSigningKey 63 | safeToVerification (noPassSafeSigner sk) === toVerification sk 64 | -------------------------------------------------------------------------------- /crypto/test/Test/Cardano/Crypto/Signing/Signing.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TemplateHaskell #-} 2 | 3 | module Test.Cardano.Crypto.Signing.Signing (tests) where 4 | 5 | import Cardano.Prelude 6 | 7 | import Hedgehog 8 | (Gen, Property, assert, checkParallel, discover, forAll, property) 9 | import qualified Hedgehog.Gen as Gen 10 | import qualified Hedgehog.Range as Range 11 | 12 | import Cardano.Binary (toCBOR) 13 | import Cardano.Crypto.Signing (SignTag(..), sign, toVerification, verifySignature) 14 | 15 | import qualified Test.Cardano.Crypto.Dummy as Dummy 16 | import Test.Cardano.Crypto.Gen 17 | (genKeypair, genVerificationKey, genSigningKey) 18 | 19 | 20 | -------------------------------------------------------------------------------- 21 | -- Main Test Action 22 | -------------------------------------------------------------------------------- 23 | 24 | tests :: IO Bool 25 | tests = checkParallel $$discover 26 | 27 | 28 | -------------------------------------------------------------------------------- 29 | -- Redeem Signature Properties 30 | -------------------------------------------------------------------------------- 31 | 32 | -- | Signing and verification works 33 | prop_sign :: Property 34 | prop_sign = property $ do 35 | (vk, sk) <- forAll genKeypair 36 | a <- forAll genData 37 | 38 | assert 39 | $ verifySignature toCBOR Dummy.protocolMagicId SignForTestingOnly vk a 40 | $ sign Dummy.protocolMagicId SignForTestingOnly sk a 41 | 42 | -- | Signing fails when the wrong 'VerificationKey' is used 43 | prop_signDifferentKey :: Property 44 | prop_signDifferentKey = property $ do 45 | sk <- forAll genSigningKey 46 | vk <- forAll $ Gen.filter (/= toVerification sk) genVerificationKey 47 | a <- forAll genData 48 | 49 | assert 50 | . not 51 | $ verifySignature toCBOR Dummy.protocolMagicId SignForTestingOnly vk a 52 | $ sign Dummy.protocolMagicId SignForTestingOnly sk a 53 | 54 | -- | Signing fails when then wrong signature data is used 55 | prop_signDifferentData :: Property 56 | prop_signDifferentData = property $ do 57 | (vk, sk) <- forAll genKeypair 58 | a <- forAll genData 59 | b <- forAll $ Gen.filter (/= a) genData 60 | 61 | assert 62 | . not 63 | $ verifySignature toCBOR Dummy.protocolMagicId SignForTestingOnly vk b 64 | $ sign Dummy.protocolMagicId SignForTestingOnly sk a 65 | 66 | genData :: Gen [Int32] 67 | genData = Gen.list (Range.constant 0 50) (Gen.int32 Range.constantBounded) 68 | -------------------------------------------------------------------------------- /crypto/test/cardano-crypto-test.cabal: -------------------------------------------------------------------------------- 1 | name: cardano-crypto-test 2 | version: 1.3.0 3 | synopsis: Test helpers from cardano-crypto exposed to other packages 4 | description: Test helpers from cardano-crypto exposed to other packages 5 | license: Apache-2.0 6 | license-file: LICENSE 7 | author: IOHK 8 | maintainer: operations@iohk.io 9 | copyright: 2018 IOHK 10 | category: Currency 11 | build-type: Simple 12 | cabal-version: >=1.10 13 | 14 | flag development 15 | description: Disable `-Werror` 16 | default: False 17 | manual: True 18 | 19 | library 20 | exposed-modules: 21 | Test.Cardano.Crypto.CBOR 22 | Test.Cardano.Crypto.Dummy 23 | Test.Cardano.Crypto.Example 24 | Test.Cardano.Crypto.Gen 25 | Test.Cardano.Crypto.Json 26 | Test.Cardano.Crypto.Orphans 27 | 28 | build-depends: base 29 | , bytestring 30 | , cardano-binary 31 | , cardano-binary-test 32 | , cardano-crypto 33 | , cardano-crypto-wrapper 34 | , cardano-prelude 35 | , cardano-prelude-test 36 | , cryptonite 37 | , hedgehog 38 | , memory 39 | 40 | default-language: Haskell2010 41 | default-extensions: NoImplicitPrelude 42 | 43 | ghc-options: -Weverything 44 | -fno-warn-all-missed-specialisations 45 | -fno-warn-missing-import-lists 46 | -fno-warn-safe 47 | -fno-warn-unsafe 48 | 49 | if (!flag(development)) 50 | ghc-options: -Werror 51 | -------------------------------------------------------------------------------- /crypto/test/golden/AbstractHash: -------------------------------------------------------------------------------- 1 | 00: 582001f4b788593d4f70de2a45c2e1e8 2 | 10: 7088bfbdfa29577ae1b62aba60e095e3 3 | 20: ab53 4 | -------------------------------------------------------------------------------- /crypto/test/golden/DecShare: -------------------------------------------------------------------------------- 1 | 00: 58610379a7cfbc3c66ad878629f79505 2 | 10: 10f9fd7ac85977306c53f3a6450c0725 3 | 20: d8da31bfc752b92868d6f3276d15a14c 4 | 30: d7b95979d30b32fc33f1f988a149f63b 5 | 40: 6105a540c532f93b8bd26eb85570a3c7 6 | 50: 7a1114942d23a2d9711f23918d4975a7 7 | 60: d46fb7 8 | -------------------------------------------------------------------------------- /crypto/test/golden/EncShare: -------------------------------------------------------------------------------- 1 | 00: 582102d0ca9ebbac514ebfd135172a06 2 | 10: 1e5f0bcf56babbe5781cdcefa1adb71e 3 | 20: dc2588 4 | -------------------------------------------------------------------------------- /crypto/test/golden/PassPhrase: -------------------------------------------------------------------------------- 1 | 00: 582077346c4453453553346653483665 2 | 10: 744e6f756958657a4379456a4b633374 3 | 20: 4734 4 | -------------------------------------------------------------------------------- /crypto/test/golden/RedeemSignature: -------------------------------------------------------------------------------- 1 | 00: 584011cf71f75af2d73d3afa61af5cc2 2 | 10: cc53a98704d78b97b7daec06ccf7eb7c 3 | 20: 6607a954f3fda82b80832290c646bf31 4 | 30: 074c15aaef8eacda84b993882088be60 5 | 40: 5701 6 | -------------------------------------------------------------------------------- /crypto/test/golden/RedeemSigningKey: -------------------------------------------------------------------------------- 1 | 00: 58404b6d7977346c4453453553346653 2 | 10: 483665744e6f756958657a4379456a4b 3 | 20: 6333538960a916726b09f05c9d4d4a92 4 | 30: 2b85b4e11acfcc1434673d95019b7a9a 5 | 40: 52d2 6 | -------------------------------------------------------------------------------- /crypto/test/golden/RedeemVerificationKey: -------------------------------------------------------------------------------- 1 | 00: 5820538960a916726b09f05c9d4d4a92 2 | 10: 2b85b4e11acfcc1434673d95019b7a9a 3 | 20: 52d2 4 | -------------------------------------------------------------------------------- /crypto/test/golden/Secret: -------------------------------------------------------------------------------- 1 | 00: 582103a889b85070721af446a282e8d2 2 | 10: 3934612eb6ffc7c422f15aa85ad5c072 3 | 20: 267c79 4 | -------------------------------------------------------------------------------- /crypto/test/golden/SecretProof: -------------------------------------------------------------------------------- 1 | 000: 8458210317f64d0daa9ed18cb2b51102 2 | 010: 89755601862d2779c11d988bd31cd777 3 | 020: 9f590ff8584034d60d150f99ef6a8b3a 4 | 030: 20d2243d5304c5926d99d739373a85fc 5 | 040: 32f29b099f2ad52f54d9692526b27830 6 | 050: a77fd616d133bcdc502b248a1d9ecf95 7 | 060: 9488b4da3f6458a8c1f9a1af53542e45 8 | 070: f4d17a0a973e65657c35ac6712954843 9 | 080: 914de6be15cec2ac0000000000000004 10 | 090: 374869e2742d25443a466821097df49c 11 | 0a0: 941be59a40c45dfb4b4586482a9f12a8 12 | 0b0: 5acfc58628ed128b878943cde8d33cdd 13 | 0c0: 582288400b81aa0cb673935f59f64536 14 | 0d0: 5ba3189d04d323ff5f36b023bf297063 15 | 0e0: 129dbdd1c718a561e9783e49697a27cb 16 | 0f0: 4b47d91f0934461fd6801248d54d50ff 17 | 100: 791ae1596a59fc842eb0ca9797604276 18 | 110: 9f58210308f5d87bc37317806a481e85 19 | 120: 5a31b64b8e3958b1eb0775bac0b3ec53 20 | 130: 0275a8805821037a1844c68428b1e5b9 21 | 140: 145a32acaae05826eafbca6877b64ef2 22 | 150: df22004e479978582103faecfd77bcec 23 | 160: cf788f772fab560a72818f89fc7742e6 24 | 170: e254417d245aa929223c58210282931f 25 | 180: f9451ef9f29948f97ed511843bf913ae 26 | 190: cd96b6bc4050e7ed6b48080012ff 27 | -------------------------------------------------------------------------------- /crypto/test/golden/Signature: -------------------------------------------------------------------------------- 1 | 00: 5840b28bf6b4c08892f5b82dc11e9df0 2 | 10: 8c0c4374a8f7e2b2558d42a83ed43ec2 3 | 20: b6b76dabf1293a561971d772d3f96097 4 | 30: f96f40a363b4201616202ef18fe52f27 5 | 40: f806 6 | -------------------------------------------------------------------------------- /crypto/test/golden/SigningKey: -------------------------------------------------------------------------------- 1 | 00: 588053346653483665744e6f75695865 2 | 10: 7a4379456a4b63337447346a61306b46 3 | 20: 6a4f38717a616932365a4d5055454a66 4 | 30: 457931356f78356b4a30754b44626937 5 | 40: 6936644c586b756573565a394a664867 6 | 50: 6a726374734c4674324e766f76586e63 7 | 60: 68734f7658303559364c6f686c544e74 8 | 70: 356d6b504668556f587531455a534a54 9 | 80: 4979 10 | -------------------------------------------------------------------------------- /crypto/test/golden/VerificationKey: -------------------------------------------------------------------------------- 1 | 00: 58404b6d7977346c4453453553346653 2 | 10: 483665744e6f756958657a4379456a4b 3 | 20: 63337447346a61306b466a4f38717a61 4 | 30: 6932365a4d5055454a66457931356f78 5 | 40: 356b 6 | -------------------------------------------------------------------------------- /crypto/test/golden/VssPublicKey: -------------------------------------------------------------------------------- 1 | 00: 582102294842accb1d76aaa64bc1af23 2 | 10: 1378e1a01a67c0fc8010824caa021097 3 | 20: 0275c4 4 | -------------------------------------------------------------------------------- /crypto/test/golden/json/ProtocolMagic0_Legacy_HasNetworkMagic: -------------------------------------------------------------------------------- 1 | 31337 -------------------------------------------------------------------------------- /crypto/test/golden/json/ProtocolMagic1_Legacy_HasNetworkMagic: -------------------------------------------------------------------------------- 1 | 2147000001 -------------------------------------------------------------------------------- /crypto/test/golden/json/ProtocolMagic2_Legacy_HasNetworkMagic: -------------------------------------------------------------------------------- 1 | -58952 -------------------------------------------------------------------------------- /crypto/test/golden/json/ProtocolMagic_Legacy_NMMustBeJust: -------------------------------------------------------------------------------- 1 | {"pm":31337,"requiresNetworkMagic":"NMMustBeJust"} -------------------------------------------------------------------------------- /crypto/test/golden/json/ProtocolMagic_Legacy_NMMustBeNothing: -------------------------------------------------------------------------------- 1 | {"pm":500,"requiresNetworkMagic":"NMMustBeNothing"} 2 | -------------------------------------------------------------------------------- /crypto/test/test.hs: -------------------------------------------------------------------------------- 1 | import Cardano.Prelude 2 | import Test.Cardano.Prelude 3 | 4 | import qualified Test.Cardano.Crypto.CBOR 5 | import qualified Test.Cardano.Crypto.Hashing 6 | import qualified Test.Cardano.Crypto.Json 7 | import qualified Test.Cardano.Crypto.Limits 8 | import qualified Test.Cardano.Crypto.Keys 9 | import qualified Test.Cardano.Crypto.Random 10 | import qualified Test.Cardano.Crypto.Signing.Redeem 11 | import qualified Test.Cardano.Crypto.Signing.Redeem.Compact 12 | import qualified Test.Cardano.Crypto.Signing.Safe 13 | import qualified Test.Cardano.Crypto.Signing.Signing 14 | 15 | 16 | -- | Main testing action 17 | main :: IO () 18 | main = runTests 19 | [ Test.Cardano.Crypto.CBOR.tests 20 | , Test.Cardano.Crypto.Hashing.tests 21 | , Test.Cardano.Crypto.Json.tests 22 | , Test.Cardano.Crypto.Keys.tests 23 | , Test.Cardano.Crypto.Limits.tests 24 | , Test.Cardano.Crypto.Random.tests 25 | , Test.Cardano.Crypto.Signing.Redeem.tests 26 | , Test.Cardano.Crypto.Signing.Redeem.Compact.tests 27 | , Test.Cardano.Crypto.Signing.Safe.tests 28 | , Test.Cardano.Crypto.Signing.Signing.tests 29 | ] 30 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem 2 | , crossSystem ? null 3 | # allows to cutomize haskellNix (ghc and profiling, see ./nix/haskell.nix) 4 | , config ? {} 5 | # allows to override dependencies of the project without modifications, 6 | # eg. to test build against local checkout of nixpkgs and iohk-nix: 7 | # nix build -f default.nix cardano-ledger --arg sourcesOverride '{ 8 | # iohk-nix = ../iohk-nix; 9 | # }' 10 | , sourcesOverride ? {} 11 | # pinned version of nixpkgs augmented with overlays (iohk-nix and our packages). 12 | , pkgs ? import ./nix { inherit system crossSystem config sourcesOverride; } 13 | , gitrev ? pkgs.iohkNix.commitIdFromGitRepoOrZero ./.git 14 | }: 15 | with pkgs; with commonLib; 16 | let 17 | 18 | haskellPackages = recRecurseIntoAttrs 19 | # the Haskell.nix package set, reduced to local packages. 20 | (selectProjectPackages cardanoLedgerHaskellPackages); 21 | 22 | self = { 23 | inherit haskellPackages; 24 | 25 | inherit (haskellPackages.cardano-ledger.identifier) version; 26 | 27 | # `tests` are the test suites which have been built. 28 | tests = collectComponents' "tests" haskellPackages; 29 | # `benchmarks` (only built, not run). 30 | benchmarks = collectComponents' "benchmarks" haskellPackages; 31 | 32 | libs = collectComponents' "library" haskellPackages; 33 | 34 | checks = recurseIntoAttrs { 35 | # `checks.tests` collect results of executing the tests: 36 | tests = collectChecks haskellPackages; 37 | }; 38 | 39 | shell = import ./shell.nix { 40 | inherit pkgs; 41 | withHoogle = true; 42 | }; 43 | }; 44 | in self 45 | -------------------------------------------------------------------------------- /iohk-monitoring/static/configuration-editor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | IOHK Monitoring | Configuration Editor 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 |
31 |
 
32 | 33 |
34 |
35 |
36 | 37 |
38 | 39 |
40 |
41 | Monitoring/Logging Configuration Editor 42 |
43 |
44 |
45 | 46 |
47 | 48 |
49 | 50 |
51 |
52 |
53 | 54 |
 
55 |
56 | 57 | 58 | -------------------------------------------------------------------------------- /iohk-monitoring/static/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/input-output-hk/cardano-ledger-byron/d309449e6c303a9f0dcc8dcf172df6f0b3195ed5/iohk-monitoring/static/images/favicon.ico -------------------------------------------------------------------------------- /iohk-monitoring/static/images/iohk-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/input-output-hk/cardano-ledger-byron/d309449e6c303a9f0dcc8dcf172df6f0b3195ed5/iohk-monitoring/static/images/iohk-logo.png -------------------------------------------------------------------------------- /lib.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem 2 | , crossSystem ? null 3 | , config ? {} 4 | , overlays ? [] 5 | }: 6 | 7 | let 8 | sources = import ./nix/sources.nix; 9 | iohkNix = import sources.iohk-nix { 10 | sourcesOverride = sources; 11 | }; 12 | haskellNix = import sources."haskell.nix"; 13 | args = haskellNix // { 14 | inherit system crossSystem; 15 | overlays = (haskellNix.overlays or []) ++ overlays; 16 | config = (haskellNix.config or {}) // config; 17 | }; 18 | nixpkgs = import sources.nixpkgs; 19 | pkgs = nixpkgs args; 20 | haskellPackages = import ./nix/pkgs.nix { 21 | inherit pkgs; 22 | src = ./.; 23 | }; 24 | lib = pkgs.lib; 25 | niv = (import sources.niv {}).niv; 26 | isCardanoLedger = with lib; package: 27 | (package.isHaskell or false); 28 | filterCardanoPackages = pkgs.lib.filterAttrs (_: package: isCardanoLedger package); 29 | getPackageChecks = pkgs.lib.mapAttrs (_: package: package.checks); 30 | in lib // { 31 | inherit (pkgs.haskell-nix.haskellLib) collectComponents; 32 | inherit 33 | niv 34 | sources 35 | haskellPackages 36 | pkgs 37 | iohkNix 38 | isCardanoLedger 39 | getPackageChecks 40 | filterCardanoPackages; 41 | } 42 | -------------------------------------------------------------------------------- /local-stack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | stack --stack-yaml=stack-local.yaml --work-dir=.stack-work-local $@ 3 | -------------------------------------------------------------------------------- /nix/cardano-mainnet-mirror.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: 2 | 3 | pkgs.fetchgit { 4 | url = "https://github.com/input-output-hk/cardano-mainnet-mirror"; 5 | rev = "a31ac7534ec855b715b9a6bb6a06861ee94935d9"; 6 | sha256 = "1z51ak4f7klz5pv2kjgaj5jv6agn2aph2n172hjssmn8x1q2bdys"; 7 | } 8 | -------------------------------------------------------------------------------- /nix/default.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem 2 | , crossSystem ? null 3 | , config ? {} 4 | , sourcesOverride ? {} 5 | }: 6 | let 7 | sources = import ./sources.nix { inherit pkgs; } 8 | // sourcesOverride; 9 | iohKNix = import sources.iohk-nix {}; 10 | haskellNix = import sources."haskell.nix"; 11 | # use our own nixpkgs if it exists in our sources, 12 | # otherwise use iohkNix default nixpkgs. 13 | nixpkgs = if (sources ? nixpkgs) 14 | then (builtins.trace "Not using IOHK default nixpkgs (use 'niv drop nixpkgs' to use default for better sharing)" 15 | sources.nixpkgs) 16 | else (builtins.trace "Using IOHK default nixpkgs" 17 | iohKNix.nixpkgs); 18 | 19 | # for inclusion in pkgs: 20 | overlays = 21 | # Haskell.nix (https://github.com/input-output-hk/haskell.nix) 22 | haskellNix.overlays 23 | # haskell-nix.haskellLib.extra: some useful extra utility functions for haskell.nix 24 | ++ iohKNix.overlays.haskell-nix-extra 25 | # iohkNix: nix utilities and niv: 26 | ++ iohKNix.overlays.iohkNix 27 | # our own overlays: 28 | ++ [ 29 | (pkgs: _: with pkgs; { 30 | 31 | # commonLib: mix pkgs.lib with iohk-nix utils and our own: 32 | commonLib = lib // iohkNix 33 | // import ./util.nix { inherit haskell-nix; } 34 | # also expose our sources and overlays 35 | // { inherit overlays sources; }; 36 | }) 37 | # And, of course, our haskell-nix-ified cabal project: 38 | (import ./pkgs.nix) 39 | ]; 40 | 41 | pkgs = import nixpkgs { 42 | inherit system crossSystem overlays; 43 | config = haskellNix.config // config; 44 | }; 45 | 46 | in pkgs 47 | -------------------------------------------------------------------------------- /nix/pkgs.nix: -------------------------------------------------------------------------------- 1 | 2 | # our packages overlay 3 | pkgs: _: with pkgs; { 4 | cardanoLedgerHaskellPackages = import ./haskell.nix { 5 | inherit config 6 | lib 7 | stdenv 8 | pkgs 9 | haskell-nix 10 | buildPackages 11 | ; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /nix/regenerate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd $(git rev-parse --show-toplevel) 4 | 5 | exec $(nix-build `dirname $0`/. -A iohkNix.cabalProjectRegenerate --no-out-link --option substituters "https://hydra.iohk.io https://cache.nixos.org" --option trusted-substituters "" --option trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=")/bin/cabal-project-regenerate 6 | -------------------------------------------------------------------------------- /nix/sources.json: -------------------------------------------------------------------------------- 1 | { 2 | "haskell.nix": { 3 | "branch": "master", 4 | "description": "Alternative Haskell Infrastructure for Nixpkgs", 5 | "homepage": "https://input-output-hk.github.io/haskell.nix", 6 | "owner": "input-output-hk", 7 | "repo": "haskell.nix", 8 | "rev": "ded93b38ff656d3bf1b90f926bbf0ecea3fab723", 9 | "sha256": "12pw3ykv2wp6kj0vj8y499p4khmzyx9r9il15l8p2wr2i7cpjxnc", 10 | "type": "tarball", 11 | "url": "https://github.com/input-output-hk/haskell.nix/archive/ded93b38ff656d3bf1b90f926bbf0ecea3fab723.tar.gz", 12 | "url_template": "https://github.com///archive/.tar.gz" 13 | }, 14 | "iohk-nix": { 15 | "branch": "master", 16 | "description": "nix scripts shared across projects", 17 | "homepage": null, 18 | "owner": "input-output-hk", 19 | "repo": "iohk-nix", 20 | "rev": "083761953f5f74ec12e803aa735b460cde9985c8", 21 | "sha256": "16xdndn57br83ayq9xj7f0f7milwqgr5c2sak3ps033n4ndxfsxg", 22 | "type": "tarball", 23 | "url": "https://github.com/input-output-hk/iohk-nix/archive/083761953f5f74ec12e803aa735b460cde9985c8.tar.gz", 24 | "url_template": "https://github.com///archive/.tar.gz" 25 | }, 26 | "niv": { 27 | "branch": "iohk", 28 | "description": "Easy dependency management for Nix projects", 29 | "homepage": "https://github.com/nmattia/niv", 30 | "owner": "input-output-hk", 31 | "repo": "niv", 32 | "rev": "89da7b2e7ae0779fd351618fc74df1b1da5e6214", 33 | "sha256": "0jn88ahv6mycxdkzihy1v0dz2110q0d42q4ggyj68l2lyba6y0yy", 34 | "type": "tarball", 35 | "url": "https://github.com/input-output-hk/niv/archive/89da7b2e7ae0779fd351618fc74df1b1da5e6214.tar.gz", 36 | "url_template": "https://github.com///archive/.tar.gz" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /nix/stack-shell.nix: -------------------------------------------------------------------------------- 1 | 2 | with import ./. {}; 3 | 4 | haskell.lib.buildStackProject { 5 | name = "stack-env"; 6 | buildInputs = [ zlib openssl gmp libffi git haskellPackages.happy ]; 7 | ghc = (import ../shell.nix { inherit pkgs; }).ghc.baseGhc; 8 | CARDANO_MAINNET_MIRROR = 9 | "${import ./cardano-mainnet-mirror.nix {inherit pkgs;}}/epochs"; 10 | } 11 | -------------------------------------------------------------------------------- /nix/update-iohk-nix.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-shell 2 | #!nix-shell -A devops ../shell.nix -i bash 3 | niv update iohk-nix 4 | -------------------------------------------------------------------------------- /nix/util.nix: -------------------------------------------------------------------------------- 1 | { haskell-nix }: 2 | 3 | with haskell-nix.haskellLib; 4 | { 5 | 6 | inherit 7 | selectProjectPackages 8 | collectComponents'; 9 | 10 | inherit (extra) 11 | recRecurseIntoAttrs 12 | collectChecks; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /release.nix: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # 3 | # Hydra release jobset. 4 | # 5 | # The purpose of this file is to select jobs defined in default.nix and map 6 | # them to all supported build platforms. 7 | # 8 | ############################################################################ 9 | 10 | # The project sources 11 | { cardano-ledger ? { outPath = ./.; rev = "abcdef"; } 12 | 13 | # Function arguments to pass to the project 14 | , projectArgs ? { 15 | config = { allowUnfree = false; inHydra = true; }; 16 | gitrev = cardano-ledger.rev; 17 | } 18 | 19 | # The systems that the jobset will be built for. 20 | , supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ] 21 | 22 | # The systems used for cross-compiling 23 | , supportedCrossSystems ? [ "x86_64-linux" ] 24 | 25 | # A Hydra option 26 | , scrubJobs ? true 27 | 28 | # Dependencies overrides 29 | , sourcesOverride ? {} 30 | 31 | # Import pkgs, including IOHK common nix lib 32 | , pkgs ? import ./nix { inherit sourcesOverride; } 33 | 34 | }: 35 | 36 | with (import pkgs.iohkNix.release-lib) { 37 | inherit pkgs; 38 | inherit supportedSystems supportedCrossSystems scrubJobs projectArgs; 39 | packageSet = import cardano-ledger; 40 | gitrev = cardano-ledger.rev; 41 | }; 42 | 43 | with pkgs.lib; 44 | 45 | let 46 | testsSupportedSystems = [ "x86_64-linux" "x86_64-darwin" ]; 47 | # Recurse through an attrset, returning all test derivations in a list. 48 | collectTests' = ds: filter (d: elem d.system testsSupportedSystems) (collect isDerivation ds); 49 | # Adds the package name to the test derivations for windows-testing-bundle.nix 50 | # (passthru.identifier.name does not survive mapTestOn) 51 | collectTests = ds: concatLists ( 52 | mapAttrsToList (packageName: package: 53 | map (drv: drv // { inherit packageName; }) (collectTests' package) 54 | ) ds); 55 | 56 | inherit (systems.examples) mingwW64 musl64; 57 | 58 | jobs = { 59 | native = mapTestOn (__trace (__toJSON (packagePlatforms project)) (packagePlatforms project)); 60 | "${mingwW64.config}" = mapTestOnCross mingwW64 (packagePlatformsCross project); 61 | # TODO: fix broken evals 62 | #musl64 = mapTestOnCross musl64 (packagePlatformsCross project); 63 | } // (mkRequiredJob ( 64 | collectTests jobs.native.checks ++ 65 | collectTests jobs.native.benchmarks ++ [ 66 | #jobs.native.cardano-ledger.x86_64-darwin 67 | #jobs.native.cardano-ledger.x86_64-linux 68 | ])); 69 | 70 | in jobs 71 | -------------------------------------------------------------------------------- /scripts/brittany/brittany-all-hs: -------------------------------------------------------------------------------- 1 | set +e 2 | 3 | for f in $(find . -not -path "*/.stack-work*/*" -not -path "*specs/*" -name '*.hs'); do 4 | brittany --config-file scripts/brittany/config.yaml --write-mode inplace $f 5 | done 6 | -------------------------------------------------------------------------------- /scripts/brittany/config.yaml: -------------------------------------------------------------------------------- 1 | conf_debug: 2 | dconf_roundtrip_exactprint_only: false 3 | dconf_dump_bridoc_simpl_par: false 4 | dconf_dump_ast_unknown: false 5 | dconf_dump_bridoc_simpl_floating: false 6 | dconf_dump_config: false 7 | dconf_dump_bridoc_raw: false 8 | dconf_dump_bridoc_final: false 9 | dconf_dump_bridoc_simpl_alt: false 10 | dconf_dump_bridoc_simpl_indent: false 11 | dconf_dump_annotations: false 12 | dconf_dump_bridoc_simpl_columns: false 13 | dconf_dump_ast_full: false 14 | conf_forward: 15 | options_ghc: 16 | - -XLambdaCase 17 | - -XMultiWayIf 18 | - -XGADTs 19 | - -XPatternGuards 20 | - -XViewPatterns 21 | - -XRecursiveDo 22 | - -XTupleSections 23 | - -XExplicitForAll 24 | - -XImplicitParams 25 | - -XQuasiQuotes 26 | - -XTemplateHaskell 27 | - -XBangPatterns 28 | - -XRecordWildCards 29 | - -XTypeApplications 30 | - -XOverloadedLabels 31 | - -XRankNTypes 32 | conf_errorHandling: 33 | econf_ExactPrintFallback: ExactPrintFallbackModeInline 34 | econf_Werror: false 35 | econf_omit_output_valid_check: false 36 | econf_produceOutputOnErrors: false 37 | conf_preprocessor: 38 | ppconf_CPPMode: CPPModeAbort 39 | ppconf_hackAroundIncludes: false 40 | conf_obfuscate: false 41 | conf_roundtrip_exactprint_only: false 42 | conf_version: 1 43 | conf_layout: 44 | lconfig_reformatModulePreamble: true 45 | lconfig_altChooser: 46 | tag: AltChooserBoundedSearch 47 | contents: 3 48 | lconfig_allowSingleLineExportList: false 49 | lconfig_importColumn: 50 50 | lconfig_hangingTypeSignature: false 51 | lconfig_importAsColumn: 50 52 | lconfig_alignmentLimit: 10 53 | lconfig_indentListSpecial: true 54 | lconfig_indentAmount: 2 55 | lconfig_alignmentBreakOnMultiline: true 56 | lconfig_cols: 80 57 | lconfig_indentPolicy: IndentPolicyMultiple 58 | lconfig_indentWhereSpecial: true 59 | lconfig_columnAlignMode: 60 | tag: ColumnAlignModeMajority 61 | contents: 0.7 62 | -------------------------------------------------------------------------------- /scripts/brittany/default.nix: -------------------------------------------------------------------------------- 1 | with import ../../nix/lib.nix; 2 | with pkgs; 3 | 4 | writeScript "check-brittany" '' 5 | #!${stdenv.shell} 6 | export PATH=${lib.makeBinPath [ findutils git haskellPackages.brittany ]}:$PATH 7 | 8 | set -xe 9 | 10 | ${builtins.readFile ./brittany-all-hs} 11 | 12 | fail_brittany_check () { 13 | git diff --text > /tmp/brittany.patch 14 | buildkite-agent artifact upload /tmp/brittany.patch --job $BUILDKITE_JOB_ID 15 | rm /tmp/brittany.patch 16 | echo "ERROR: You need to run brittany over your changes and commit them" >&2 17 | exit 1 18 | } 19 | 20 | git diff --text --exit-code || fail_brittany_check 21 | '' 22 | -------------------------------------------------------------------------------- /scripts/buildkite/default.nix: -------------------------------------------------------------------------------- 1 | with import ../../nix {}; 2 | 3 | let 4 | stack-hpc-coveralls = iohkNix.stack-hpc-coveralls; 5 | stackRebuild = runCommand "stack-rebuild" {} '' 6 | ${haskellPackages.ghcWithPackages (ps: [ps.turtle ps.safe ps.transformers])}/bin/ghc -o $out ${./rebuild.hs} 7 | ''; 8 | 9 | buildTools = 10 | [ git gzip nix gnumake stack gnused gnutar coreutils stack-hpc-coveralls systemd ]; 11 | 12 | in 13 | writeScript "stack-rebuild-wrapped" '' 14 | #!${stdenv.shell} 15 | export PATH=${lib.makeBinPath buildTools} 16 | exec ${stackRebuild} "$@" 17 | '' 18 | -------------------------------------------------------------------------------- /scripts/buildkite/rebuild.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | {-# LANGUAGE OverloadedStrings #-} 3 | {-# LANGUAGE ScopedTypeVariables #-} 4 | 5 | import Control.Exception 6 | import Control.Monad.Trans.Maybe 7 | import qualified Data.Text as T 8 | import Safe 9 | import System.Exit (exitWith) 10 | import Turtle 11 | 12 | 13 | -- | Run build and upload coverage information when successful 14 | main :: IO () 15 | main = do 16 | buildResult <- buildStep (Just ["--scenario=ContinuousIntegration"]) 17 | 18 | when (buildResult == ExitSuccess) coverageUploadStep 19 | 20 | exitWith buildResult 21 | 22 | 23 | -- | Build and test all packages using stack 24 | buildStep :: Maybe [Text] -> IO ExitCode 25 | buildStep testArgs = do 26 | echo "+++ Build and test" 27 | run "stack" $ cfg ++ ["build", "--fast"] ++ buildArgs 28 | where 29 | cfg = ["--dump-logs", "--color", "always"] 30 | buildArgs = 31 | [ "--bench" 32 | , "--no-run-benchmarks" 33 | , "--haddock" 34 | , "--haddock-internal" 35 | , "--no-haddock-deps" 36 | , "--test" 37 | , "--coverage" 38 | ] 39 | ++ maybe [] ("--ta" :) testArgs 40 | 41 | 42 | -- | Upload coverage information to coveralls 43 | coverageUploadStep :: IO () 44 | coverageUploadStep = do 45 | echo "--- Uploading Coverage Information" 46 | need "CARDANO_LEDGER_COVERALLS_REPO_TOKEN" >>= \case 47 | Nothing -> printf 48 | "Missing coverall repo token. Not uploading coverage information.\n" 49 | Just repoToken -> do 50 | result <- proc 51 | "shc" 52 | [ "--repo-token" 53 | , repoToken 54 | , "--exclude-dirs" 55 | , "crypto/test" 56 | , "combined" 57 | , "all" 58 | ] 59 | empty 60 | case result of 61 | ExitSuccess -> printf "Coverage information upload successful.\n" 62 | ExitFailure _ -> printf "Coverage information upload failed.\n" 63 | 64 | 65 | run :: Text -> [Text] -> IO ExitCode 66 | run cmd args = do 67 | printf (s % " " % s % "\n") cmd (T.unwords args) 68 | res <- proc cmd args empty 69 | case res of 70 | ExitSuccess -> pure () 71 | ExitFailure code -> eprintf 72 | ("error: Command exited with code " % d % "!\nContinuing...\n") 73 | code 74 | pure res 75 | -------------------------------------------------------------------------------- /scripts/buildkite/stack-cabal-sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | # This script checks that the `stack.yaml` and `cabal.project` files have 5 | # consistent git hashes for the packages they depend on. We use 6 | # `cardano-repo-tool`'s `update-cabal-project` command which modifies 7 | # `cabal.project` to be consistent with `stack.yaml`s versions. If the 8 | # diff is non-empty, we know they're out of sync. 9 | 10 | # Check that functions are defined. 11 | HELP_TEXT="cardano-repo-tool not found." 12 | type cardano-repo-tool > /dev/null 2>&1 || { echo "${HELP_TEXT}"; exit 1; } 13 | HELP_TEXT="git not found." 14 | type git > /dev/null 2>&1 || { echo "${HELP_TEXT}"; exit 1; } 15 | 16 | # Update `cabal.project` from the `stack.yaml` file. 17 | cardano-repo-tool update-cabal-project 18 | 19 | git diff cabal.project | tee stack-cabal.patch 20 | 21 | if test "$(wc -l < stack-cabal.patch)" -gt 0 ; then 22 | buildkite-agent artifact upload stack-cabal.patch --job "$BUILDKITE_JOB_ID" 23 | exit 1 24 | fi 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /scripts/buildkite/stack-cabal_config_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -euo pipefail 3 | 4 | # This script checks that the `stack.yaml` and `cabal.project` files have 5 | # consistent git hashes for the packages they depend on. We use 6 | # `cardano-repo-tool`'s `update-cabal-project` command which modifies 7 | # `cabal.project` to be consistent with `stack.yaml`s versions. If the 8 | # diff is non-empty, we know they're out of sync. 9 | 10 | # Check that functions are defined. 11 | HELP_TEXT="cardano-repo-tool not found. Please add it to your PATH, either\n\n\ 12 | [1] installing it from \ 13 | https://github.com/input-output-hk/cardano-repo-tool\n\ 14 | [2] (usually for CI) using nix-shell from iohk-ops to bring it in scope: \ 15 | https://github.com/input-output-hk/iohk-nix/blob/\ 16 | 91febccdb615c365dbbda03a9adcaffbafa57846/docs/buildkite-scripts.md" 17 | type cardano-repo-tool &>/dev/null || { echo "${HELP_TEXT}"; exit 1; } 18 | HELP_TEXT="git not found. Please add it to your PATH" 19 | type git &>/dev/null || { echo "${HELP_TEXT}"; exit 1; } 20 | 21 | # Update `cabal.project` to be consistent. 22 | cardano-repo-tool update-cabal-project 23 | 24 | # This command exits 1 if the diff is non-empty, and 0 if the 25 | # diff is empty. 26 | HELP_TEXT="\`cabal.project\` and \`stack.yaml\` files are not consistent. If \ 27 | \`stack.yaml\` is correct and \`cabal.project\` is out of date, then running \ 28 | \`cardano-repo-tool update-cabal-project\` locally will modify \ 29 | \`cabal.project\` to be consistent. But if \`cabal.project\` is correct and \ 30 | \`stack.yaml\` is out of date, running the aforementioned command will just \ 31 | overwrite \`cabal.project\` with the outdated version from \`stack.yaml\`. \ 32 | Thus, in this case one must manually copy the git hash from \`cabal.project\` \ 33 | to \`stack.yaml\`." 34 | git diff --exit-code || { echo "ERROR:\n${HELP_TEXT}"; exit 1; } 35 | -------------------------------------------------------------------------------- /scripts/nix/stack-shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem 2 | , config ? {} 3 | , pkgs ? import (import ./fetch-nixpkgs.nix) { inherit system config; } 4 | }: 5 | 6 | with pkgs; 7 | 8 | haskell.lib.buildStackProject { 9 | name = "cardano-chain-env"; 10 | buildInputs = [ zlib openssl git ]; 11 | ghc = haskell.packages.ghc865.ghc; 12 | } 13 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | # This file is used by nix-shell. 2 | # It just takes the shell attribute from default.nix. 3 | { config ? {} 4 | , sourcesOverride ? {} 5 | , withHoogle ? false 6 | , pkgs ? import ./nix { 7 | inherit config sourcesOverride; 8 | } 9 | }: 10 | with pkgs; 11 | let 12 | # This provides a development environment that can be used with nix-shell or 13 | # lorri. See https://input-output-hk.github.io/haskell.nix/user-guide/development/ 14 | shell = cardanoLedgerHaskellPackages.shellFor { 15 | name = "cabal-dev-shell"; 16 | 17 | # If shellFor local packages selection is wrong, 18 | # then list all local packages then include source-repository-package that cabal complains about: 19 | packages = ps: with ps; [ 20 | ps.cardano-ledger 21 | ]; 22 | 23 | # These programs will be available inside the nix-shell. 24 | buildInputs = with haskellPackages; [ 25 | cabal-install 26 | ghcid 27 | hlint 28 | weeder 29 | nix 30 | niv 31 | pkgconfig 32 | sqlite-interactive 33 | git 34 | ]; 35 | 36 | # Prevents cabal from choosing alternate plans, so that 37 | # *all* dependencies are provided by Nix. 38 | exactDeps = true; 39 | 40 | inherit withHoogle; 41 | }; 42 | 43 | devops = pkgs.stdenv.mkDerivation { 44 | name = "devops-shell"; 45 | buildInputs = [ 46 | niv 47 | ]; 48 | shellHook = '' 49 | echo "DevOps Tools" \ 50 | | ${figlet}/bin/figlet -f banner -c \ 51 | | ${lolcat}/bin/lolcat 52 | 53 | echo "NOTE: you may need to export GITHUB_TOKEN if you hit rate limits with niv" 54 | echo "Commands: 55 | * niv update - update package 56 | 57 | " 58 | ''; 59 | }; 60 | 61 | in 62 | 63 | shell // { inherit devops; } 64 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: https://raw.githubusercontent.com/input-output-hk/cardano-prelude/3ac22a2fda11ca7131a011a9ea48fcbfdc26d6b3/snapshot.yaml 2 | 3 | packages: 4 | - cardano-ledger 5 | - cardano-ledger/test 6 | - crypto 7 | - crypto/test 8 | 9 | extra-deps: 10 | - tasty-hedgehog-1.0.0.2 11 | 12 | # To be able to use `stack hoogle` 13 | - haskell-src-exts-1.21.0 14 | 15 | - generic-monoid-0.1.0.0 16 | 17 | - git: https://github.com/input-output-hk/cardano-prelude 18 | commit: 3ac22a2fda11ca7131a011a9ea48fcbfdc26d6b3 19 | subdirs: 20 | - . 21 | - test 22 | 23 | - git: https://github.com/input-output-hk/cardano-crypto 24 | commit: 2547ad1e80aeabca2899951601079408becbc92c 25 | 26 | - git: https://github.com/input-output-hk/cardano-base 27 | commit: 2f0d4cc5b4798901333e199aa44e3a041a7aaaf1 28 | subdirs: 29 | - binary 30 | - binary/test 31 | - cardano-crypto-class 32 | 33 | - git: https://github.com/input-output-hk/cardano-ledger-specs 34 | commit: 9f96b7462a41d449826a4cc5f93dad395354cfe6 35 | subdirs: 36 | - semantics/executable-spec 37 | - byron/ledger/executable-spec 38 | - byron/chain/executable-spec 39 | 40 | # Needed for `cardano-ledger-specs` 41 | - git: https://github.com/input-output-hk/goblins 42 | commit: 26d35ad52fe9ade3391532dbfeb2f416f07650bc 43 | - moo-1.2 44 | - gray-code-0.3.1 45 | 46 | - git: https://github.com/input-output-hk/iohk-monitoring-framework 47 | commit: d998ff661aebae783a68725f3834af472bfa6468 48 | subdirs: 49 | - contra-tracer 50 | 51 | # Not yet in Stack 52 | - bimap-0.4.0 53 | - Unique-0.4.7.6 54 | - quiet-0.2 55 | 56 | nix: 57 | shell-file: nix/stack-shell.nix 58 | --------------------------------------------------------------------------------