diff --git a/.github/workflows/azure-static-web-apps-victorious-grass-0b75f1b03.yml b/.github/workflows/azure-static-web-apps-victorious-grass-0b75f1b03.yml deleted file mode 100644 index 5124040..0000000 --- a/.github/workflows/azure-static-web-apps-victorious-grass-0b75f1b03.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Azure Static Web Apps CI/CD - -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened, closed] - branches: - - main - -jobs: - build_and_deploy_job: - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') - runs-on: ubuntu-latest - name: Build and Deploy Job - steps: - - uses: actions/checkout@v3 - with: - submodules: true - lfs: false - - name: Build And Deploy - id: builddeploy - uses: Azure/static-web-apps-deploy@v1 - with: - azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_GRASS_0B75F1B03 }} - repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) - action: "upload" - ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### - # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig - app_location: "/react-wordle" # App source code path - api_location: "" # Api source code path - optional - output_location: "build" # Built app content directory - optional - ###### End of Repository/Build Configurations ###### - - close_pull_request_job: - if: github.event_name == 'pull_request' && github.event.action == 'closed' - runs-on: ubuntu-latest - name: Close Pull Request Job - steps: - - name: Close Pull Request - id: closepullrequest - uses: Azure/static-web-apps-deploy@v1 - with: - azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_GRASS_0B75F1B03 }} - action: "close" diff --git a/contracts/FHEordle.sol b/contracts/FHEordle.sol index 01e8834..e682b83 100644 --- a/contracts/FHEordle.sol +++ b/contracts/FHEordle.sol @@ -7,8 +7,6 @@ import "fhevm/lib/TFHE.sol"; import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; contract FHEordle is EIP712WithModifier { - - address public playerAddr; address public relayerAddr; @@ -97,9 +95,7 @@ contract FHEordle is EIP712WithModifier { ); } - function submitWord1( - euint16 l0, euint16 l1, euint16 l2, euint16 l3, euint16 l4, euint32 mask - ) public onlyRelayer { + function submitWord1(euint16 l0, euint16 l1, euint16 l2, euint16 l3, euint16 l4, euint32 mask) public onlyRelayer { require(!wordSubmitted, "word submitted"); TFHE.optReq( TFHE.eq( @@ -109,10 +105,7 @@ contract FHEordle is EIP712WithModifier { TFHE.shl(1, TFHE.asEuint32(l1)), TFHE.or( TFHE.shl(1, TFHE.asEuint32(l2)), - TFHE.or( - TFHE.shl(1, TFHE.asEuint32(l3)), - TFHE.shl(1, TFHE.asEuint32(l4)) - ) + TFHE.or(TFHE.shl(1, TFHE.asEuint32(l3)), TFHE.shl(1, TFHE.asEuint32(l4))) ) ) ), @@ -153,9 +146,7 @@ contract FHEordle is EIP712WithModifier { ); } - function guessWord1( - euint16 l0, euint16 l1, euint16 l2, euint16 l3, euint16 l4, euint32 letterMask - ) public { + function guessWord1(euint16 l0, euint16 l1, euint16 l2, euint16 l3, euint16 l4, euint32 letterMask) public { require(gameStarted, "game not started"); require(nGuesses < 5, "cannot exceed five guesses!"); euint8 g0 = TFHE.asEuint8(TFHE.eq(word1Letters[0], l0)); @@ -163,20 +154,10 @@ contract FHEordle is EIP712WithModifier { euint8 g2 = TFHE.asEuint8(TFHE.eq(word1Letters[2], l2)); euint8 g3 = TFHE.asEuint8(TFHE.eq(word1Letters[3], l3)); euint8 g4 = TFHE.asEuint8(TFHE.eq(word1Letters[4], l4)); - euint8 eqMask = - TFHE.or( - TFHE.shl(g0, 0), - TFHE.or( - TFHE.shl(g1, 1), - TFHE.or( - TFHE.shl(g2, 2), - TFHE.or( - TFHE.shl(g3, 3), - TFHE.shl(g4, 4) - ) - ) - ) - ); + euint8 eqMask = TFHE.or( + TFHE.shl(g0, 0), + TFHE.or(TFHE.shl(g1, 1), TFHE.or(TFHE.shl(g2, 2), TFHE.or(TFHE.shl(g3, 3), TFHE.shl(g4, 4)))) + ); eqMaskGuess[nGuesses] = eqMask; letterMaskGuess[nGuesses] = TFHE.and(word1LettersMask, letterMask); letterMaskGuessHist[nGuesses][0] = l0; @@ -188,31 +169,24 @@ contract FHEordle is EIP712WithModifier { nGuesses += 1; } - function getGuess(uint8 guessN, + function getGuess( + uint8 guessN, bytes32 publicKey, bytes calldata signature - ) - public view onlySignedPublicKey(publicKey, signature) onlyPlayer - returns (bytes memory, bytes memory) { + ) public view onlySignedPublicKey(publicKey, signature) onlyPlayer returns (bytes memory, bytes memory) { require(guessN < nGuesses, "canno exceed nGuesses"); - return ( - TFHE.reencrypt(eqMaskGuess[guessN], publicKey), - TFHE.reencrypt(letterMaskGuess[guessN], publicKey) - ); + return (TFHE.reencrypt(eqMaskGuess[guessN], publicKey), TFHE.reencrypt(letterMaskGuess[guessN], publicKey)); } - function getLetterGuess(uint8 guessN, + function getLetterGuess( + uint8 guessN, uint8 letterN, bytes32 publicKey, - bytes calldata signature - ) - public view onlySignedPublicKey(publicKey, signature) onlyPlayer - returns (bytes memory) { + bytes calldata signature + ) public view onlySignedPublicKey(publicKey, signature) onlyPlayer returns (bytes memory) { require(guessN < nGuesses, "canno exceed nGuesses"); require(letterN < 5, "cannot exceed 5"); - return ( - TFHE.reencrypt(letterMaskGuessHist[guessN][letterN], publicKey) - ); + return (TFHE.reencrypt(letterMaskGuessHist[guessN][letterN], publicKey)); } function claimWin(uint8 guessN) public onlyPlayer { @@ -240,7 +214,22 @@ contract FHEordle is EIP712WithModifier { uint16 l3; uint16 l4; (l0, l1, l2, l3, l4) = revealWord(); - word1 = uint32(l0) + uint32(l1) * 26 + uint32(l2)*26*26 + uint32(l3)*26*26*26 + uint32(l4)*26*26*26*26; + word1 = + uint32(l0) + + uint32(l1) * + 26 + + uint32(l2) * + 26 * + 26 + + uint32(l3) * + 26 * + 26 * + 26 + + uint32(l4) * + 26 * + 26 * + 26 * + 26; } function checkProof() public onlyPlayer { @@ -261,5 +250,4 @@ contract FHEordle is EIP712WithModifier { require(msg.sender == playerAddr); _; } - -} \ No newline at end of file +} diff --git a/contracts/FHEordleFactory.sol b/contracts/FHEordleFactory.sol index a7f6b1b..24211a2 100644 --- a/contracts/FHEordleFactory.sol +++ b/contracts/FHEordleFactory.sol @@ -6,9 +6,7 @@ import "fhevm/abstracts/EIP712WithModifier.sol"; import "./FHEordle.sol"; import "fhevm/lib/TFHE.sol"; - contract FHEordleFactory is EIP712WithModifier { - address public creator; mapping(address => address) public userLastContract; @@ -52,7 +50,7 @@ contract FHEordleFactory is EIP712WithModifier { ); } - function gameNotStarted() public view returns (bool){ + function gameNotStarted() public view returns (bool) { if (userLastContract[msg.sender] != address(0)) { FHEordle game = FHEordle(userLastContract[msg.sender]); return game.playerWon() || (game.nGuesses() == 5); @@ -69,7 +67,4 @@ contract FHEordleFactory is EIP712WithModifier { gamesWon[msg.sender] += 1; } } - - - -} \ No newline at end of file +} diff --git a/test/fheordle/FHEordle.ts b/test/fheordle/FHEordle.ts index 3d015bd..92f447b 100644 --- a/test/fheordle/FHEordle.ts +++ b/test/fheordle/FHEordle.ts @@ -1,14 +1,14 @@ +import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; import { expect } from "chai"; import { ethers } from "hardhat"; -import { getSigners } from "../signers"; import { FHEordle, FHEordleFactory, FHEordle__factory } from "../../types"; -import { createTransaction } from "../utils"; import { createInstances } from "../instance"; -import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; -import { WORDS } from './wordslist'; +import { getSigners } from "../signers"; +import { createTransaction } from "../utils"; +import { WORDS } from "./wordslist"; -export function genProofAndRoot(values: any, key: any) : [string, string[]] { +export function genProofAndRoot(values: any, key: any): [string, string[]] { const tree = StandardMerkleTree.of(values, ["uint16", "uint32"]); const root = tree.root; for (const [i, v] of tree.entries()) { @@ -22,22 +22,23 @@ export function genProofAndRoot(values: any, key: any) : [string, string[]] { export const wordAtIdToNumber = (id: number) => { const word = WORDS[id]; - return (word.charCodeAt(0)-97) - + (word.charCodeAt(1)-97) * 26 - + (word.charCodeAt(2)-97) * 26 * 26 - + (word.charCodeAt(3)-97) * 26 * 26 * 26 - + (word.charCodeAt(4)-97) * 26 * 26 * 26 * 26; -} + return ( + word.charCodeAt(0) - + 97 + + (word.charCodeAt(1) - 97) * 26 + + (word.charCodeAt(2) - 97) * 26 * 26 + + (word.charCodeAt(3) - 97) * 26 * 26 * 26 + + (word.charCodeAt(4) - 97) * 26 * 26 * 26 * 26 + ); +}; console.log(WORDS[3]); - -describe("FHEordle", function() { +describe("FHEordle", function () { before(async function () { this.signers = await getSigners(ethers); }); - it("should return correct masks", async function() { - + it("should return correct masks", async function () { // word // 0 1 3 2 4 // 0 + 1*26 + 3*26*26 + 2*26*26*26 + 4*26*26*26*26 @@ -54,23 +55,19 @@ describe("FHEordle", function() { // } const ourWord = wordsList[3][1]; - const [_root, proof] = genProofAndRoot( - wordsList, 3 - ); + const [_root, proof] = genProofAndRoot(wordsList, 3); console.log(_root); console.log(wordsSz); const fheordleFactoryFactory = await ethers.getContractFactory("FHEordleFactory"); const factoryContract: FHEordleFactory = await fheordleFactoryFactory.connect(this.signers.alice).deploy(); await factoryContract.waitForDeployment(); - const txDeploy = await createTransaction( - factoryContract.createTest, this.signers.bob.address - ); + const txDeploy = await createTransaction(factoryContract.createTest, this.signers.bob.address); await txDeploy.wait(); const testContractAddress = await factoryContract.userLastContract(this.signers.alice.address); const contract: FHEordle = FHEordle__factory.connect(testContractAddress).connect(this.signers.alice); - + this.contractAddress = await contract.getAddress(); this.instances = await createInstances(this.contractAddress, ethers, this.signers); @@ -93,12 +90,12 @@ describe("FHEordle", function() { // submit word letters (Bob-Relayer) { const bobContract = contract.connect(this.signers.bob); - const l0 = ourWord%26; - const l1 = (ourWord/26)%26; - const l2 = (ourWord/26/26)%26; - const l3 = (ourWord/26/26/26)%26; - const l4 = (ourWord/26/26/26/26)%26; - const mask = (1<