Skip to content

bitcoincrane/Legit-Check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

🔐 PvP Battle Legitimacy Check

"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

📦 Project Files

.
├── pvp_battle_legit_check.py   # Verification script
├── test_roll.json              # Example battle data
└── README.md

⚙️ How It Works

The verification process consists of two main steps.

1️⃣ Seed Hash Verification

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.


2️⃣ Weighted Winner Determination

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

Random Index Generation

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

Winner Selection

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.


📂 Example Roll Data

File: test_roll.json

[
  {
    "amount": 20,
    "id": 409,
    "username": "@Mityaich89"
  },
  {
    "amount": 10,
    "id": 410,
    "username": "@Maks77"
  }
]

🔑 Example Verification Data

Seed:

64c5a63257ad213f2ec6e2b12650f50b1b07d47fa291f8f51b93bc4a1fdc8ae3

Published hash:

de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b

🚀 Usage

Run the script from the command line:

python pvp_battle_legit_check.py \
--seed 64c5a63257ad213f2ec6e2b12650f50b1b07d47fa291f8f51b93bc4a1fdc8ae3 \
--hash de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b \
--json test_roll.json

✅ Example Output

Hash verification passed! ✓

┌──────────────────────────┐
│ Winner ID: 409           │
│ Username: @Mityaich89    │
│ Amount: 20               │
└──────────────────────────┘

🔎 Why This Is Provably Fair

The system follows a commit-reveal cryptographic scheme.

Step 1 — Commit

The system generates a random seed and publishes its hash:

SHA256(seed)

Example:

de2f547e08e7647d7b3335cc4e7450e2082a054e13057662c41543838b326b2b

Step 2 — Betting

Players place bets while only the hash is known.

The actual seed remains secret.


Step 3 — Reveal

After betting ends, the seed is revealed.

Anyone can verify:

  • the seed matches the published hash
  • the winner was determined fairly

🛡 Deterministic Guarantees

Given the same:

  • seed
  • hash
  • bet data

The script will always produce the same winner.

This makes the system:

  • transparent
  • reproducible
  • tamper-resistant

🧰 Requirements

Python 3.8+

Standard library only:

decimal
hashlib
json
argparse
os

No external dependencies required.


📜 License

MIT License

About

The future grows from the seeds of the past.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages