I am writing to inquire feasible strategies to defeat Transaction Ordering Dependence (TOD) bugs.
I learned from the best practice guideline such that we can use a so-called "pre-committed" scheme to defeat TOD attacks: https://consensys.github.io/smart-contract-best-practices/known_attacks/#front-running-aka-transaction-ordering-dependence
However, it is still unclear to me how does the "pre-committed" scheme is implemented. Could anyone shed some lights or some code fragment of such implementations? Also, besides such "pre-committed" scheme, what else can be done to defeat TOD attacks?
======== update ====================
contract TransactionOrdering { uint256 price; address owner; function buy(uint256 amount) { cost = price * amount return cost; } function setPrice(uint256 _price) { // owner can set the price. if (msg.sender == owner) price = _price; } } Let's suppose when the contract owner see a transaction of buy from the user, then the owner front runs a setPrice transaction to raise the price. Can the pre-committed pattern be used to defeat such attacks? Thanks a lot.