Documentation

FMMidgard.ProofProtocol.Catalogue.Ledger.AllInputsValid

Ledger Rule - All inputs must be Valid #

See MidgardSpec -- Section 5.1.1.

This section is a proof-of-concept trying to verify the logic behind fraudproofs and their descomposition.

The Valid Inputs Property #

The property we are checking in this file is:

ValidInput
= ∀ t ∈ Ledger, ∀ i ∈ spend_inputs(t)
  : (∃ t_1 ∈ Ledger, t ≠ t_1 ∧ i ∈ outputs(t_1))
  ∧ (∄ t_2 ∈ Ledger, t ≠ t_2 ∧ i ∈ spend_inputs(t_2))

Claim of the spec:

ValidInput ↔
            ( NOInput
            ∧ InputNoIdx
            ∧ WithdrawnInput
            ∧ DoubleSpend
            ∧ DoubleWithdraw
            )

To prove the above claim, we need to have a definition of the Ledger, i.e. a Ledger Spec. However, once we have the spec implemented, we can prove the above statement in isolation.

What we can try is to modify the ValidInput statement so we only use local data: e.g. each transaction consumes utxos and produce new ones. So we do not need to look at the whole Ledger.

Let's propose the following valid input statement: Let's txs be the current list of transactions forming a block and utxo_prev the current set of utxos alive.

ValidInput
= ∀ t ∈ txs, ∀ i ∈ spend_inputs(t)
  : i ∈ utxo_prev
  ∧ (∄ t_2 ∈ txs, t ≠ t_2 ∧ i ∈ spend_inputs(t_2))

In words, inputs exist before spending them and only one transaction gets to spend them.

Simple Translation into Lean #

This is how we would write it in lean. In the spec there is no clear definition of what they consider a /Ledger/, I assume it is just a list of blocks.

