I'm wondering if the following scenario could work with smart contracts. I'm very new to Blockchain so what I'm saying might sound too silly.

I have 10 users who are sharing a common resource. There is an efficient resource allocation mechanism (which I'm not gonna explain for the sake of simplicity). The allocation mechanism receives some information from each user and decides on a final allocation. I do not have a central trustable entity to run the mechanism and none of the users is trusted by all the others so we can choose them as the host to run the mechanism.

1- Does it make sense to say let us allow all the users run the mechanism as a smart contract and record the results in the blockchain?

2- If yes, the problem is that the mechanism needs the information from all the users to run properly and this information is private to each user. Is there any solution for this?

  • This question is difficult to answer without additional information. Which information exactly does the mechanism need from the users? – ivicaa Apr 6 '18 at 18:15
  • @ivicaa Simply stated, the mechanism is a double-auction mechanism. So it requires two parameters from each user. 1- The quantity of the resource unit required and 2- Their bid/ask value for each unit (depending on if it's a buyer/seller user who wants to buy/sell excess resources). – Nima Afraz Apr 7 '18 at 12:48

A blockchain (at least Ethereum's) is not very good for dealing with race conditions when multiple users want the same finite resource(s). The reason is that you can't know for sure whose request gets processed first if they are in the same block. Even if they are in different blocks you can't be sure which block ends up being in the canonical chain (unless the other block is on top of the previous block in the chain).

What you'd basically need is a two-phased contract:

1) Whenever someone requests a resource, mark the request in the contract

2) When the request has been mined, wait for X confirmation (blocks on top of the block which included the request. The higher the X, the more sure you can be). If, after X blocks/confirmations, there are no competing and/or mutually exclusive requests, mark the resource as given to the contract and the situation is resolved. If you see a conflict, you can either deny all conflicting requests or decide on one.

About your second question: smart contracts are very bad in keeping secrets. If it's ok that the contract has no direct access to the data, you could encrypt it off-the-chain and send it to the contract in encrypted format. There are some other alternatives (for example public key cryptography) but they are very expensive gas-wise and I haven't heard that someone had really tried them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.