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!

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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