Linked Questions

1
vote
1answer
1k views

BlockHash used for random number generation [duplicate]

I am designing a lottery smart contract. A winning ticket number is drawn from a pool of tickets. In order to do this, I use the following code: bytes32 blockhash = block.blockhash(block.number - 1);...
3
votes
1answer
450 views

Are future block hashes viable as an RNG? [duplicate]

Let's say I want to make a gambling contract. Anyone can call the createWager function to create a new bet to flip a coin. When they win, in order to collect the payment for the wager, they have to ...
3
votes
1answer
107 views

Risk of using BlockHash, other miners preventing attack. [duplicate]

When I read about the risk of using the blockhash as a random number it was explained to me the issue was that a miner can trow away the block if the block-hash is not in his advantage, and keeps ...
152
votes
17answers
42k views

How can I securely generate a random number in my smart contract?

If I am writing a smart contract for some kind of (gambling) game, how can I generate a random number securely? What are the best practises and security trade-offs to be aware of?
25
votes
3answers
6k views

Can a contract safely rely on block.timestamp?

How safe is it to use block.timestamp as contract expiration time? If a miner provides an incorrect timestamp in a block header, how much can it be off before it is rejected by other nodes? Is there a ...
5
votes
2answers
2k views

Honest lottery winner generation - pseudo random number obtaining

Suppose I would like to organize a honest lottery and prevent cheating when we need to find a winner. I known problem of random number in the known network arises. I would like to try the following ...
1
vote
2answers
367 views

How to generate randomness without external calls within a smart contract?

How can I generate a random number within the smart contract without external oracles. Maybe based on the block number or is there any other element that can be used for that?
1
vote
1answer
240 views

Is this a safely design for a lottery smart contract? [closed]

I'm design a lottery smart contract. The lottery is like this: the lottery will be drawed everyday; 24 hours of one day is split to active period(23 hours), freeze period(30 mins), and draw period(30 ...
2
votes
0answers
226 views

Can successive confirmation length blockhashes be used to generate an effective random number?

I've been trying to make a random number generator that doesn't need to be outsourced like Oraclize or break down at scale like RanDAO where n deposits gives 2^n possible manipulations for the random ...
2
votes
2answers
102 views

Where can I get feedback on how to improve my smart contract?

I built a fairly simple contract lottery that gives 20% of all proceedings to Give Directly, my favorite charity organization. I'd like to have someone who know what (s)he's doing to have a look at my ...
2
votes
0answers
160 views

How bad are future blockhashes as source of entropy exactly?

This is not a duplicate (see below) Before you answer “bad, the miner can influence them”, please let me specify the question. It’s clear that things like timestamp should not flow into a random ...
2
votes
1answer
87 views

Fair, barely malleable CSPRNG that can still be deterministic?

Just for fun, I wanted to start off making a test contract that generates ERC-20 tokens based off of prime length when in binary representation. I decided to use Rabin-Miller for the primality test, ...