Skip to content

Commit 0e73b8a

Browse files
committed
added title
1 parent 71f25a4 commit 0e73b8a

File tree

3 files changed

+24
-51
lines changed

3 files changed

+24
-51
lines changed

README.md

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1-
# fhevm-react-template
2-
3-
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.
1+
# fhEVM dApp examples
42

3+
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.
54

65
## Examples featured
76

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

10-
The Confidential Counter examples demonstrate progressively more complex uses of FHE operations:
11-
12-
1. **Basic Counter (Sample 1)**
13-
- Simple encrypted counter using `euint8` type
14-
- Basic increment operation using FHE addition
15-
- Demonstrates minimal FHE setup and operations
16-
17-
2. **Input Counter (Sample 2)**
18-
- Accepts encrypted input values to increment by
19-
- Shows how to handle encrypted inputs with proofs
20-
- Demonstrates converting between encrypted types
21-
22-
3. **Decryptable Counter (Sample 3)**
23-
- Adds decryption capability via Gateway integration
24-
- Shows how to request and handle decryption callbacks
25-
- Maintains both encrypted and decrypted state
26-
27-
4. **Multi-User Counter (Sample 4)**
28-
- Individual encrypted counters per user address
29-
- Demonstrates access control with FHE
30-
- Shows re-encryption for specific users
31-
- Uses mapping for multiple encrypted values
10+
1. **Basic Counter**: Simple encrypted counter with basic increment operations
11+
2. **Input Counter**: Handles encrypted inputs with proofs and type conversions
12+
3. **Decryptable Counter**: Adds decryption capabilities and state management
13+
4. **Multi-User Counter**: Supports per-user encrypted counters with access control
3214

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

3517
### GuessRandomNumberGame
3618

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

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

121-
1. **Confidential Token**: A privacy-preserving ERC20 token implementation using Fully Homomorphic Encryption (FHE):
122-
- Balances and allowances are stored as encrypted values
123-
- Transfers and approvals operate on encrypted data
124-
- Inherits from ConfidentialERC20Mintable for basic token functionality
125-
126-
2. **Key Features**:
127-
- Encrypted balances using euint64 type
128-
- Standard ERC20 functions (transfer, approve, etc.) with FHE
129-
- Minting capability restricted to owner
130-
- Built-in decryption request/callback mechanism
131-
132-
3. **Secret Value Demo**:
133-
- Contains an encrypted SECRET value (set to 42)
134-
- Demonstrates Gateway decryption flow:
135-
- requestSecret() initiates decryption request
136-
- callbackSecret() receives and stores decrypted value
137-
- Shows basic FHE operations and Gateway integration
138-
139-
4. **Privacy Protection**:
140-
- All token balances and transfers are encrypted
141-
- Only transaction participants can view their own balances
142-
- Uses TFHE library for homomorphic operations
143-
- Integrates with Zama's FHE infrastructure
144-
145-
The contract showcases how to implement confidential tokens while maintaining ERC20 compatibility and leveraging FHE for privacy preservation.
104+
2. **Key Features**: Encrypted balances (euint64), standard ERC20 functions with FHE, and owner-restricted minting.
146105

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

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

149110
## How to use this repo
150111

hardhat/contracts/guessRandomNumberGame/GuessRandomNumberGame.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ contract GuessRandomNumberGame is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConf
144144
closestPreviousWinningValueDecrypted = _closestValueDecrypted;
145145
closestPreviousWinnerDecrypted = _closestOwnerDecrypted;
146146

147+
// Increment winner's score
148+
playerScores[closestPreviousWinnerDecrypted] += 1;
149+
147150
// Emit winner information
148151
emit WinnerDeclared(closestPreviousWinnerDecrypted, closestPreviousWinningValueDecrypted);
149152

hardhat/test/guessRandomNumberGame/GuessRandomNumberGame.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,14 @@ describe("EncryptedSecretKeeper", function () {
162162
closestOwnerDecrypted = await contract.closestPreviousWinnerDecrypted();
163163
// console.log("Second game closest Owner: ", closestOwnerDecrypted);
164164
expect(closestOwnerDecrypted).to.be.oneOf([this.signers.bob.address, this.signers.alice.address]);
165+
166+
// Check player scores are updated correctly
167+
const aliceScore = await contract.playerScores(this.signers.alice.address);
168+
const bobScore = await contract.playerScores(this.signers.bob.address);
169+
// console.log("Alice's score:", aliceScore);
170+
// console.log("Bob's score:", bobScore);
171+
172+
// At least one of them should have points after two games
173+
expect(aliceScore + bobScore).to.be.equal(2n); // Total score should be 2 after 2 games since each game has 1 winner
165174
});
166175
});

0 commit comments

Comments
 (0)