Core Principle
All game results are generated through cryptographically verifiable random number generation (VRF):
import hmac
import hashlib
def generate_result(server_seed, client_seed, nonce, game_type):
# 种子组合与HMAC-SHA256计算
message = f"{client_seed}:{nonce}".encode()
h = hmac.new(server_seed.encode(), message, hashlib.sha256)
hex_digest = h.hexdigest()
# 转换为整数(取前8字符避免溢出)
random_int = int(hex_digest[:8], 16) # 0~4,294,967,295
if game_type == "integer":
return integer_game_result(random_int)
else:
return float_game_result(random_int)
1. Integer Game (0/1) Result Generation
Generation Process

Verification Formula
Technical Specifications
Input Sources
Triple-seed system (server seed + client seed + nonce)
Hash Algorithm
HMAC-SHA256 (collision resistance > 2¹²⁸)
Output Range
Deterministic binary output {0, 1}
Bias Control
Floating-point error eliminated via modulo operation
Verification Tools
Web calculator/SDK provided
Verification Example
// 输入参数
const serverSeed = "2b8f1c7e0a9d6543";
const clientSeed = "player_choice_2023";
const nonce = 142;
// 计算过程
const digest = hmacSHA256(serverSeed, `${clientSeed}:${nonce}`);
const value = parseInt(digest.substring(0,8), 16) % 2;
// 输出: 0 (与链上记录一致)
2. Floating-Point Game (0.1-9.9) Result Generation
Generation Process

Verification Formula
Distribution Guarantee
def float_game_result(random_int):
base_value = random_int % 99 # 0~98整数
return round(base_value/10 + 0.1, 1) # 精确到0.1
Statistical Validation
Mean
5.0
4.997
Standard Deviation
2.87
2.869
χ² Test
p>0.99
p=0.998
Min/Max
0.1/9.9
0.1/9.9
Verifiability Assurance System
Triple-Layer Verification
Pre-commitment Verification
// 游戏开始前提交种子承诺 function commitSeed(bytes32 hashedServerSeed) external { require(!seedRevealed[msg.sender], "Already committed"); commitments[msg.sender] = hashedServerSeed; }
On-chain Result Recording
// IPFS存储结构 { "metadata": { "algo": "HMAC-SHA256", "mapping": "float_game_result" }, "inputs": { "server_seed": "encrypted:0x8a3b...f21c", "client_seed": "player_choice_2023", "nonce": 142 }, "output": 7.2, "proof": "sha256:9f86d...0a9c" }
Public Verification Tool
$ pofg-verify --game-id 0x5a38d4b \ --type float \ --server-seed "2b8f1c7e0a9d6543" \ --client-seed "player_choice_2023" \ --nonce 142 > 验证通过: 输出值7.2匹配链上记录
Anti-Manipulation Features
Seed Control Separation
Server seed: Secured by POFG smart contract (commit-reveal scheme)
Client seed: Submitted by player before game start
Nonce: Auto-incremented per game round
Time-lock Mechanism
// 服务器种子揭示时间锁 function revealSeed(string memory seed) external { require(block.timestamp > gameEndTime + 1 hours, "Reveal locked"); require(keccak256(abi.encodePacked(seed)) == commitments[msg.sender], "Invalid seed"); // 触发自动验证... }
Post-audit Interface
// 批量验证API POST /audit-verify { "game_ids": ["0x8a3b...f21c", "0x5b38...c7"], "auditor_signature": "0x1234..." }
This mechanism provides triple-layer assurance through cryptographic binding + decentralized verification + mandatory transparency, ensuring no single party (including POFG system) can manipulate outcomes. Players can independently verify game fairness using open-source tools.
Last updated