Security of Smart Contracts 5: Weak Randomness

Weak randomness can cause some security issues. The attacker can predict the random number generated to achieve the purpose of the attack.

For example:

In this lottery smart contract, the random number is generated based on the timestamp of the block. The issue that follows is that miners can use the transparent feature of blockchain to exploit the funds in the lottery pools.

How can an attacker exploit it?

Transaction order in the Mempool is mutable. Every transaction may be modified. When a node receives the transaction that runs the function of generating the random number in the contract, the attacker(miner) can predict the “random number“ and send a transaction right away and change its order to the front of the transaction containing the random number generating function. After that, the miner can get all the funds from the lottery pool.

Subscribe to Hicss
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.