In this track: Smart contract security foundations
advanced · 4 MIN READ

Predictable randomness

Public or influenceable inputs do not automatically form a fair draw.

LET’S PICTURE IT

A lottery is not fair if a participant can see or choose the ticket-selection rule’s result in advance.

SEE IT FOR YOURSELF
From exact bytes to a Keccak-256 fingerprintStep 1 / 4
From exact bytes to a Keccak-256 fingerprintUTF-8 texthelloExact spelling mattersA hash commits to bytes, not a visual interpretationFive input bytes68656c6c6fLiteral text 0x68656c6c6f would be a different text inputInput bytes68 65 6c 6c 6f5 bytesKeccak-256Deterministic calculation32-byte resultUse Keccak-256, not an interchangeable SHA3-256 assumption0x1c8aff95…36deac8Fixed output: 32 bytesSame input bytes → same outputA fingerprint does not prove that the input is truthful or safe

The text hello is a particular sequence of characters. Case or text normalization can change the encoded bytes.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Define the adversary’s choices

Ask who can observe inputs, choose transaction timing or withhold participation. Randomness security depends on those abilities, not just a hash function.

Do not hide known data with hashing

Hashing timestamps, user inputs and other predictable values preserves predictability for someone who knows the same inputs.

Review a complete randomness protocol

Commit-reveal, verifiable randomness and other designs have assumptions about bias, availability and liveness. No mechanism is solved by using a familiar acronym alone.

Test withholding and retries

Consider participants who decline to reveal or try again after seeing an unfavorable outcome. The rules should address those choices explicitly.

Reason about the scenario

public known inputs → public computable digest

Review unpredictability, influence, withholding and retry behavior.

Pseudocode or a simplified scenario for local reasoning. This is not a production contract or a completed security review.

QUICK CHECK · NO PRESSURE

Does hashing only public predictable inputs make them secret?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.