Skip to content

Commit

Permalink
docs: improve the learn fundamentals
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Jan 22, 2025
1 parent 7e33720 commit 63406b4
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 181 deletions.
48 changes: 0 additions & 48 deletions docs/getting_started/key_concepts.md

This file was deleted.

68 changes: 50 additions & 18 deletions docs/getting_started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,55 @@ Thanks to a breakthrough in FHE, Zama’s fhEVM makes it possible to run confide
- **Composability and data availability on-chain**: States are updated while remaining encrypted at all times.
- **No impact on existing dapps and state**: Encrypted state co-exists alongside public one, and doesn't impact existing dapps.

## Main features

- **Solidity integration**: fhEVM contracts are simple solidity contracts that are built using traditional solidity toolchains.
- **Simple developer experience**: Developers can use the euint data types to mark which part of their contracts should be private.
- **Programmable privacy**: All the logic for access control of encrypted states is defined by developers in their smart contracts.
- **High precision encrypted integers** : Up to 256 bits of precision for integers
-Full range of Operators : All typical operators are available: +, -, \*, /, <, >, ==, …
- **Encrypted `if-else` conditionals**: Check conditions on encrypted states
- **On-chain PRNG**: Generate secure randomness without using oracles
- **Configurable decryption**: Threshold, centralized or KMS decryption
- **Unbounded compute depth**: Unlimited consecutive FHE operations

## Use cases

- **Tokenization**: Swap tokens and RWAs on-chain without others seeing the amounts.
- **Blind auctions**: Bid on items without revealing the amount or the winner.
- **On-chain games**: Keep moves, selections, cards, or items hidden until ready to reveal.
- **Confidential voting**: Prevents bribery and blackmailing by keeping votes private.
- **Encrypted DIDs**: Store identities on-chain and generate attestations without ZK.
- **Private transfers**: Keep balances and amounts private, without using mixers.
fhEVM enables powerful privacy-preserving applications across key blockchain sectors:

### 1. Decentralized Finance (DeFi)

- **Private Trading & AMMs**
- Execute trades without revealing amounts or strategies
- Prevent front-running and MEV exploitation
- Create dark pools with hidden order books
- **Confidential Lending**
- Keep collateral amounts and positions private
- Protect borrowing history and credit scores
- Enable private under-collateralized lending
- **Example**: [Confidential ERC20 tutorial](../getting_started/quick_start/overview.md)

### 2. Identity & Governance

