Documentation

FraudProof.History_L2

Stateful Protocol. #

History Protocol takes into account the whole history of the L2 Protocol.

The main difference is that blocks are conditional valid depending on the elements that were added before the current block (the History.)

Main Definition is that valid now checks that elements do not occurr more than once across the whole history. Here we are a bit redundant, because historic non-duplication implies local non-duplication. However, we choosed to follow a compositional approach. Eventually, we may be interested in adding more properties and it is worth exploring such approach.

So historical_valid is local_valid plus no-duplicates accross history.

def historical_valid {α : Type} [DecidableEq α] [Hash α ] [HashMagma ] (Hist : List (BTree α × )) (val_fun : αBool) :
Equations
Instances For

    Lemma historical_concat characterizes the evolution of the definition historical_valid everytime we add a new block. Since the protocol evolves linearly adding new blocks, this lemma simplifies the following proofs.

    theorem historical_concat {α : Type} [DecidableEq α] [Hash α ] [HashMagma ] (hist : List (BTree α × )) (new : BTree α × ) (val_fun : αBool) :
    historical_valid (hist ++ [new]) val_fun = (historical_valid hist val_fun ((List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten ++ new.1.toList).Nodup local_valid new val_fun)

    Player two, the player acting as challenger, on top of the previous moves defined in L2.lean file, can also challenge new blocks of duplicating elements across history.

    inductive P2_History_Actions (α : Type) :
    Instances For

      Player one actions are defending the elements they present.

      structure P1_History_Actions (α : Type) :
      Instances For

        Duplicates in History #

        We define how we find elements and duplicates.

        def find_first_dup_in_history {α : Type} [DecidableEq α] (elems : List (Skeleton × α)) (hist : List (BTree α × )) :
        Option ((List (BTree α × ) × (BTree α × ) × List (BTree α × )) × (List (Skeleton × α) × (Skeleton × α) × List (Skeleton × α)) × List (Skeleton × α) × (Skeleton × α) × List (Skeleton × α))
        Equations
        Instances For
          theorem no_dups_find_first_none {α : Type} [DecidableEq α] (elems : List (Skeleton × α)) (hist : List (BTree α × )) (HDis : (List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten.Disjoint (List.map (fun (x : Skeleton × α) => x.2) elems)) :
          theorem find_first_dup_in_history_none {α : Type} [DecidableEq α] (elems : List (Skeleton × α)) (hist : List (BTree α × )) (HNoFind : find_first_dup_in_history elems hist = none) :
          (List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten.Disjoint (List.map (fun (x : Skeleton × α) => x.2) elems)
          theorem find_first_dup_in_history_law {α : Type} [DecidableEq α] {t : BTree α} {hist pre post : List (BTree α × )} {oldDA : BTree α × } {oldE currE : Skeleton × α} {preOld posOld preCurr posCurr : List (Skeleton × α)} (H : find_first_dup_in_history t.toPaths_elems hist = some ((pre, oldDA, post), (preOld, oldE, posOld), preCurr, currE, posCurr)) :
          ABTree.access oldDA.1 oldE.1 = some (Sum.inl oldE.2) ABTree.access t currE.1 = some (Sum.inl currE.2) oldE.2 = currE.2 hist[pre.length]? = some oldDA

          Honest PLayer #

          Honest players check new blocks to see if they check the required conditions and if not, they build a challengin move.

          def historical_honest_algorith {α : Type} [DecidableEq α] [BEq ] [Hash α ] [m : HashMagma ] (val_fun : αBool) (history : List (BTree α × )) (public_data : BTree α) (da_mtree : ) :
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem List.Disjoin_iff_forall {α : Type} {l r : List α} [DecidableEq α] :
            l.Disjoint r il, jr, (i != j) = true
            theorem honest_chooser_history_accepts_valid {α : Type} [DecidableEq α] [BEq ] [LawfulBEq ] [o : Hash α ] [m : HashMagma ] {val_fun : αBool} {history : List (BTree α × )} {new : BTree α × } (da_valid : historical_valid (history ++ [new]) val_fun) :
            theorem Nodups_no_dups_in_history {α : Type} [DecidableEq α] [BEq ] [Hash α ] [m : HashMagma ] (val_fun : αBool) (history : List (BTree α × )) (public_data : BTree α) (da_mtree : ) (HDis : (List.map (fun (x : BTree α × ) => x.1.toList) history).flatten.Disjoint public_data.toList) :
            historical_honest_algorith val_fun history public_data da_mtree = P2_History_Actions.Local (honest_chooser val_fun public_data da_mtree)

            L2 History Protocol #

            The protocol consists on a player providing information and another player challenging such information. Since we do not have IO here, all players must build and provide all strategies before hand.

            def linear_l2_historical_protocol {α : Type} [BEq α] [BEq ] [o : Hash α ] [HashMagma ] (val_fun : αBool) (hist : List (BTree α × )) (playerOne : P1_History_Actions α ) (playerTwo : List (BTree α × )BTree α × P2_History_Actions α ) :
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem history_honest_chooser_no_intersect_hist {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_History_Actions α ) (hist : List (BTree α × )) (histCorrect : ehist, e.1.hash_BTree = e.2) (HHist : (List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten.Nodup) :
              (linear_l2_historical_protocol val_fun hist p1 fun (h : List (BTree α × )) (x : BTree α × ) => match x with | (t, mt) => historical_honest_algorith val_fun h t mt) = true((List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten ++ p1.local_str.da.1.toList).Nodup
              theorem history_honest_chooser_local_valid {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_History_Actions α ) (hist : List (BTree α × )) (HNodups : ((List.map (fun (x : BTree α × ) => x.1.toList) hist).flatten ++ p1.local_str.da.1.toList).Nodup) :
              (linear_l2_historical_protocol val_fun hist p1 fun (h : List (BTree α × )) (x : BTree α × ) => match x with | (t, mt) => historical_honest_algorith val_fun h t mt) = truelocal_valid p1.local_str.da val_fun
              theorem history_honest_chooser_valid {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_History_Actions α ) (hist : List (BTree α × )) (hist_valid : historical_valid hist val_fun) :
              (linear_l2_historical_protocol val_fun hist p1 fun (h : List (BTree α × )) (x : BTree α × ) => match x with | (t, mt) => historical_honest_algorith val_fun h t mt) = truehistorical_valid (hist ++ [p1.local_str.da]) val_fun
              theorem history_honest_chooser_valid' {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_History_Actions α ) (hist : List (BTree α × )) (AllValid : historical_valid (hist ++ [p1.local_str.da]) val_fun) :
              (linear_l2_historical_protocol val_fun hist p1 fun (h : List (BTree α × )) (x : BTree α × ) => match x with | (t, mt) => historical_honest_algorith val_fun h t mt) = true

              Theorem HistoryProtocol states that the history protocol when played with an honest player challenging proposed blocks only accepts correct blocks (->) and correct blocks are accepted by the protocol (<-).

              theorem HistoryProtocol {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_History_Actions α ) (hist : List (BTree α × )) :
              (linear_l2_historical_protocol val_fun hist p1 fun (h : List (BTree α × )) (x : BTree α × ) => match x with | (t, mt) => historical_honest_algorith val_fun h t mt) = true historical_valid hist val_fun historical_valid (hist ++ [p1.local_str.da]) val_fun