smartcontractkit / smartcontractkit/chainlink

[FEAT] VRF for Normal (Gaussian) Distribution

Open
#5,393 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs votes
Dominant language
Go
Stars
8.2k
Forks
2k
Avg merge
1d 23h
Merged PRs (30d)
202

Description

Description
Requesting a new VRF that returns a random number from a Normal Distribution. The simplest version would be a function that returns a random value from the standard normal distribution (Z, where mean = 0, st. dev = 1). The value could be stored as an int256 but evaluated as a fixed point number with 18 decimal places (similar to most ERC20 tokens). The sample from Z can be converted to any other normal distribution by the simple formula: sigma * Z + mu.

Motivation
The current Chainlink VRF returns a random number from a uniform distribution. This is sufficient for generating outcomes at a specific probability or providing a random selection from group of choices. However, it is not a convenient or optimal solution for randomly selecting values for properties that vary from a mean. Examples include random rolls for game character or item attributes, size distribution for objects (height/width/length, weight, brightness, etc.), breeding time variation, growth rates, etc. Other potential areas not yet explored are in new DeFi constructs and generative art.

Justification
Approximating a normal random number from the currently available options (i.e. uniform random numbers from Chainlink VRF) is possible, but hard. For example, the Box-Muller Transform allows you to approximate 2 values from a normal distribution from using two values from a uniform distribution from 0 to 1, but it requires several operations not native to solidity, sin, sqrt, and log2. You can use get these by using an advanced math library, but that adds to contract byte size and will cost a non-trivial amount of gas.

On the other hand, there are several optimized libraries in off-chain programming languages for quickly generating values from a normal distribution, e.g. NumPy

Additional Information
Inspired by work on a NFT project that would generate random offspring from existing characters using hereditary attributes. Pointed to create an issue from twitter thread with Patrick Collins.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by reviewing the current Chainlink VRF implementation and the proposed standard-normal, 18-decimal fixed-point model. Resolve the API, distribution-generation method, gas and precision constraints, and validation strategy; done means a supported normal-distribution VRF with tests and documented conversion to other normal distributions.

Written by the indexing model from the issue text.

Assessment

Tech stack
blockchain, solidity
Domain
blockchain, cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.