1

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?

closed as primarily opinion-based by Nicolas Massart, Achala Dissanayake, Vignesh Karthikeyan, Ismael, Badr Bellaj Jul 23 '18 at 11:22

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
1

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?

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