Your own moral code, your own inner code of ethics, your own personal conscience as the ultimate rule. This is far more robust than any legal system, which can be gamed. Or in other words:
There are things you can do legally (which conflict with your own inner code of ethics).
Avoid these types of ‘legal’ transactions.
Takeaway point:
If you can sleep at night, you’re doing the right thing.