Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kroist committed Dec 18, 2023
1 parent 4b8af9a commit 088e4fa
Show file tree
Hide file tree
Showing 6 changed files with 5,865 additions and 5,930 deletions.

This file was deleted.

78 changes: 33 additions & 45 deletions contracts/FHEordle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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)))
)
)
),
Expand Down Expand Up @@ -153,30 +146,18 @@ 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));
euint8 g1 = TFHE.asEuint8(TFHE.eq(word1Letters[1], l1));
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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -261,5 +250,4 @@ contract FHEordle is EIP712WithModifier {
require(msg.sender == playerAddr);
_;
}

}
}
9 changes: 2 additions & 7 deletions contracts/FHEordleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -69,7 +67,4 @@ contract FHEordleFactory is EIP712WithModifier {
gamesWon[msg.sender] += 1;
}
}



}
}
Loading

0 comments on commit 088e4fa

Please sign in to comment.