- **Decentralized Identity**
- Store encrypted credentials on-chain
- Issue private attestations
- Verify membership without revealing identity
- **Private Voting**
- Cast encrypted votes without revealing choices
- Prevent voter coercion and vote buying
- Enable quadratic voting with private token balances
- **Example**: [Decentralized identity](https://github.com/zama-ai/dapps/tree/main/hardhat/contracts/decIdentity)

### 3. Enterprise Solutions

- **Supply Chain**
- Track sensitive business metrics privately
- Share data selectively with partners
- Maintain competitive advantages on-chain
- **Data Markets**
- Trade data while preserving confidentiality
- Enable private computation services
- Create subscription-based data access

### 4. Gaming & NFTs

- **Strategy Games**
- Hide player moves and game state
- Enable private bidding and trading of in-game assets
- Implement truly random number generation
- **NFT Privacy**
- Conceal ownership and transfer history
- Keep metadata and attributes private
- Enable sealed-bid NFT auctions
- **Example**: [FHE Wordle](https://github.com/zama-ai/dapps/tree/main/hardhat/contracts/fheWordle)

These applications showcase how fhEVM uniquely combines the transparency and composability of blockchain with the privacy guarantees of FHE, enabling a new generation of confidential smart contracts.
4 changes: 2 additions & 2 deletions docs/getting_started/quick_start/overview.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Quick Start: Build Your First FHE Smart Contract
# Quick start tutorial: Build your first FHE smart contract

Welcome to the world of **Fully Homomorphic Encryption (FHE)** and privacy-preserving smart contracts! This tutorial will guide you step-by-step through deploying your first **confidential smart contract** using Zama’s groundbreaking FHE technology.

### What you'll zchieve
### What you'll achieve

In just **~20 minutes**, you’ll:

Expand Down
57 changes: 6 additions & 51 deletions docs/getting_started/quick_start/understandingERC20.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

The **ConfidentialERC20** contract is a privacy-preserving implementation of the ERC20 token standard, leveraging **Fully Homomorphic Encryption (FHE)**. It combines the familiar functionality of ERC20 tokens with powerful encryption features to protect user privacy.

---
## Key features

## Key Features

### 1. **Encrypted Balances**
### Encrypted balances

ConfidentialERC20 revolutionizes the way balances are stored by encrypting them using FHE.

- **Enhanced Privacy**: Balances are stored as encrypted values (`euint64`), ensuring no one can view account balances by inspecting the blockchain.
- **Exclusive Access**: Only the account owner can decrypt and view their own balance.
- **Encrypted Transactions**: Transaction amounts are also encrypted, maintaining confidentiality.

---

### 2. **Standard ERC20 Functions with Encryption**
### Standard ERC20 Functions with Encryption

ConfidentialERC20 supports all the standard ERC20 functions, adapted for encrypted values. For example:

Expand All @@ -26,15 +22,15 @@ ConfidentialERC20 supports all the standard ERC20 functions, adapted for encrypt
- `balanceOf`: Returns the encrypted balance of an account.
- `totalSupply`: Returns the encrypted total token supply.

---
To dive deeper into the workings of ConfidentialERC20, check out the [Zama blog post](https://www.zama.ai/post/confidential-erc-20-tokens-using-homomorphic-encryption).

## What is `ConfidentialERC20Mintable`?

The **`ConfidentialERC20Mintable`** contract, part of the **`fhevm-contracts`** library, extends the ConfidentialERC20 by adding **minting capabilities**.

### **Key Features**

- **Confidential Balances**: All balances are encrypted, safeguarding user privacy.
- **All ConfidentialERC20 functions**: Since the `ConfidentialERC20Mintable` is extending the `ConfidentialERC20` contract, it has all the functionalities that the `ConfidentialERC20` contract has.
- **Minting**: The contract owner can securely create new tokens and distribute them.

## What are `fhevm-contracts`?
Expand All @@ -48,45 +44,4 @@ The `fhevm-contracts` library is a collection of **privacy-preserving smart cont

The library serves as both a reference implementation and a toolkit for developers building privacy-focused applications on the fhEVM. It demonstrates best practices for implementing confidential operations while maintaining compatibility with existing Ethereum standards.

### Key Components

- **Token Standards**: Confidential versions of popular token standards (ERC20, ERC721, etc.)
- **Access Control**: FHE-compatible permission and role management systems
- **Security Features**: Built-in safeguards and checks for encrypted operations
- **Utility Functions**: Helper methods for common FHE operations

## Installing `fhevm-contracts`

While Remix automatically imports dependencies, you can manually install the `fhevm-contracts` library for local development:

```bash
# Using npm
npm install fhevm-contracts

# Using Yarn
yarn add fhevm-contracts

# Using pnpm
pnpm add fhevm-contracts
```

---

## Additional Examples in `fhevm-contracts`

Here are more examples of contracts available in the **fhevm-contracts** library:

- [**ConfidentialERC20**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/ConfidentialERC20.sol): Standard encrypted ERC20 implementation.
- [**ConfidentialERC20Wrapped**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/ConfidentialERC20Wrapped.sol): Wrapped ERC20 tokens with encryption.
- [**ConfidentialWETH**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/ConfidentialWETH.sol): Confidential version of wrapped Ether.
- [**ConfidentialERC20Mintable**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol): ERC20 with encryption and minting capabilities.
- [**ConfidentialERC20WithErrors**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol): ERC20 with encrypted balances and integrated error handling.
- [**ConfidentialERC20WithErrorsMintable**](https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol): Combines minting and error handling in an encrypted ERC20 token.

---

### Learn more

For this tutorial, we focus on the **`ConfidentialERC20Mintable`** contract, as it provides both the essential functionalities of ERC20 and secure minting. To dive deeper into the workings of ConfidentialERC20, check out the [Zama blog post](https://www.zama.ai/post/confidential-erc-20-tokens-using-homomorphic-encryption).

Explore more advanced features and concepts in the next section! 🚀
To learn more about the `fhevm-contracts` and how to use them refer to the [fhevm-contracts page-](../../smart_contracts/contracts.md)
51 changes: 31 additions & 20 deletions docs/tutorials/learn_fundamentals/hardhat.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ This guide will help you set up a development environment for building privacy-p

## Getting Started

Learn how to write, test and deploy fhEVM specific smart contracts with Hardhat.

1\. Go to <https://github.com/zama-ai/fhevm-hardhat-template>

2\. Create a new repository from this template.

![](https://colony-recorder.s3.amazonaws.com/files/2025-01-17/49d22a7e-bba5-4dee-b7f9-60d675970fa3/stack_animation.webp)

3\. [[git clone]] the repository you have created.

![](https://colony-recorder.s3.amazonaws.com/files/2025-01-17/bbee17d3-aa84-45ce-92b7-4f9c44239711/stack_animation.webp)

1. Clone the template repository:

```bash
Expand All @@ -38,11 +50,15 @@ This guide will help you set up a development environment for building privacy-p
pnpm install
```

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2025-01-17/6504ddf1-f841-48b6-a84e-ddc6946c1ae2/File.jpeg?tl_px=0,41&br_px=3024,1964&force_format=jpeg&q=100&width=1120.0&wat=1&wat_opacity=1&wat_gravity=northwest&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/FB923C_standard.png&wat_pad=59,408)

## Development Workflow

- Place your smart contracts in the `contracts/` directory
- Place your tests under the `tests/` directory

![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2025-01-20/03790808-a211-4b7d-a87f-1734305177b5/ascreenshot.jpeg?tl_px=0,18&br_px=1719,979&force_format=jpeg&q=100&width=1120.0&wat=1&wat_opacity=1&wat_gravity=northwest&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/FB923C_standard.png&wat_pad=157,277)

### Testing

Run the test suite using:
Expand All @@ -51,35 +67,30 @@ Run the test suite using:
pnpm test
```

## Deployment to Sepolia Testnet
![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2025-01-17/2128ed01-f2c9-4a85-9fd7-4af37686e2af/ascreenshot.jpeg?tl_px=0,41&br_px=3024,1964&force_format=jpeg&q=100&width=1120.0&wat=1&wat_opacity=1&wat_gravity=northwest&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/FB923C_standard.png&wat_pad=629,553)

Follow these steps to deploy your contracts to the Sepolia testnet:
7\. When ready to **deploy** type `cast wallet new-mnemonic` to generate a new mnemonic seed and copy it to the `.env` file.

1. Generate a wallet:
![](https://colony-recorder.s3.amazonaws.com/files/2025-01-20/93145686-0ef2-4636-a7ac-9bb25c8a43a6/stack_animation.webp)

```bash
cast wallet new-mnemonic
```
8\. Add a `SEPOLIA_RPC_URL` from sites like Alchemy or Infura

Copy the generated mnemonic seed phrase to your `.env` file.
![](https://ajeuwbhvhr.cloudimg.io/colony-recorder.s3.amazonaws.com/files/2025-01-20/05128377-e779-44bc-b177-a2159e766cd8/ascreenshot.jpeg?tl_px=416,0&br_px=2136,961&force_format=jpeg&q=100&width=1120.0&wat=1&wat_opacity=1&wat_gravity=northwest&wat_url=https://colony-recorder.s3.amazonaws.com/images/watermarks/FB923C_standard.png&wat_pad=909,169)

2. Set up RPC access:
9\. Type `npx hardhat get-accounts --num-accounts 5` to see which accounts have been generated.

- Get an RPC URL from [Alchemy](https://www.alchemy.com/) or [Infura](https://www.infura.io/)
- Add it to your `.env` file as `SEPOLIA_RPC_URL`
![](https://colony-recorder.s3.amazonaws.com/files/2025-01-20/51576e45-72c9-492b-9c7e-0fb3c8393da4/stack_animation.webp)

3. Verify your accounts:
10\. Import the first 2 accounts (alice and bob) and fund them

```bash
npx hardhat get-accounts --num-accounts 5
```
![](https://colony-recorder.s3.amazonaws.com/files/2025-01-20/8009d260-6693-40f2-8117-0412fa7f6c39/stack_animation.webp)

This will show the addresses that will be used for deployment.
11\. Deploy the contracts by running `pnpm deploy-sepolia`

4. Deploy your contracts:
![](https://colony-recorder.s3.amazonaws.com/files/2025-01-20/2dd9fa0a-190a-46c2-b3be-12394bb4de1c/stack_animation.webp)

```bash
pnpm deploy-sepolia
```
12\. Find the deployed contract on <https://sepolia.etherscan.io/>

![](https://colony-recorder.s3.amazonaws.com/files/2025-01-20/7c45e315-a133-4592-b856-3ebb85fb23a6/stack_animation.webp)

5. Once deployed, you can view your contract on [Sepolia Etherscan](https://sepolia.etherscan.io/)
#### [Made with Scribe](https://scribehow.com/shared/Get_started_with_Hardhat__1fcheHVgTIuGETSdEBRmkw)
Loading

0 comments on commit 63406b4

Please sign in to comment.