From this article I understand that randomness can only be secured by

External oracles


Commit–reveal approach

However, in the case that I am okay to have a pseudo random number generator which is manipulatable by miners. What would be the best approach to still "secure" it, in terms of make it most expensive for a malicious user to manipulate?

Are there any other factors I can use except:

block.coinbase represents the address of the miner who mined the current block.
block.difficulty is a relative measure of how difficult it was to find the block.
block.gaslimit restricts maximum gas consumption for transactions within the block.
block.number is the height of current block.
block.timestamp is when the block was mined.
block.blockhash(block.number), which is the blockhash of the current block.
block.blockhash(block.number - 1), which is the blockhash of the last block.
block.blockhash() of a block that is at least 256 blocks older than the current one.

1 Answer 1


The block hash should be good enough for most applications. If this is used to decide winners of ether or other currencies the miner will be destimated from doing something if the price is lower than the block reward.

Also you should use the block hash of a block in the future. That is, if you are running a lottery you first close the purchases and then wait for several block before getting the block hash. This will avoid someone from buying a ticket in the same block when the winner is selected.

Commiting a number should be easy as well, you publish the hash and when the lottery finish you combine your commitment with the block hash, in this way the miner has no power any more but also you as the owner have no power over the result. You will reveal the number at the end so that people can verify the result.

The solution of the Oracle is good but it also requires trust, despite the proof of authenticity is provided you still trust that sources like random.org are genuine or that has not been compromised.

In summary, for prizes that are small, blockhash is more than enough as long as you close the lottery at one particular block and use the hash of a block in the future ( meaning that you wait some time to get the blockhash).

The most secure strategy is to combine several sources.

Hope this helps.

  • Thank you for the reply. Still not 100% answer I was looking for. ;) In terms of cost for the malicious miner. What is the best solution to use? The way to make it most expensive.
    – Senju
    Jun 26, 2018 at 4:50
  • what do you mean by expensive?
    – Jaime
    Jun 26, 2018 at 4:53
  • in terms of $$$ - wouldn't there be a difference? e.g. it is worse for the miner to manipulate the timestamp than the blockhash.
    – Senju
    Jun 26, 2018 at 5:09
  • I do not think I can help you further. Good luck.
    – Jaime
    Jun 26, 2018 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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