Provably correct programs verified for the hardware they are running on are possible (seL4 is one of a few examples). Their development is very time consuming though. There are caveats, but it's possible, in principle, to fully block certain attack vectors (for example, network access). The attackers then should go a more expensive and dangerous human manipulation or physical access route.
ASI (artificial superintelligence), theoretically, can exploit the ultimate analog nature of digital circuits (something like Plundervolt, but more intricate), but if we'd get to this stage when we need to defend against ASI, we'd have bigger problems.