In the spec, it is not clear how the different components are composed to /verify/ the All Valid Property.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    All valid Property from the spec. There are no mention of withdrawals here, maybe we should add something so it matches the other properties.

    Equations
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Methodology #

        In this first PoC, I assume I have access to all the required data. Lateron, we will replace:

        Data retieval may be a bit different. We get some hashes from the State Queue, or recieve external data and verify it correct using hashes.

        When it comes to the logic of /Optimistic properties/, we follow the same ideas stated in the Operators Directory module. We define a way to observe the property, to create a witness, and then, a way to /correct/ the state. Technically, we are not in a bad (/bad/ in the old ways) state, we allow such states to be reached, but we penalize the agents generating it.

        NoInput Violation #

        There is a non-membership proof that may involve several others.

        Definition

        Spec:

           ∃ t ∈ txs, ∃ i ∈ spend_inputs(t)
            : (i ∉ utxos_prev)
            ∧ (∄ t_1 ∈ txs, t ≠ t_1 → tx_hash(t_1) = tx_hash(i))
        

        Replaced by

           ∃ t ∈ txs, ∃ i ∈ spend_inputs(t)
            : (i ∉ utxos_prev)
            ∧ (hash(i) ∉ txs)
        
        Equations
        Instances For

          The following property is noncomputable because flat_tx_hash is not computable.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Computation #

            Computation Finds a Witness #

            Computation finding one violation. Hashing is axiomatized, so we cannot run it.

            TODO: Missing witnesses. We need to reconstruct the path so we can build the fraudproof. See findWitness?

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem AllInputsValid.NoInputViolation.Computation_correct {prev : List TxId} {txs : List FlattenTransaction} {i : OutputRef} {t : FlattenTransaction} {pi pt : ListSimulation.Path} {noi : ListSimulation.NonMemProof TxId} {not : ListSimulation.NonMemProof Hash_64} (prev_ne : ¬prev = []) (prev_sorted : List.Sorted (fun (x1 x2 : TxId) => x1 < x2) prev) (txs_ne : ¬txs = []) (txs_sorted : List.Sorted (fun (x1 x2 : Hash_64) => x1 < x2) (List.map TransactionHash.flat_tx_hash txs)) (H : Computation prev prev_ne txs txs_ne = some ((((i, noi, not), t), pi), pt)) :

              Computation Returns None #

              If Computation returns none, it means we cannot build valid witnesses. If we cannot build a valid witness, it should mean the transaction is valid.

              Therefore, all inputs are correct? Since i ∈ t.inputs, hash t cannot be the same as hash i.

              theorem AllInputsValid.NoInputViolation.Computation_empty [LawfulBEq FlattenTransaction] {prev : List TxId} {txs : List FlattenTransaction} (assump : ∀ (tx : FlattenTransaction), ∀ i ∈ tx.inputs, ¬TransactionHash.flat_tx_hash tx = i.id) (prev_ne : ¬prev = []) (prev_sorted : List.Sorted (fun (x1 x2 : TxId) => x1 < x2) prev) (txs_ne : ¬txs = []) (txs_sorted : List.Sorted (fun (x1 x2 : Hash_64) => x1 < x2) (List.map TransactionHash.flat_tx_hash txs)) (H : Computation prev prev_ne txs txs_ne = none) (t : FlattenTransaction) :
              t ∈ txs → ∀ i ∈ t.inputs, (∃ t' ∈ txs, (!t == t' && decide (TransactionHash.flat_tx_hash t' = i.id)) = true) ∨ i.id ∈ prev

              Computation Thread #

              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Instances For
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      No Input IDX Violation #

                      Definition

                      ∃ t ∈ txs, ∃ i ∈ spend_inputs(t), ∃ t_1 ∈ txs
                          : tx_hash(t_1) = tx_hash(i)
                          ∧ i ∉ outputs(t_1)
                      
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Computation #

                        Equations
                        Instances For

                          Computation Thread #

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            WithdrawnInput Violation #

                             ∃ t ∈ txs,
                             ∃ i ∈ spend_inputs(t),
                             ∃ w ∈ wtxs,
                             i = l2_outref(w)
                            
                            Equations
                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Lean Computation function. #

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem AllInputsValid.WithdrawnInputViolation.Computation_correct {txs : List FlattenTransaction} {withdrawals : Withdrawals} {t : FlattenTransaction} {i w : OutputRef} (H : Computation txs withdrawals = some (t, i, w)) :
                                  t ∈ txs ∧ i ∈ t.inputs ∧ ∃ withdrawal ∈ withdrawals, withdrawal.1 = w ∧ withdrawal.2.l2_outref = i
                                  theorem AllInputsValid.WithdrawnInputViolation.Computation_none {txs : List FlattenTransaction} {withdrawals : Withdrawals} (H : Computation txs withdrawals = none) (t : FlattenTransaction) :
                                  t ∈ txs → ∀ i ∈ t.inputs, ∀ w ∈ withdrawals, ¬w.2.l2_outref = i

                                  Computation Thread #

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    DoubleSpend Violation #

                                    Property:

                                    ∃ t ∈ txs,
                                    ∃ i ∈ spend_inputs(t),
                                    ∃ t_1 ∈ txs
                                     : ¬ t = t_1
                                     ∧ i ∈ spend_inputs(t_1)
                                    
                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Computation #

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem AllInputsValid.DoubleSpendViolation.Computation_none {txs : List FlattenTransaction} (H : Computation txs = none) (t : FlattenTransaction) :
                                        t ∈ txs → ∀ i ∈ t.inputs, ∀ t' ∈ txs, ¬t = t' → i ∉ t'.inputs

                                        Computation Thread #

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          DoubleWithdraw Violation #

                                          Property:

                                           ∃ w, w_1 ∈ withdrawals
                                           : ¬ w = w_1
                                           ∧ l2_outref(w) = l2_outref(w_1)
                                          
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            Computation #

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For
                                              theorem AllInputsValid.DoubleWithdrawViolation.Computation_none {wts : Withdrawals} (H : Computation wts = none) (w : Withdrawal) :
                                              w ∈ wts → ∀ w' ∈ wts, ¬w.1 = w'.1 → ¬w.2.l2_outref = w'.2.l2_outref

                                              Computation Thread #

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For

                                                Lemmas #

                                                We need to prove that our Computation Threads are checking the property we want.

                                                Verification #

                                                We define a property AllValidProp and we claim that we can split it into different fraudproofs:

                                                However, these props are at different levels.

                                                The main prop AllValidProp is at the ledger level and the other ones are at the block level.

                                                Fraud Proof #

                                                In this section, we define the scripts and the fraudproofs as inductive types. We are forgetting about the different scripts steps and if they are proving the original statement or not.

                                                In other words, this is a quick fix to have a mechanized implementation of the FraudProof mechanisim.