GithubHelp home page GithubHelp logo

input-output-hk / cardano-ledger Goto Github PK

View Code? Open in Web Editor NEW
242.0 57.0 153.0 110.57 MB

The ledger implementation and specifications of the Cardano blockchain.

License: Apache License 2.0

Makefile 0.14% Haskell 85.13% TeX 13.84% Nix 0.36% Shell 0.06% C 0.12% C++ 0.08% Ruby 0.01% Rich Text Format 0.25% Dhall 0.01% Perl 0.01%
cryptocurrency blockchain cardano ada

cardano-ledger's Introduction

Cardano Ledger

CEH GitHub Workflow Status (master) Haddock (master)

This repository contains the formal specifications, executable models, and implementations of the Cardano Ledger.

The documents are built in our CI and can be readily accessed using the following links:

Era Design Documents Formal Specification CDDL
Byron Chain Spec, Ledger Spec CDDL, PDF
Shelley Design Spec CDDL
Allegra Same as Mary era below Same as Mary era below CDDL
Mary Multi-Currency, UTXOma Spec CDDL
Alonzo eUTXO Spec CDDL
Babbage batch-verification, CIP-31, CIP-32, CIP-33 Spec CDDL
Conway CIP-1694 Spec (WIP) CDDL

Other Documents:

In addition, there is a formalization of the Ledger Specification in Isabelle/HOL which can be found here.

Some user documentation is published on Read the Docs

Haddock code documentation of the latest master branch is available here.

Repository structure

The directory structure of this repository is as follows:

Building

It is recommended to use nix for building everything in this repository. Haskell files can be built with cabal inside of a nix shell.

Make sure you have a recent version of nix by following this guide

Nix Cache

When using nix it is recommended that you setup the cache, so that it can reuse built artifacts, reducing the compilation times dramatically:

If you are using NixOS add the snippet below to your /etc/nixos/configuration.nix:

nix.settings = {
  experimental-features = [ "nix-command" "flakes" ];
  substituters = [
    "https://cache.nixos.org"
    "https://cache.iog.io"
  ];
  trusted-public-keys = [
    "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
  ];
};

If you are using the nix package manager next to another operating system put the following in /etc/nix/nix.conf:

experimental-features = nix-command flakes
substituters        = https://cache.iog.io https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

Building the LaTeX documents and executable specifications

When using nix the documents and Haskell code can be readily built by running:

nix build .#specs

The LaTeX documents will be placed inside a directory named result, e.g.:

result/byron-ledger.pdf
result/shelley-delegation.pdf
result/non-integer-calculations.pdf
result/small-step-semantics.pdf
result/shelley-ledger.pdf
result/byron-blockchain.pdf

Building individual LaTeX documents

Change to the latex directory where the latex document is (e.g. eras/shelley/formal-spec for the ledger specification corresponding to the Shelley release, or eras/byron/ledger/formal-spec for the ledger specification corresponding to the Byron release). Then, build the latex document by running:

cd <myLaTexDir>
nix develop --command make

For a continuous compilation of the LaTeX file run:

cd <myLaTexDir>
nix develop --command make watch

Testing

Run cabal test all to run all tests or cabal test <package> to run the tests for a specific package.

Note: The CARDANO_MAINNET_MIRROR environment variable can be overriden in flake.nix if one desires to run the Byron tests with a different version of the mainnet epochs.

Submitting an issue

Issues can be filed in the GitHub Issue tracker.

However, note that this is pre-release software, so we will not usually be providing support.

Contributing

See CONTRIBUTING.

cardano-ledger's People

Contributors

aniketd avatar dcoutts avatar dnadales avatar erikd avatar goolord avatar intricate avatar iohk-bors[bot] avatar jaredcorduan avatar jimbo4350 avatar kantp avatar kevinhammond avatar lehins avatar lucsanszky avatar maximilianalgehed avatar mdimjasevic avatar mgudemann avatar mhuesch avatar michaelpj avatar mrbliss avatar nc6 avatar neilmayhew avatar newhoggy avatar polinavino avatar redxaxder avatar ruhatch avatar soupstraw avatar teodanciu avatar timsheard avatar uroboros avatar whatisrt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cardano-ledger's Issues

Deposits and Refunds (executable model)

