|
| 1 | + |
| 2 | +import Cli |
| 3 | +import Linleios |
| 4 | +import Parser.Char.Numeric |
| 5 | +import Parser.Stream |
| 6 | + |
| 7 | +open Cli |
| 8 | +open Lean (Json) |
| 9 | + |
| 10 | + |
| 11 | +instance : ParseableType Float where |
| 12 | + name := "Float" |
| 13 | + parse? x := match (Parser.Char.ASCII.parseFloat : SimpleParser Substring Char Float).run x with |
| 14 | + | .ok _ y => some y |
| 15 | + | _ => none |
| 16 | + |
| 17 | + |
| 18 | +def runMarkovCmd (p : Parsed) : IO UInt32 := |
| 19 | + do |
| 20 | + let activeSlotCoefficient : Float := p.flag! "active-slot-coefficient" |>.as! Float |
| 21 | + let Lheader : Nat := p.flag! "l-header" |>.as! Nat |
| 22 | + let Lvote : Nat := p.flag! "l-vote" |>.as! Nat |
| 23 | + let Ldiff : Nat := p.flag! "l-diff" |>.as! Nat |
| 24 | + let committeeSize : Nat := p.flag! "committee-size" |>.as! Nat |
| 25 | + let τ : Float := p.flag! "quorum-fraction" |>.as! Float |
| 26 | + let pRbHeaderArrives : Float := p.flag! "p-rb-header-arrives" |>.as! Float |
| 27 | + let pEbValidates : Float := p.flag! "p-eb-validates" |>.as! Float |
| 28 | + let pLateDiffusion : Float := p.flag! "p-late-diffusion" |>.as! Float |
| 29 | + let fAdversary : Float := p.flag! "adversary-fraction" |>.as! Float |
| 30 | + let ε : Float := p.flag! "tolerance" |>.as! Float |
| 31 | + let rbCount : Nat := p.flag! "rb-count" |>.as! Nat |
| 32 | + let env := makeEnvironment Lheader Lvote Ldiff activeSlotCoefficient committeeSize.toFloat τ pRbHeaderArrives pEbValidates pLateDiffusion fAdversary |
| 33 | + let sn := simulate env default ε rbCount |
| 34 | + if p.hasFlag "output-file" |
| 35 | + then IO.FS.writeFile (p.flag! "output-file" |>.as! String) (Json.pretty $ ebDistributionJson sn) |
| 36 | + IO.println s!"RB efficiency: {(reprPrec (rbEfficiency sn) 0).pretty}" |
| 37 | + IO.println s!"EB efficiency: {(reprPrec (ebEfficiency sn) 0).pretty}" |
| 38 | + IO.println s!"Overall efficiency: {(reprPrec (efficiency sn) 0).pretty}" |
| 39 | + IO.eprintln s!"Missing probability: {1 - totalProbability sn}" |
| 40 | + pure 0 |
| 41 | + |
| 42 | +def markov : Cmd := `[Cli| |
| 43 | + markov VIA runMarkovCmd; ["0.0.1"] |
| 44 | + "Run a Markov simulation of Linear Leios." |
| 45 | + FLAGS: |
| 46 | + "active-slot-coefficient" : Float ; "The active slot coefficient for RBs, in probability per slot." |
| 47 | + "l-header" : Nat ; "L_header protocol parameter, in slots." |
| 48 | + "l-vote" : Nat ; "L_vote protocol parameter, in slots." |
| 49 | + "l-diff" : Nat ; "L_diff protocol parameter, in slots." |
| 50 | + "committee-size" : Nat ; "Expected number of voters in the committee, out of 2500 stakepools total." |
| 51 | + "quorum-fraction" : Float ; "τ protocol parameter, in %/100." |
| 52 | + "p-rb-header-arrives" : Float ; "Probability that the RB header arrives before L_header." |
| 53 | + "p-eb-validates" : Float ; "Probability that the EB is fully validated before 3 L_header + L_vote." |
| 54 | + "p-late-diffusion" : Float ; "Probability than a RB producer hasn't validated the previous EB." |
| 55 | + "adversary-fraction" : Float ; "Fraction of stake that is adversarial: the adversary never produces RBs or EBs and never votes." |
| 56 | + "tolerance" : Float ; "Discard states with less than this probability." |
| 57 | + "rb-count" : Nat ; "Number of potential RBs to simulate." |
| 58 | + "output-file" : String ; "Path to the JSON output file for the EB distribution." |
| 59 | + EXTENSIONS: |
| 60 | + defaultValues! #[ |
| 61 | + ("active-slot-coefficient", "0.05") |
| 62 | + , ("l-header" , "1" ) |
| 63 | + , ("l-vote" , "4" ) |
| 64 | + , ("l-diff" , "7" ) |
| 65 | + , ("committee-size" , "600" ) |
| 66 | + , ("quorum-fraction" , "0.75") |
| 67 | + , ("p-rb-header-arrives" , "0.95") |
| 68 | + , ("p-eb-validates" , "0.90") |
| 69 | + , ("p-late-diffusion" , "0.05") |
| 70 | + , ("adversary-fraction" , "0" ) |
| 71 | + , ("tolerance" , "1e-8") |
| 72 | + , ("rb-count" , "100" ) |
| 73 | + ] |
| 74 | +] |
| 75 | + |
| 76 | +def main (args : List String) : IO UInt32 := |
| 77 | + markov.validate args |
0 commit comments