可证公平
每一局 BC 自研游戏的结果,都可以用服务端种子、客户端种子和 nonce 自行核验。选择游戏,查看它的结果是怎么算出来的。
Patti
去核验Is The Game Fair?
Every round has a pre-generated SHA256 hash. The hashes form a chain and are released in reverse order, each corresponding to one round of the game. The SHA256 of a round's hash equals the hash of the previous round, so the results cannot be changed once the chain is published.
The cards of a round are calculated from its hash and a salt. The salt is the hash of Bitcoin block 790,100 (0000000000000000000301e2801a9a9598bfb114e574a91a887f2132f33047e6), which had not been mined when the chain was published.
How Are the Results Calculated?
- seed = HMAC_SHA256 with the round's hash (decoded from hexadecimal into bytes) as the message and the salt as the key.
- Shuffle the 52 cards by the seed (first shuffle), then shuffle the result again by the SHA256 of the seed (second shuffle).
- The first six cards are dealt: Player A gets the 1st, 3rd and 5th cards, and Player B gets the 2nd, 4th and 6th cards.
function seedGenerator(hash, salt) {
const hmac = CryptoJS.HmacSHA256(CryptoJS.enc.Hex.parse(hash), salt);
return hmac.toString(CryptoJS.enc.Hex);
}
function createNums(allNums, hash) {
const nums = [];
let h = CryptoJS.SHA256(hash).toString(CryptoJS.enc.Hex);
allNums.forEach((c) => {
nums.push({ num: c, hash: h });
h = h.substring(1) + h.charAt(0);
});
nums.sort(function (o1, o2) {
if (o1.hash < o2.hash) {
return -1;
} else if (o1.hash === o2.hash) {
return 0;
} else {
return 1;
}
});
return nums;
}