Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions content/md/en/docs/build/randomness.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ The result is a pseudo-random number that is difficult to predict because of the

However, applications that run on the blockchain are more tightly constrained because all authorities in the network must agree on any on-chain value, including any randomness data that is injected.
Because of this constraint, you can't use real randomness directly in blockchain applications.
For this reason, using randomness on-chain securely must utilize techniques such as VRFs otherwise it becomes possible to predict the outcome of a random function whereby any participant could game the system.

For blockchain applications, the most common approach to providing randomness is a cryptographic primitive called a[verifiable random function](https://en.wikipedia.org/wiki/Verifiable_random_function).
For blockchain applications, the most common approach to providing randomness is a cryptographic primitive called a [verifiable random function](https://en.wikipedia.org/wiki/Verifiable_random_function).
A verifiable random function (VRF) is a mathematical operation that takes input and produces a random number and a proof of authenticity that this random number was generated by the submitter.
The proof can be verified by any challenger to ensure that the random number generation is valid.

Expand All @@ -28,7 +29,7 @@ For more information about the relationship between verifiable random functions
## Generate and consume randomness

Substrate provides a [`Randomness`](https://paritytech.github.io/substrate/master/frame_support/traits/trait.Randomness.html) trait called that defines the interface between the logic that **generates randomness** and the logic that **consumes randomness**.
This trait allows you to write the logic for generating randomness and consuming randomness independently of each other.
This trait allows you to write the logic for generating pseudo randomness and consuming randomness independently of each other.

### Generating randomness

Expand All @@ -41,7 +42,7 @@ Substrate includes two examples of how to implement the `Randomness` trait in pa
You should only use this pallet in applications with low security requirements or when testing randomness-consuming applications.
You shouldn't use this pallet in a production environment.

= The [BABE pallet](https://paritytech.github.io/substrate/master/pallet_babe/index.html) provides randomness by using verifiable random functions.
- The [BABE pallet](https://paritytech.github.io/substrate/master/pallet_babe/index.html) provides randomness by using verifiable random functions.

This pallet provides production-grade randomness, and is used in Polkadot.
If you select this pallet as the source of randomness your blockchain must use the blind assignment of blockchain extension ([BABE](/reference/glossary/#blind-assignment-of-blockchain-extension-babe)) slot-based consensus for producing blocks.
Expand Down
4 changes: 2 additions & 2 deletions content/md/en/docs/build/troubleshoot-your-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ Substrate provides two default implementations of randomness.

- The [insecure randomness collective flip](https://paritytech.github.io/substrate/master/pallet_insecure_randomness_collective_flip/index.html) pallet generates random values based on the block hashes from the previous 81 blocks.
This pallet can be useful when defending against weak adversaries or in low-security situations like testing.
For example, you can use this pallet when testing randomness-consuming pallets.
You should never use this pallet in production as a true source of randomness.
For example, you can use this pallet when testing pallets that require some source of randomness.
**You should _never_ use this pallet in production as a true source of randomness.**

- The [BABE](https://paritytech.github.io/substrate/master/pallet_babe/index.html) pallet uses verifiable random functions (VRF) to implement a more secure version of randomness.
This pallet provides production-grade randomness.
Expand Down
1 change: 0 additions & 1 deletion content/md/en/docs/quick-start/modify-the-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ To add the Utility pallet:
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
...
Expand Down
2 changes: 1 addition & 1 deletion content/md/en/docs/reference/frame-pallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You should check the [Rust documentation](https://paritytech.github.io/substrate
| [`pallet_nicks`](https://paritytech.github.io/substrate/master/pallet_nicks/index.html) | Demonstrates simplified account naming on-chain. It makes no effort to create a name hierarchy, be a DNS replacement, or provide reverse lookups.
| [`pallet_offences`](https://paritytech.github.io/substrate/master/pallet_offences/index.html) | Tracks reported offences.
| [`pallet_proxy`](https://paritytech.github.io/substrate/master/pallet_proxy/index.html)| Allows accounts to give permission to other accounts to dispatch types of calls from their signed origin.
| [`pallet_randomness_collective_flip`](https://paritytech.github.io/substrate/master/pallet_randomness_collective_flip/index.html) | Provides a `random` function that can be used in tests and generates low-influence random values based on the block hashes from the previous `81` blocks. This pallet is not intended for use in production.
| [`pallet_randomness_collective_flip`](https://paritytech.github.io/substrate/master/pallet_randomness_collective_flip/index.html) | Provides a `random` function that can be used in tests and generates low-influence random values based on the block hashes from the previous `81` blocks. This pallet is not intended for use in production as it is _not secure_.
| [`pallet_recovery`](https://paritytech.github.io/substrate/master/pallet_recovery/index.html) | Provides a social recovery tool for users to gain access to their accounts if their private key or other authentication mechanism is lost. This pallet enables an account owner to identify trusted parties who can act on the owner's behalf to recover access to an account.
| [`pallet_scheduler`](https://paritytech.github.io/substrate/master/pallet_scheduler/index.html) | Exposes capabilities for scheduling dispatches to occur at a specified block number or at a specified period. These scheduled dispatches can be named or anonymous and can be canceled.
| [`pallet_scored_pool`](https://paritytech.github.io/substrate/master/pallet_scored_pool/index.html)| Maintains a scored membership pool where the highest scoring entities are made members.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Incorporate randomness
title: Incorporate pseudo-randomness (not secure)
description: On-chain randomness techniques and tools detailed.
keywords:
- pallet design
Expand All @@ -15,7 +15,9 @@ This is particularly true in the context of a blockchain, when all the nodes in
FRAME provides runtime engineers with a source of [on-chain randomness](/build/randomness/), using the [Randomness trait](https://paritytech.github.io/substrate/master/frame_support/traits/trait.Randomness.html).

This guide explains how to make use of FRAME's Randomness trait by using the `random` method and a nonce as a subject.
The guide also illustrates how to add entropy to the randomness value by assigning the `RandomCollectiveFlip` pallet to the configuration trait of a pallet that exposes a "random" type.
The guide also illustrates how to add some entropy to the randomness value by assigning the `InsecureRandomCollectiveFlip` pallet to the configuration trait of a pallet that exposes a "random" type.

**Note that the `InsecureRandomCollectiveFlip` is not a secure source of randomness, this guide is intended for educational purposes only.**

## Import `Randomness`

Expand Down Expand Up @@ -88,11 +90,11 @@ Use a nonce to serve as a subject for the `frame_support::traits::Randomness::ra
1. Update your pallet's runtime implementation.

Because you have added a type to your pallet's configuration trait, `Config` opens up the opportunity to further enhance the randomness derived by the `Randomness` trait.
This is accomplished by using the [Randomness Collective Flip pallet](https://paritytech.github.io/substrate/master/pallet_randomness_collective_flip/index.html).
This is accomplished by using the [Insecure Randomness Collective Flip pallet](https://paritytech.github.io/substrate/master/pallet_insecure_randomness_collective_flip/index.html).

Using this pallet alongside the `Randomness` trait will significantly improve the entropy being processed by `random()`.

In `runtime/src/lib.rs`, assuming `pallet_random_collective_flip` is instantiated in `construct_runtime` as `RandomCollectiveFlip`, specify your exposed type in the following way:
In `runtime/src/lib.rs`, assuming `pallet_insecure_randomness_collective_flip` is instantiated in `construct_runtime` as `RandomCollectiveFlip`, specify your exposed type in the following way:

```rust
impl my_pallet::Config for Runtime{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ To add the Utility types and configuration trait:
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ For this demonstration, be sure you have:
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system, // index 0
RandomnessCollectiveFlip: pallet_randomness_collective_flip, // index 1
Timestamp: pallet_timestamp, // index 2
Aura: pallet_aura, // index 3
Grandpa: pallet_grandpa, // index 4
Balances: pallet_balances, // index 5
Nicks: pallet_nicks, // index 6
System: frame_system, // index 0
Timestamp: pallet_timestamp, // index 1
Aura: pallet_aura, // index 2
Grandpa: pallet_grandpa, // index 3
Balances: pallet_balances, // index 4
Nicks: pallet_nicks, // index 5
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ To add the collectibles pallet to the runtime:
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Grandpa: pallet_grandpa,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ impl frame_system::Config for Runtime {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_randomness_collective_flip::Config for Runtime {}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
Expand Down Expand Up @@ -310,7 +308,6 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Grandpa: pallet_grandpa,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ impl frame_system::Config for Runtime {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_randomness_collective_flip::Config for Runtime {}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
Expand Down Expand Up @@ -310,7 +308,6 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Grandpa: pallet_grandpa,
Expand Down