Linked Questions

3 votes
1 answer
3k 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);...
mankee's user avatar
  • 263
3 votes
1 answer
976 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 ...
Jay's user avatar
  • 33
3 votes
1 answer
477 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 ...
Jeth's user avatar
  • 312
0 votes
1 answer
556 views

Minereum Lucky Draw claims 100% Safe randomness on a smart contract without oracles, is it really possible? [duplicate]

Is the way Minereum Lucky Draw game works really safe 100% onchain RNG and verifiable on smart contract? They claim yes but I would like to know expert technical answer for this, if so, isn't this a ...
Manu's user avatar
  • 9
233 votes
20 answers
103k 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?
J-B's user avatar
  • 8,971
40 votes
3 answers
12k 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 ...
J-B's user avatar
  • 8,971
5 votes
2 answers
3k 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 ...
StanislavL's user avatar
1 vote
1 answer
539 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 ...
杜荣政's user avatar
0 votes
2 answers
462 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?
Moisés Briseño Estrello's user avatar
2 votes
2 answers
171 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 ...
Anto's user avatar
  • 311
2 votes
0 answers
248 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 ...
Kaizen Bran's user avatar
2 votes
0 answers
250 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 ...
matthias_buehlmann's user avatar
2 votes
1 answer
153 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, ...
Expectator's user avatar