Linked Questions

162
votes
18answers
45k 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?
27
votes
1answer
4k views

When can BLOCKHASH be safely used for a random number? When would it be unsafe?

I've seen more complicated ways for a contract to generate a random number. But the Ethereum Yellow Paper itself suggests a "trivial solution" using the BLOCKHASH opcode (see below, bold is mine). ...
12
votes
3answers
3k views

what is block.timestamp

In a function, does block.timestamp record the time the transaction was processed, or the time the block.timestamp computational step was processed? Is block.timestamp the time the transaction is ...
16
votes
2answers
1k views

How would a miner cope with a huge block time?

Given that: According to the white and yellow paper a block's timestamp must be bigger than the parent's. According to the white paper a block's timestamp can be within 15 min of the parent ...
8
votes
2answers
14k views

How to get current time by solidity?

I'd like to describe time like Apr15th 10:00AM . I know how to describe time range as follows, but I am not sure how to call date of time. Could you tell me about it if you know? 1 == 1 second 1 ...
3
votes
1answer
925 views

How does Ethereum avoid inaccurate timestamps in blocks?

A contract can reference the currently being mined contract's timestamp. This means that changing the timestamp of an in-progress to be mined block requires executing all contracts referencing that ...
4
votes
2answers
473 views

Check that the timestamp of the block is greater than that of the previous block and less than 2 hours into the future?

I am reading the White Paper of Ethereum. And at the Mining Section, I do not understand the this part "less than 2 hours into the future" of the following sentence: Check that the timestamp of the ...
3
votes
2answers
141 views

Are there any misbehaving miners?

Many of the discussions I read about security relate to how miners can manipulate this or that aspect of the way a transaction gets processed, such as whether or not it's included, what it's timestamp ...
2
votes
0answers
430 views

Working with time in smart contracts

I know there have been quite a few questions surrounding time, and the use of block.timestamp. However, I still have a few questions design-wise. At what point exactly is it 'dangerous' to use block....
1
vote
1answer
167 views

Get time when the transaction was included in your node

Is there any way to obtain the time when you have received a transaction? I would like to know when is a Smart contract included in my node. (local testnet)
0
votes
1answer
185 views

How are price changes based on time implemented in crowdsale smart contracts?

How can I implement a price structure into a crowdsale smart contract so that a price per token would be increased after a certain time? I want to use best practices for this but cannot find ...
0
votes
2answers
50 views

Are there other sources of input to a contract than transaction data or the invocation of other contracts?

Are there other sources of input to a contract than transaction data or the invocation of other contracts? I've wondered whether there are other sources of input to a contract than those mentioned ...
0
votes
0answers
58 views

SmartContract determine timestamp of saving data

I have really simple solidity smartcontract for saving and fetching data structs. When I ask for data struct (fetching function) I need to know timestamp (or block ID) when was the struct saved. How ...
1
vote
1answer
43 views

Are the timestamps of blocks for Ethereum only accepted when they are monotonically increasing?

Are the timestamps of blocks for Ethereum only accepted when they are monotonically increasing? If yes, why? And why other blockchains like Bitcoin and other blockchains with shorter block time can ...