  Self-testing a quantum device means verifying the existence of a certain
quantum state as well as the effect of the associated measurements based only
on the statistics of the measurement outcomes. Robust, i.e., error-tolerant,
self-testing quantum devices are critical building blocks for quantum
cryptographic protocols that rely on imperfect or untrusted quantum devices. We
give a criterion which determines whether a given binary XOR game is robust
self-testing with the asymptotically optimal error parameter. As an
application, we prove that the celebrated CHSH game is an optimally robust
self-test. We also prove the same for a family of tests recently proposed by
Acin et al. (PRL 108:100402, 2012) for random number generation, thus extending
the benefit of the latter tests to allow imperfect or untrusted quantum
devices.
