I'm design a lottery smart contract. The lottery is like this:

  1. the lottery will be drawed everyday;
  2. 24 hours of one day is split to active period(23 hours), freeze period(30 mins), and draw period(30 mins);
  3. users can bet and apply for reward only in active period;

the contract use the latest 6 blockhash, and current block's timpstamp as seed to generate random, because no-one can bet in freeze period and draw period, no-one can bet a set of number base on a known blockhash.

Is it a safely design for a lottery smart contract?

still more. i plan to using the latest 6 blockhash to generate the randomness, like this:
keccak256(block.blockhash(block.blocknumber-1), block.blockhash(block.blocknumber-6),block.blocktimpstamp);

it will consume more gas. but, is it safe?

  • I think it is a good design. There will be always some weak points. The miners are here the possible weak point as other answers have pointed out. If your prize is not bigger than the reward of mining a block, then you are on the safe side. – Jaime Jul 19 '18 at 13:52
  • The block's timestamp can be set to an arbitrary value within a specific range by the miner of the block. See also ethereum.stackexchange.com/questions/419/… – lungj Jul 19 '18 at 16:29

No! This is completely vulnerable to manipulation by miners. Miners get to pick block.timestamp arbitrarily within a reasonably large range and so the miner can simply pick it so that they win the lottery every time.

For a longer discussion of randomness, see How can I securely generate a random number in my smart contract?

|improve this answer|||||

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