Documentation

FraudProof.L2

Arranger Block Validity Fraud Proofs #

We explore a simple protocol with two kind of players: One proposing blocks and the other just challenging.

The main goal is to prove that when we have an honest challenger challenging only /good/ blocks are accepted: See honest_chooser_valid

Player One (Proposer) #

Player one, the player proposing elements, actions are to propose a new block da : BTree α × ℍ. Since we do not have IO, upon propsing a new block, they player also provides all possible strategies for all elements.

structure P1_Actions (α : Type) :
Instances For

    Local Validity #

    We define a local valid block Local_valid to a block that hashes to a given hash, holds only valid elements and has no duplicates.

    structure Local_valid {α : Type} [DecidableEq α] [Hash α ] [HashMagma ] (data : BTree α) (mk : ) (val_fun : αBool) :
    Instances For

      Helper function building a complete tree from a sequence of 2^lgn elements.

      def Valid_Seq {α : Type} {lgn : } [DecidableEq α] [Hash α ] [HashMagma ] (data : Sequence (2 ^ lgn) α) (merkle_tree : ) (P : αBool) :
      Equations
      Instances For

        Same as Local_valid but instead of having a struct, we just have a Prop.

        def local_valid {α : Type} [DecidableEq α] [Hash α ] [HashMagma ] (da : BTree α × ) (val_fun : αBool) :
        Equations
        Instances For
          theorem struct_and_iff_valid {α : Type} [DecidableEq α] [Hash α ] [HashMagma ] (data : BTree α) (mk : ) (val_fun : αBool) :
          Local_valid data mk val_fun local_valid (data, mk) val_fun

          PLayer 2 (Challenger) #

          The second player, bsaed on what the player one (proposer) proposes, can perform one of the following actions:

          1. DAC challenge
          2. Element invalid challenge
          3. Duplicate elements challenge
          4. accept the block as valid
          inductive P2_Actions (α : Type) :
          Instances For

            L2 Local Linear Protocol #

            Simple linear protocol: no optimizations as logarithmic search. There is no time involved: we assume players have all the time in the world to play and there is no rush. We assume players play to win, and we do not reason about the incentives they have to beahve like that. If plaer two wins, the proposed block is discarded and nothing else happens. In the real protocol, we player one should be penalized.

            Helper function defining actions taken after player one moved.

            def inner_l2_actions {α : Type} [BEq α] [BEq ] [o : Hash α ] [HashMagma ] (val_fun : αBool) (playerOne : P1_Actions α ) (playerTwo : P2_Actions α ) :
            Equations
            Instances For

              Definition of L2 protocol playing linear games.

              def linear_l2_protocol {α : Type} [BEq α] [BEq ] [o : Hash α ] [HashMagma ] (val_fun : αBool) (playerOne : P1_Actions α ) (playerTwo : BTree α × P2_Actions α ) :
              Equations
              Instances For

                Crafting Honest Players. #

                Witness Finding. #

                structure IH ( : Type) :
                • side : SkElem
                • spine :
                • sib :
                Instances For
                  structure Witness (α : Type) :
                  Instances For

                    Find leftest invalid value

                    def find_left_invalid_path {α : Type} [o : Hash α ] [m : HashMagma ] (val : αBool) :
                    BTree αOption (Witness α )
                    Equations
                    Instances For
                      theorem find_valid_nothing {α : Type} [o : Hash α ] [m : HashMagma ] (val : αBool) (t : BTree α) (valid : BTree.fold val and t = true) :
                      theorem find_nothing_is_valid {α : Type} [o : Hash α ] [m : HashMagma ] (val : αBool) (t : BTree α) :
                      theorem find_invalid_path_accessed {α : Type} [o : Hash α ] [m : HashMagma ] (val : αBool) (t : BTree α) (wit : Witness α ) :
                      find_left_invalid_path val t = some witABTree.iaccess t (Sequence.map (fun (f : IH ) => f.side) wit.pathInfo) = some (Sum.inl wit.src) val wit.src = false
                      def generate_merkle_tree {α : Type} [o : Hash α ] [m : HashMagma ] (data : BTree α) :
                      ABTree α
                      Equations
                      Instances For
                        def gen_chooser_opt' { : Type} [BEq ] (data : × ) (proposed : × × ) :
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Honest player two. Check each condition and if the proposed block violates one, it generates a witness and challenges the validity of such block.

                          def honest_chooser {α : Type} [DecidableEq α] [BEq ] [Hash α ] [m : HashMagma ] (val_fun : αBool) (public_data : BTree α) (da_mtree : ) :
                          P2_Actions α
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem const_comp {α β γ : Type} (f : αβ) (g : γ) :
                            (fun (x : β) => g) f = fun (x : α) => g
                            theorem gen_chooser_opt_some { : Type} [BEq ] :
                            ((fun (fhs : × × Option ChooserMoves) (x : × × ) => fhs x) gen_chooser_opt) some = (fun (fhs : × × Option ChooserMoves) (x : × × ) => fhs x) gen_chooser_opt'
                            theorem fold_getI_hash {α : Type} [o : Hash α ] [m : HashMagma ] (b : ABTree α Unit) :
                            ABTree.fold o.mhash (fun (x : Unit) => m.comb) b = ABTree.getI' o.mhash (fun (x : × ) => m.comb x.1 x.2) b.hash_SubTree

                            Honest chooser finds correct witnesses, and thus, it always wins the challenging games (if played.)

                            theorem honest_chooser_wins {α : Type} [BEq ] [LawfulBEq ] [o : Hash α ] [m : HashMagma ] (da : BTree α) :
                            winning_condition_player (fun (hc : ) (a : α) (h : ) => dac_leaf_winning_condition hc a h = true) (fun (_x : Unit) (x : × ) (res : ) => dac_node_winning_condition res x.1 x.2 = true) (fun (_x : ) => id) { data := ABTree.map o.mhash id da, res := ABTree.fold o.mhash (fun (_x : Unit) => m.comb) da } (ABTree.map some some (ABTree.hash_SubTree da))

                            Honest player do not challenge valid blocks

                            theorem honest_chooser_accepts_valid {α : Type} [DecidableEq α] [BEq ] [LawfulBEq ] [o : Hash α ] [m : HashMagma ] (val_fun : αBool) (data : BTree α) (mk : ) (da_valid : Local_valid data mk val_fun) :

                            L2 Protocol and Honest player #

                            theorem inner_honest_valid_dac_wrong {α : Type} [DecidableEq α] [BEq ] [LawfulBEq ] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (da : BTree α × ) (dac_str : ABTree (Option α) (Option ( × ))) (gen_elem_str : {n : } → ISkeleton nSequence n (Option ( × )) × Option α) (Hm : (da.2 == ABTree.fold o.mhash (fun (x : Unit) => m.comb) da.1) = false) :
                            (linear_l2_protocol val_fun { da := da, dac_str := dac_str, gen_elem_str := gen_elem_str } fun (x : BTree α × ) => honest_chooser val_fun x.1 x.2) = false

                            Helper lemma, if a block is accepted by linear_l2_protocol, then that block is valid.

                            theorem inner_honest_valid {α : Type} [DecidableEq α] [BEq ] [LawfulBEq ] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (da : BTree α × ) (dac_str : ABTree (Option α) (Option ( × ))) (gen_elem_str : {n : } → ISkeleton nSequence n (Option ( × )) × Option α) :
                            (linear_l2_protocol val_fun { da := da, dac_str := dac_str, gen_elem_str := gen_elem_str } fun (x : BTree α × ) => honest_chooser val_fun x.1 x.2) = truelocal_valid da val_fun

                            Valid blocks are accepted by the linear_l2_protocol .

                            theorem honest_chooser_valid_local_valid {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_Actions α ) :
                            local_valid p1.da val_fun(linear_l2_protocol val_fun p1 fun (x : BTree α × ) => match x with | (t, mt) => honest_chooser val_fun t mt) = true

                            Main theorem, the L2 Protocol linear_l2_protocol accepts valid blocks and every block accepted by the protocol is valid, when equipped with the honest player two.

                            theorem honest_chooser_valid {α : Type} [BEq ] [LawfulBEq ] [DecidableEq α] [o : Hash α ] [m : HashMagma ] [InjectiveHash α ] [InjectiveMagma ] (val_fun : αBool) (p1 : P1_Actions α ) :
                            (linear_l2_protocol val_fun p1 fun (x : BTree α × ) => match x with | (t, mt) => honest_chooser val_fun t mt) = true local_valid p1.da val_fun