This commit is contained in:
jude 2023-04-18 20:29:39 +01:00
parent 8e149fad42
commit 7f6ceb1968
3 changed files with 13 additions and 4 deletions

View File

@ -85,10 +85,11 @@ export class Packet {
}); });
} }
static createReinforce(regionCipherTexts) { static createReinforce(regionCipherTexts, verification) {
return this._sign({ return this._sign({
...this._createBase("ACT"), ...this._createBase("ACT"),
regions: regionCipherTexts, regions: regionCipherTexts,
verification: verification,
}); });
} }

View File

@ -4,6 +4,7 @@ import { RsaPubKey } from "../crypto/rsa.js";
import { PaillierPubKey, ReadOnlyCiphertext } from "../crypto/paillier.js"; import { PaillierPubKey, ReadOnlyCiphertext } from "../crypto/paillier.js";
import { Region } from "./map.js"; import { Region } from "./map.js";
import { showDefenseDom } from "./dom.js"; import { showDefenseDom } from "./dom.js";
import { proveRegions, verifyRegions } from "./proofs.js";
// Timeout to consider a player disconnected // Timeout to consider a player disconnected
const TIMEOUT = 30_000; const TIMEOUT = 30_000;
@ -107,6 +108,11 @@ export class Player {
* @param data Data received via socket. * @param data Data received via socket.
*/ */
reinforce(data) { reinforce(data) {
if (!verifyRegions(data.verification, this.paillierPubKey)) {
console.log("Failed to verify Protocol 4.5!");
return;
}
for (let regionName of Object.keys(data.regions)) { for (let regionName of Object.keys(data.regions)) {
let region = Region.getRegion(regionName); let region = Region.getRegion(regionName);
@ -153,11 +159,13 @@ export class Player {
cipherText = this.paillierPubKey.encrypt(1n); cipherText = this.paillierPubKey.encrypt(1n);
} }
regions[ourRegion.name] = cipherText.toString(); regions[ourRegion.name] = cipherText;
ourRegion.reinforce(cipherText); ourRegion.reinforce(cipherText);
} }
socket.emit("message", Packet.createReinforce(regions)); let verification = proveRegions(regions);
socket.emit("message", Packet.createReinforce(regions, verification));
this.totalStrength += 1; this.totalStrength += 1;

View File

@ -43,7 +43,7 @@ function getCoins(text) {
window.cryptoShuffle = cryptoShuffle; window.cryptoShuffle = cryptoShuffle;
function proveRegions(regions) { export function proveRegions(regions) {
// Construct prover coins // Construct prover coins
let proofs = []; let proofs = [];
let privateInputs = []; let privateInputs = [];