DEV Community

Mahima Thacker
Mahima Thacker

Posted on

1

The Danger of Randomness in Smart Contracts and its solution

In Ethereum smart contracts, getting true randomness can be tricky and dangerous. Here’s why:

The Problem:
When you use common methods like blockhash or now for randomness in Solidity, it can be manipulated by miners. This makes your contract vulnerable to attacks, especially in games or lotteries.

The code in the below attached image seems to generate a random number, but it’s predictable and can be exploited.

Image description

The Solution: Chainlink VRF 👀
Chainlink’s Verifiable Random Function (VRF) provides a secure and verifiable way to get true randomness that cannot be tampered with.

Here’s how Chainlink VRF solves the problem:

  • Chainlink VRF generates a random number off-chain and provides cryptographic proof that it was done fairly.
  • The smart contract verifies this proof on-chain, ensuring the randomness is - reliable and cannot be tampered with.
  • The cryptographic process ensures that even miners or oracles cannot influence the outcome, hence guaranteeing true randomness

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay