0

I am a newbie to this field and currently learning to write some smart contract programs.

I am writing to inquire the best practice to use those system-level variables, such as BLOCKHASH, TIMESTAMP, COINBASE DIFFICULTY, and GASLIMIT when writing my contract.

I got the impression from the best practice manual that we should try to avoid using such variables, since they may be manipulated by malicious miners. But then in which situation do we need this? Could anyone shed some lights on a "legit" and "secure" usage of such variables? Thanks!

1 Answer 1

0

The recommendation is to use them with care and with knowledge of their limitations.

You have to ask yourself. Does the manipulations of these parameters provide an advantage to the sender of the transaction?

For example the use keccak256(block.timestamp) as source of randomness is not good because a miner can manipulate it. Althought the miner is risking the block reward so if the profit is much smaller than the reward it doesn't make much sense for the miner to manipulate it.

Unfortunately there's no rule that will cover 100% of the use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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