Add certificate deposits and refunds to the Haskell executable model. This requires adding the protocol constants to the ledger state as well. It may make sense to not model refunding pool certificates until some kind of epoch boundary rules are in place.

min fee as ax+b

In the LaTeX spec, instead of keeping the minfee calculation abstract, define it as ax+b, where a and b are in the protocol constants and x is the number of bytes in an encoding of the transaction.

state properties for the delegation model

We will be writing property tests for our executable haskell model of the ledger with delegation. The first step is to think of all the properties that we can test. Add these to the LaTeX (or lhs) document.

Property Test for conservation of 45B ADA

Write a property test that checks that for any valid ledger state:

45B ADA == balance utxo + balance rewards + deposits + treasury + reserves + rewardPool + fees

add stale stake

add stale stake mechanism, as described in the delegation design doc, to the ledger rules.

add LaTeX spec to CI

There is a makefile inside fm-ledger-rules/latex which builds a pdf using Nix. It would be nice to check this build as a part of CI. It would also be great if there was a way to publish the pdf as an artifact.

Adapt mutators for use with Goblins framework

After finishing this issue it

  • MUST be possible to instantiate the Goblins framework with the mutators as toys

  • MUST be possible to instantiate the ledger value transactions using the STS framework

  • SHOULD be possible to run the Goblins to create invalid data using the GA approach

  • SHOULD be possible to see labeled test results from the GA run

pool reg cert refunds

Currently, the spec refunds both stake key registration and pool registration deposits at any slot in the UTxO rule. The pool registration, however, should not be done this way since we allow retirement certificates to override each other. These refunds can only be returned when the pool is reaped.

Delegation Design: Review Section on Displaying Pools in the Wallet

The section "Display of Stake Pools in the Wallet" (currently 5.2) was written before the incentives part of the document was finished. We should review this section, to make sure everything covered therein is covered in the section on incentives, and then just reference that section instead of duplicating information.

Implement replay protection for transactions

To ensure replay protection, each transaction must consume at least one input. This is in particular important for delegation transactions, but currently not implemented in the executable spec.

After resolving this issue it

  • MUST be ensured that a validated transaction consumes at least one input
  • MUST be ensured that 'DelegationData' transactions spend at least one input
  • SHOULD be one combined LedgerEntry data type
  • there SHOULD be at least one test for checking that a transaction with empty input set is not validated

Generators for invalid data

The current generators can supply valid data to the state transition function. It should also be possible to generate invalid data, to test the correct behaviour of the state transition functions in those case.

This should then collect all reasons of why a transaction is rejected.
It is necessary to choose an efficient approach to generate invalid data, likely doesn't generate "interesting" cases that test the important edge cases.

add fees to the ledger rules

In the latex spec, we need to model transaction fees.

We can then state the preservation of value property as an equality instead of an inequality. For example, with implicit fees, we state this validation rule as balance (txouts tx) \leq balance (txins tx domRestr utxo). When fees and minted coins are explicit, we get an equality: fees + balance (txouts tx) = minted + balance (txins tx domRestr utxo).

Investigate use of Liquid Haskell in spec

Liquid Haskell provides means for automatic checking of certain properties

  • refinement types
  • theorem proving for equational reasoning
  • termination checks (automatic for subset, manual in more complex cases)

There may be some properties that could be proven directly in Haskell using Liquid Haskell. Nevertheless, there are challenges, for example:

  • expressiveness
  • integration into Project, CI ...
  • Results depend on choice of SMT solver (Z3, CVC4, MathSAT)

address replay attacks - spend one txin

Non UTxO actions that a transaction may take do not always afford the same replay protection as the UTxO. so, for this reason, we can piggyback replay prevention by signing the transaction body, assuming the transaction spends at least one input. We should make this a conditional requirement in the appropriate rules.

literate haskell?

Try combining our latex spec and haskell model with literate haskell. Decide if this is the approach that we should take. See this report for an example of multiple .lhs modules.

DELEW rule does not conform to small step semantics

The current rule DELEGW has two rules in its antecedent. It is intended that this rule succeeds if either DELEG or POOL succeeds. As all the conditions in the antecedent are conjoined, however, as currently written, this rule can never succeed.

We need to either split this rule into multiple rules, or find a way to express the disjunction.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.