The Chaos module is used to inject chaos into a Substrate Runtime and intentionally break things.
The Chaos module provides functions for:
- Make Substrate Runtimes behave in ways that they're not supposed to.
- Explore Runtime edge cases.
- Explore Extrinsic weights and their economic implications.
- Expose Runtime Attack Vectors.
Inspired by overflow extrinsic implementation from Alexander Popiak's how-not-to-build-a-pallet
, performs an unchecked sum over the Adder
storage object. If the result is above 4_294_967_296
, then Adder
overflows.
This extrinsic illustrates the importance of using safe operations such as checked_add
, checked_sub
and their variants from substrate_primitives::U256
.
Simply clears the Adder
storage object so that unwrap_add
can illustrate bad unwraps.
Injects a heavy computation payload into the runtime, effectively dragging block production by calculating hashes in a loop (n times), with constant unitary extrinsic weight.
This extrinsic illustrates the importance of proper weight design.
chaoscope
provides a CLI utility to automate interaction with pallet-chaos
on a local setup.
- In case you want to interact with it manually, follow the steps below.
- Include
pallet-chaos
to asubstrate-node-template
, build it, and start the chain:
$ ./target/release/node-template --dev --tmp
- On PolkadotJS, connect to
DEVELOPMENT
Chain (ws://127.0.0.1:9944
). - Open
Developer
->Extrinsics
.
On a browser new tab, open Developer
->Chain state
.
Then choose chaos
-> adder()
, and click the +
sign. This is how you'll monitor the Adder
storage object.
On the extrinsics tab you had previously open, choose chaos
->overflowAdder(n)
.
While monitoring adder()
on the Chain state
tab, keep adding numbers at will, until you reach 4_294_967_296
.
Observe what happens after you add above this value, and imagine what would be the implications if Adder
actually represented something meaningful in your chain.
Choose chaos
->dragBlockUnitWeight(n)
.
Here's where the experimentation starts. Choose different values for n
, call Submit Transaction
and observe the effects on block production.
AGPL-3.0