Skip to content

Commit

Permalink
added title
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Jan 13, 2025
1 parent 71f25a4 commit 0e73b8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 51 deletions.
63 changes: 12 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
# fhevm-react-template

This is an example dApp made with React.js to let users do transfers of a `ConfidentialERC20` token on fhEVM. It contains also a button to request the decryption of an encrypted secret value.
# fhEVM dApp examples

This repository contains example dApps built using fhEVM (Fully Homomorphic EVM). Each example demonstrates different aspects of building privacy-preserving smart contracts using FHE operations.

## Examples featured

### Confidential Counter
The Confidential Counter examples demonstrate progressively more complex uses of FHE operations through four samples:

The Confidential Counter examples demonstrate progressively more complex uses of FHE operations:

1. **Basic Counter (Sample 1)**
- Simple encrypted counter using `euint8` type
- Basic increment operation using FHE addition
- Demonstrates minimal FHE setup and operations

2. **Input Counter (Sample 2)**
- Accepts encrypted input values to increment by
- Shows how to handle encrypted inputs with proofs
- Demonstrates converting between encrypted types

3. **Decryptable Counter (Sample 3)**
- Adds decryption capability via Gateway integration
- Shows how to request and handle decryption callbacks
- Maintains both encrypted and decrypted state

4. **Multi-User Counter (Sample 4)**
- Individual encrypted counters per user address
- Demonstrates access control with FHE
- Shows re-encryption for specific users
- Uses mapping for multiple encrypted values
1. **Basic Counter**: Simple encrypted counter with basic increment operations
2. **Input Counter**: Handles encrypted inputs with proofs and type conversions
3. **Decryptable Counter**: Adds decryption capabilities and state management
4. **Multi-User Counter**: Supports per-user encrypted counters with access control

Each sample builds on the previous one to showcase different FHE capabilities while maintaining security and privacy of the counter values.
Each sample builds on the previous one to showcase different FHE capabilities.

### GuessRandomNumberGame

Expand Down Expand Up @@ -117,34 +99,13 @@ The system leverages FHE operations to enable privacy-preserving identity and cr
### MyConfidentialERC20.sol

**How it works**
1. **Confidential Token**: A privacy-preserving ERC20 token using FHE with encrypted balances, transfers and approvals.

1. **Confidential Token**: A privacy-preserving ERC20 token implementation using Fully Homomorphic Encryption (FHE):
- Balances and allowances are stored as encrypted values
- Transfers and approvals operate on encrypted data
- Inherits from ConfidentialERC20Mintable for basic token functionality

2. **Key Features**:
- Encrypted balances using euint64 type
- Standard ERC20 functions (transfer, approve, etc.) with FHE
- Minting capability restricted to owner
- Built-in decryption request/callback mechanism

3. **Secret Value Demo**:
- Contains an encrypted SECRET value (set to 42)
- Demonstrates Gateway decryption flow:
- requestSecret() initiates decryption request
- callbackSecret() receives and stores decrypted value
- Shows basic FHE operations and Gateway integration

4. **Privacy Protection**:
- All token balances and transfers are encrypted
- Only transaction participants can view their own balances
- Uses TFHE library for homomorphic operations
- Integrates with Zama's FHE infrastructure

The contract showcases how to implement confidential tokens while maintaining ERC20 compatibility and leveraging FHE for privacy preservation.
2. **Key Features**: Encrypted balances (euint64), standard ERC20 functions with FHE, and owner-restricted minting.

3. **Privacy Protection**: All operations are encrypted using TFHE, with balances visible only to transaction participants.

The contract implements confidential tokens with ERC20 compatibility using FHE for privacy.

## How to use this repo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ contract GuessRandomNumberGame is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConf
closestPreviousWinningValueDecrypted = _closestValueDecrypted;
closestPreviousWinnerDecrypted = _closestOwnerDecrypted;

// Increment winner's score
playerScores[closestPreviousWinnerDecrypted] += 1;

// Emit winner information
emit WinnerDeclared(closestPreviousWinnerDecrypted, closestPreviousWinningValueDecrypted);

Expand Down
9 changes: 9 additions & 0 deletions hardhat/test/guessRandomNumberGame/GuessRandomNumberGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,14 @@ describe("EncryptedSecretKeeper", function () {
closestOwnerDecrypted = await contract.closestPreviousWinnerDecrypted();
// console.log("Second game closest Owner: ", closestOwnerDecrypted);
expect(closestOwnerDecrypted).to.be.oneOf([this.signers.bob.address, this.signers.alice.address]);

// Check player scores are updated correctly
const aliceScore = await contract.playerScores(this.signers.alice.address);
const bobScore = await contract.playerScores(this.signers.bob.address);
// console.log("Alice's score:", aliceScore);
// console.log("Bob's score:", bobScore);

// At least one of them should have points after two games
expect(aliceScore + bobScore).to.be.equal(2n); // Total score should be 2 after 2 games since each game has 1 winner
});
});

0 comments on commit 0e73b8a

Please sign in to comment.