"The future grows from the seeds of the past."
A deterministic provably-fair verification script for validating the result of a PvP battle based on player bets and a cryptographic seed.
The script allows anyone to independently verify that a battle result was not manipulated by checking:
- the integrity of the seed
- the correctness of the winner selection algorithm
.
├── pvp_battle_legit_check.py # Verification script
├── test_roll.json # Example battle data
└── README.md
The verification process consists of two main steps.
Before the battle begins, the system publishes the SHA256 hash of a secret seed.
Later the seed is revealed.
The script checks that the revealed seed matches the previously published hash:
SHA256(seed_bytes) == provided_hash
If the hash does not match, the round is invalid.
This prevents the seed from being changed after bets are known.
Each player's bet increases their probability of winning.
To avoid floating-point inaccuracies, bets are converted into atoms.
ATOM = 0.01
Example:
| Bet | Atoms |
|---|---|
| 20.00 | 2000 |
| 10.00 | 1000 |
Total atoms:
3000
The seed is converted into a large integer:
rand_int = int.from_bytes(seed_bytes, "big")
Then a deterministic index is calculated:
index = rand_int % total_atoms
Each player occupies a range proportional to their bet.
Example:
| Player | Bet | Atom Range |
|---|---|---|
| Player A | 20 | 0–1999 |
| Player B | 10 | 2000–2999 |
If the generated index falls within a player's range — that player wins.
Because the algorithm is deterministic, anyone running the script will get the same result.
File: test_roll.json
[
{
"amount": 20,
"id": 409,
"username": "@Mityaich89"
},
{
"amount": 10,
"id": 410,
"username": "@Maks77"
}
]Seed:
64c5a63257ad213f2ec6e2b12650f50b1b07d47fa291f8f51b93bc4a1fdc8ae3
Published hash:
de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b
Run the script from the command line:
python pvp_battle_legit_check.py \
--seed 64c5a63257ad213f2ec6e2b12650f50b1b07d47fa291f8f51b93bc4a1fdc8ae3 \
--hash de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b \
--json test_roll.jsonHash verification passed! ✓
┌──────────────────────────┐
│ Winner ID: 409 │
│ Username: @Mityaich89 │
│ Amount: 20 │
└──────────────────────────┘
The system follows a commit-reveal cryptographic scheme.
The system generates a random seed and publishes its hash:
SHA256(seed)
Example:
de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b
Players place bets while only the hash is known.
The actual seed remains secret.
After betting ends, the seed is revealed.
Anyone can verify:
- the seed matches the published hash
- the winner was determined fairly
Given the same:
- seed
- hash
- bet data
The script will always produce the same winner.
This makes the system:
- transparent
- reproducible
- tamper-resistant
Python 3.8+
Standard library only:
decimal
hashlib
json
argparse
os
No external dependencies required.
MIT License