And just to be clear, it is well within the realm of possibility to write such code and (I think) such law. Neither the technical nor the legal is the obstacle here.
This is a political problem, in the broad sense of “political,” i.e. what people believe, which people have power, and how are society as a whole makes collective decisions.