Random audits can generally solve this. Take a random count from a random machine and validate that it matches the hand count. If I’m trying to rig an election I would have to be very reckless to just cross my fingers and hope that the systems I hacked aren’t audited. I’d have to bribe the auditors or something, and at that point it’s simpler to just bribe people anyway and not bother with the whole hacking part.