Skip to content

10. Proving nothing leaks

In a battle royale, what you cannot see matters as much as what you can. A jet behind you, outside your radar, must not show up on your screen. That includes its data arriving at your browser and simply not being drawn, because anyone can open the browser's developer tools.

So the engine decides what each player may know, and proves it. This chapter reads Adawars.Views.

Coverage

A player sees what their radar covers while their jet flies, plus what the seekers of their own missiles cover:

engine/src/adawars-views.ads
   function Covered (W : World; P : Player_Id; Target : Point) return Boolean
   is ((W.Jets (P).State = Flying
        and then Detects
                   (Radar, W.Jets (P).Pos, W.Jets (P).Heading, Target))
       or else
         (for some S in Slot =>
            W.Missiles (P) (S).Active
            and then Detects
                       (Weapons (W.Missiles (P) (S).Kind).Seeker,
                        W.Missiles (P) (S).Pos,
                        W.Missiles (P) (S).Heading,
                        Target)))
   with Pre => P <= W.Players;

Detects is the same sensor test guidance uses (chapter 5). One definition of detection serves both: what a heat-seeker can chase and what a player can see.

What a view contains

A player's view is an Observation. Other jets appear in it as contacts:

engine/src/adawars-views.ads
   type Contact is record
      Seen    : Boolean;
      Pos     : Point;
      Heading : Angle;
      --  Ticks it has been held armed for self-destruct: a threat only
      --  those who see the jet can see.
      Fuse    : Fuse_Burned;
   end record;

   Unseen : constant Contact :=
     (Seen => False, Pos => Centre, Heading => 0, Fuse => 0);

An unseen jet is not left out of the array. It is there, as the constant Unseen, which is the same for every unseen jet and so carries no information. Note that it does not say "unseen, at the jet's real position". A Seen flag next to real data would leave hiding the data to whoever reads the flag.

The view, and its proof

Observe builds the view as one expression:

engine/src/adawars-views.ads
       Contacts =>
         [for Q in 1 .. W.Players =>
            (if Seen_Jet (W, P, Q)
             then (Seen    => True,
                   Pos     => W.Jets (Q).Pos,
                   Heading => W.Jets (Q).Heading,
                   Fuse    => W.Jets (Q).Fuse)
             else Unseen)],

and states the no-leak property as its postcondition:

engine/src/adawars-views.ads
       --  No leaks, and nothing withheld: another jet is in the view
       --  exactly when it is covered, and then as it really is.
       and then (for all Q in 1 .. W.Players =>
                   (if Seen_Jet (W, P, Q)
                    then Observe'Result.Contacts (Q).Seen
                         and then Observe'Result.Contacts (Q).Pos
                                  = W.Jets (Q).Pos
                    else Observe'Result.Contacts (Q) = Unseen))

It says two things, and both matter:

  • No leaks: a jet the player does not see is exactly Unseen.
  • Nothing withheld: a jet the player does see is in the view, at its true position.

Missiles get the same treatment, with one more rule: a missile's lock is shown only to its owner. Flares are the deliberate exception. Everyone sees a burning flare, which is what it costs to drop one:

engine/src/adawars-views.ads
   --  A burning flare lights up the sky: everyone sees it, sensors or not.
   --  That is its cost; it decoys heat-seekers but shows every player where
   --  its jet just was.
   function Seen_Flare (W : World; P, Q : Player_Id; S : Flare_Slot)
     return Boolean
   is (W.Flares (Q) (S).Active)

The server sends each player Observe (W, P) and nothing else. Since the hiding happens inside the proved engine, no bug in the server or the browser can reveal more. They never have it.

Try it

Leak a position. Make an unseen contact carry its jet's real position:

Try: engine/src/adawars-views.ads
                    Fuse    => W.Jets (Q).Fuse)
-             else Unseen)],
+             else (Unseen with delta Pos => W.Jets (Q).Pos))],

The leak is one field wide and the Seen flag is still False, so a client that checks the flag would never draw it. The prover does not care what a client would do:

Expect: prove adawars-views.ads fails
postcondition might fail, cannot prove Observe'Result.Contacts (Q) = Unseen

Recap

  • Decide what each party may know in the proved core, not in the code that displays it.
  • Represent hidden things by a constant that carries no information.
  • State both directions: nothing hidden is shown, and nothing shown is hidden.
  • Reuse one definition (here, Detects) wherever the same idea appears, so that the proofs agree with each other.