Skip to content

Commit

Permalink
tests are passing for fheWordle
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Dec 21, 2024
1 parent 11ad3d6 commit 81985a1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 280 deletions.
16 changes: 8 additions & 8 deletions hardhat/contracts/fheWordle/FHEWordle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "fhevm/config/ZamaGatewayConfig.sol";
* @dev This contract leverages the TFHE library for encryption operations and the MerkleProof library for verifying word sets.
* The game state and logic are managed using various public and private variables.
*/
contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller, Ownable2Step, Initializable {
contract FHEWordle is GatewayCaller, Ownable2Step, Initializable {
// /// Constants
bytes32 public constant root = 0x918fd5f641d6c8bb0c5e07a42f975969c2575250dc3fb743346d1a3c11728bdd;
bytes32 public constant rootAllowed = 0xd3e7a12d252dcf5de57a406f0bd646217ec1f340bad869182e5b2bfadd086993;
Expand Down Expand Up @@ -67,6 +67,8 @@ contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayC

function initialize(address _playerAddr, address _relayerAddr, uint16 _testFlag) external initializer {
TFHE.setFHEVM(ZamaFHEVMConfig.getSepoliaConfig());
Gateway.setGateway(ZamaGatewayConfig.getSepoliaConfig());

relayerAddr = _relayerAddr;
playerAddr = _playerAddr;
testFlag = _testFlag;
Expand Down Expand Up @@ -252,7 +254,7 @@ contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayC
}
}

function revealWord() public onlyPlayer {
function revealWordAndStore() public onlyPlayer {
// Prepare the ciphertext array for the five letters
uint256[] memory cts = new uint256[](5);

Expand All @@ -272,18 +274,13 @@ contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayC
uint8 _l2,
uint8 _l3,
uint8 _l4
) public onlyPlayer returns (uint8, uint8, uint8, uint8, uint8) {
) public onlyGateway returns (uint8, uint8, uint8, uint8, uint8) {
l0 = _l0;
l1 = _l1;
l2 = _l2;
l3 = _l3;
l4 = _l4;
// Handle the decrypted word letters here (e.g., emit events or store values)
return (l0, l1, l2, l3, l4); // Optionally emit an event
}

function revealWordAndStore() public onlyPlayer {
require(l0 != 0 || l1 != 0 || l2 != 0 || l3 != 0 || l4 != 0, "Word not revealed yet");

word1 =
uint32(l0) +
Expand All @@ -301,6 +298,8 @@ contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayC
26 *
26 *
26;

return (l0, l1, l2, l3, l4); // Optionally emit an event
}

function checkProof(bytes32[] calldata proof) public onlyRelayer {
Expand All @@ -320,6 +319,7 @@ contract FHEWordle is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayC
decryptedWordId = _decryptedWordId;
// Handle the decrypted wordId and check the proof
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(decryptedWordId, word1))));

if (MerkleProof.verify(storedProof, root, leaf)) {
proofChecked = true;
}
Expand Down
13 changes: 4 additions & 9 deletions hardhat/contracts/fheWordle/FHEWordleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ pragma solidity ^0.8.20;

import "./FHEWordle.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
import "fhevm/lib/TFHE.sol";
import "fhevm/gateway/GatewayCaller.sol";
import "fhevm/config/ZamaFHEVMConfig.sol";
import "fhevm/config/ZamaGatewayConfig.sol";

/**
* @title FHEWordleFactory
* @notice This contract is a factory for deploying new instances of the FHEWordle game using the minimal proxy pattern (Clones).
Expand All @@ -16,7 +13,7 @@ import "fhevm/config/ZamaGatewayConfig.sol";
* @dev This contract uses OpenZeppelin's Clones library for creating deterministic contract instances and relies on the
* FHEWordle game logic deployed at a predefined implementation address.
*/
contract FHEWordleFactory is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller, Ownable2Step {
contract FHEWordleFactory is Ownable2Step {
address public creator;

mapping(address => address) public userLastContract;
Expand All @@ -43,9 +40,8 @@ contract FHEWordleFactory is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, G
function createGame(address _relayerAddr, bytes32 salt) public {
require(gameNotStarted(), "Previous game still in progress");

// address cloneAdd = Clones.cloneDeterministic(implementation, salt);
// Deploy a proxy for the FHEWordle implementation
address cloneAdd = Clones.clone(implementation);
address cloneAdd = Clones.cloneDeterministic(implementation, salt);

FHEWordle(cloneAdd).initialize(msg.sender, _relayerAddr, 0);
userLastContract[msg.sender] = cloneAdd;
Expand All @@ -62,9 +58,8 @@ contract FHEWordleFactory is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, G
require(gameNotStarted(), "Previous game still in progress");
require(userLastContract[msg.sender] == address(0), "kek");

// address cloneAdd = Clones.cloneDeterministic(implementation, salt);
// Deploy a proxy for the FHEWordle implementation
address cloneAdd = Clones.clone(implementation);
address cloneAdd = Clones.cloneDeterministic(implementation, salt);

FHEWordle(cloneAdd).initialize(msg.sender, _relayerAddr, id);
userLastContract[msg.sender] = cloneAdd;
Expand Down
Loading

0 comments on commit 81985a1

Please sign in to comment.