Possible race condition when submiting solutions to problems posed in a contract.

I thought of this scenario:

Bob posts a contract which will pay users for a solution to a problem, say Bob want's help solving a sudoku or similar.
He posts the sudoku in a contract together with an ether reward.
The contract itself will verify that the solution is correct and pay out the reward.

Alice spends a lot of work solving the sudoku and posts the solution as a transaction to the ethereum block chain.

Since transactions are broadcasted, Eve also reads the solution of the transaction and posts her own transaction with the stolen solution.

Since timestamps are only sequential for each block and miners can get the transactions in arbitrary order, a race condition occurs which enables Eve to get half the rewards, possibly more if she gets help from Sybil. If implementation takes transactions from a pile in a certain order, Eve could also possibly tweak her message to get first in line when a miner processes the transactions

Is there an ethereum-internal way to handle this very common scenario?

One possible way to get around this would be for Alice to send a "solution reservation" transaction, with a hash of the solution, thus reserving it, wait one block and then post the actual solution. She would then be ahead of Eve & Sybil.



  • chris613chris613 Member Posts: 93 ✭✭
    Your "solution reservation" idea is neat, I swear I've read something like that in another context (still cryto related) but can't recall at the moment what it was...
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    I dont think you can talk privately, so the reservation is probably the way to go.

    Didnt realize that 'just ask for a solution' is a way to cheapen any computation for which checking is cheaper than computing plus any extra transaction fees. Reckon you dont always need to pay for it either, often you can just force one of the parties involved to calculate it for you.
  • mimarobmimarob Member Posts: 33
    Hi Chris, it's probably old hat in crypto sciences, I come from the application side..

    Jasper, There is still a cost involved in verifying the solution. What brings that cost up is that the calculation (I think) has to be re-done by all nodes in the ethereum network. Also storing the solution will take place at a lot of nodes.

  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    @mimarob: The whole point is to decrease the computation load of nodes on the entire network. Also from the contract owners' perspective, computation on-chain is much more expensive than off-chain.(off-chain is practically free)

    cost_checking +extra_transaction_costs < cost_calculating

    Then it is better to calculate off-chain and check. It depends on the problem if that is actually the case..

    "I think minimizing some value with a bunch of parameters" could be one, the guy getting the lowest value within a time period gets paid. Not strictly 'checking' though. (and even then, often an analytical approach is cheaper)
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    Often the a program of the solution of simply be publicly known, of course, the user of the contract simply pays for not having to be online to send the result, install the program.

    For the latter, i feel if people use program and are able to run them on their computer, they at least should have it available.
  • mimarobmimarob Member Posts: 33
    hmm, yep, verification is to take place online, I originally tried to aim cheaper by just letting anyone publish a solution and then let the off-line programs verify and discard crap solutions. Spam-like crap solutions would probably not be very much since they also will cost storage.

    Come to think of it I should prolly make two competing implementations:

    One which just holds the solutions and their current owner, since solutions can bev bought and sold. The risk here is for rule-interpretation sliding, solutions originally considered faulty could also gain a value and be bought and sold.

    The other variety is to compute the scores for the solutions online, one nice feature, except from discarding crap solutions, never allowing them to publish in the first place, one could also do wicked things like invalidating old solutions, putting all the previous value into the new better solution. One way to do this is to take away the possibility of owner change for the old worse solutions.
Sign In or Register to comment.