Skip to content

Commit 1c186ac

Browse files
Update random-number-generation.md
1 parent 6ac9da6 commit 1c186ac

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

docs/v3/guidelines/smart-contracts/security/random-number-generation.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,75 +12,73 @@ These algorithms typically require a _seed_ value to produce a sequence of _pseu
1212

1313
To predict the result of the `random()` function in a smart contract, one would need to know the current `seed` of the block, which is impossible unless you are a validator.
1414

15-
# Approaches and security considerations
16-
17-
There are multiple methods for generating random values, each with distinct trade-offs between speed, security, and decentralization guarantees.
15+
There are multiple approaches to generate random values, each offering different trade-offs between speed, security, and decentralization guarantees.
1816

1917
Below we outline three fundamental approaches:
2018

2119
---
2220

23-
## Approach 1: randomize_lt
21+
## Approach 1: randomize_lt {#randomize_lt}
2422

25-
**Mechanism**: Generates randomness using block logical time (`lt`) and blockchain entropy.
26-
**Security Model**:
23+
**Mechanism**: Generates [randomness using block logical time](https://docs.ton.org/v3/guidelines/smart-contracts/security/ton-hack-challenge-1/#4-lottery) (`lt`) and blockchain entropy.
24+
**Security model**:
2725

2826
- ✅ Safe against user manipulation
2927
- ❌ Vulnerable to colluding validators (could theoretically predict/influence values)
3028

3129
**Speed**: Fast (single-block operation)
32-
**Use Cases**:
30+
**Use cases**:
3331

3432
- Non-critical applications, for example gaming & NFTs
3533
- Scenarios where validator trust is assumed
3634

3735
---
3836

39-
## Approach 2: Block skipping
37+
## Approach 2: Block skipping {#block-skip}
4038

41-
**Mechanism**: Uses entropy from skipped blocks in blockchain history.
42-
**Security Model**:
39+
**Mechanism**: Uses [entropy from skipped blocks](https://github.com/puppycats/ton-random?tab=readme-ov-file#ton-random) in blockchain history.
40+
**Security model**:
4341

4442
- ✅ Resistant to user manipulation
4543
- ⚠️ Not fully secure against determined validators (may influence block inclusion timing)
4644

4745
**Speed**: Slow (requires multiple blocks to finalize)
48-
**Use Cases**:
46+
**Use cases**:
4947

5048
- Medium-stakes applications, for example lottery systems
5149
- Scenarios with partial trust in validator set
5250

5351
---
5452

55-
## Approach 3: Commit-reveal scheme
53+
## Approach 3: Commit-reveal scheme {#commit-reveal}
5654

5755
**Mechanism**:
5856

59-
1. **Commit Phase**: Participants submit hashed secrets
60-
2. **Reveal Phase**: Secrets are disclosed and combined to generate final randomness
57+
1. **Commit phase**: Participants submit hashed secrets
58+
2. **Reveal phase**: Secrets are disclosed and combined to generate final randomness
6159

62-
**Security Model**:
60+
**Security model**:
6361

6462
- ✅ Cryptographically secure when properly implemented
6563
- ✅ Resilient to both users and validators
6664
- ⚠️ Requires protocol-level verification of commitments
6765

6866
**Speed**: Very slow (multi-phase, multi-block process)
69-
**Use Cases**:
67+
**Use cases**:
7068

7169
- High-value applications, for example decentralized auctions
7270
- Systems requiring Byzantine fault tolerance
7371

7472
---
7573

76-
### **Key Considerations**
74+
## Key considerations
7775

7876
| Factor | `randomize_lt` | Block skipping | Commit-reveal |
7977
| ------------------------- | -------------- | -------------- | ------------- |
8078
| Speed | Fast | Moderate | Slow |
81-
| User Resistance | High | High | Highest |
82-
| Validator Resistance | Low | Medium | Highest |
83-
| Implementation Complexity | Low | Medium | High |
79+
| User resistance | High | High | Highest |
80+
| Validator resistance | Low | Medium | Highest |
81+
| Implementation complexity | Low | Medium | High |
8482

8583
---
8684

@@ -94,5 +92,3 @@ No method is universally perfect – choose based on:
9492
:::
9593

9694
Always audit implementations through formal verification where possible.
97-
98-
For working examples, refer to [randomization contracts example](https://github.com/puppycats/ton-random).

0 commit comments

Comments
 (0)