Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix due to change in hardhat-templates + README #642

Merged
merged 36 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4ad87af
docs: update README and MockZamaFHEVMConfig removed
poppyseedDev Dec 6, 2024
a7269de
docs: update typescript sample templates
poppyseedDev Dec 6, 2024
067dc79
docs: gas added
poppyseedDev Dec 10, 2024
af6f634
docs: resolve webpack error structure
poppyseedDev Dec 10, 2024
e724e02
Merge branch 'main' of github.com:zama-ai/fhevm into docs-fhevm06
poppyseedDev Dec 10, 2024
24c8cb7
docs: readme upgrade and tests
poppyseedDev Dec 10, 2024
7c9ff83
docs: mini change
poppyseedDev Dec 10, 2024
2408493
docs: review
poppyseedDev Dec 11, 2024
09248a3
docs: added immutable
poppyseedDev Dec 11, 2024
57e75ca
docs: types removed Declaring encrypted state variables
poppyseedDev Dec 11, 2024
26e80df
docs: add asxxoperation
poppyseedDev Dec 11, 2024
6ea9cdf
docs: added asXXoperation
poppyseedDev Dec 11, 2024
109be85
docs: mini change
poppyseedDev Dec 11, 2024
524649a
docs: apply suggestions from code review
poppyseedDev Dec 11, 2024
d19ebb5
docs: mini changes
poppyseedDev Dec 11, 2024
7ce49e2
docs: mini changes
poppyseedDev Dec 11, 2024
f164fed
docs: mini change
poppyseedDev Dec 11, 2024
840bcf0
docs: mini change
poppyseedDev Dec 11, 2024
095e3f5
Merge branch 'docs-fhevm06' of github.com:zama-ai/fhevm into docs-fhe…
poppyseedDev Dec 11, 2024
e6550e3
Update README.md
jatZama Dec 11, 2024
56527cc
Update README.md
jatZama Dec 11, 2024
56e4e50
Update README.md
jatZama Dec 11, 2024
72f6294
Update README.md
jatZama Dec 11, 2024
d67afd9
Update docs/fundamentals/asXXoperation.md
jatZama Dec 11, 2024
75f42ac
Update docs/fundamentals/asXXoperation.md
jatZama Dec 11, 2024
b42ff39
Update docs/fundamentals/asXXoperation.md
jatZama Dec 11, 2024
b6f2e2c
Update docs/fundamentals/asXXoperation.md
jatZama Dec 11, 2024
452493e
Update docs/fundamentals/asXXoperation.md
jatZama Dec 11, 2024
7888443
docs: mini changes
poppyseedDev Dec 11, 2024
230e8b1
docs: as operations
poppyseedDev Dec 11, 2024
ed4b10e
docs: gitbook problems
poppyseedDev Dec 11, 2024
f9ccf03
docs: mini change
poppyseedDev Dec 11, 2024
5f7ed5d
docs: change
poppyseedDev Dec 11, 2024
095f432
docs: remove changes from tests
poppyseedDev Dec 11, 2024
910234e
docs: mini update
poppyseedDev Dec 11, 2024
3658c74
Merge branch 'main' of github.com:zama-ai/fhevm into docs-fhevm06
poppyseedDev Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 56 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,25 @@ _Find more details on implementation instructions in [this repository](https://g
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import "fhevm/config/ZamaFHEVMConfig.sol";

contract Counter {
euint32 counter;
contract Counter is SepoliaZamaFHEVMConfig {
euint8 internal counter;

constructor() {
counter = TFHE.asEuint8(0);
TFHE.allowThis(counter);
}

function add(einput valueInput, bytes calldata inputProof) public {
euint32 value = TFHE.asEuint32(valueInput, inputProof);
euint32 value = TFHE.asEuint8(valueInput, inputProof);
counter = TFHE.add(counter, value);
TFHE.allow(counter, address(this));
TFHE.allowThis(counter);
}
}
```

_More examples are available [here](https://github.com/zama-ai/fhevm/tree/main/examples)._
_More examples are available [here](https://docs.zama.ai/fhevm/tutorials/see-all-tutorials)._

<p align="right">
<a href="#about" > ↑ Back to top </a>
Expand All @@ -136,24 +142,61 @@ _More examples are available [here](https://github.com/zama-ai/fhevm/tree/main/e

## Resources

### White paper
### **White Paper**

- [Confidential EVM Smart Contracts using Fully Homomorphic Encryption](https://github.com/zama-ai/fhevm/blob/main/fhevm-whitepaper.pdf)
<br></br>
Gain insights into the technology powering fhEVM with our in-depth white paper:
👉 [**Confidential EVM Smart Contracts using Fully Homomorphic Encryption**](https://github.com/zama-ai/fhevm/blob/main/fhevm-whitepaper-v2.pdf)

---

### **Demos and Tutorials**

Access a curated collection of demos and step-by-step tutorials to guide your development journey:
🔗 [**Visit the Tutorials Page**](https://docs.zama.ai/fhevm/tutorials/see-all-tutorials)

---

### **Documentation**

Master `fhEVM` and build smarter contracts using these resources:

- 📘 [**Comprehensive fhEVM Documentation**](https://docs.zama.ai/fhevm)
Dive deep into Zama's detailed guide for utilizing the full potential of fhEVM.

- 🤖 [**ZAMA Solidity Developer (Modified ChatGPT Model)**](https://chatgpt.com/g/g-67518aee3c708191b9f08d077a7d6fa1-zama-solidity-developer)
Accelerate your smart contract development with AI-powered assistance.

### Demos and Tutorials
### **Development templates**

For a comprehensive list of demos and tutorials, visit our [tutorials page](https://docs.zama.ai/fhevm/tutorials/see-all-tutorials).
Start building faster with pre-configured templates tailored for various frameworks:

### Documentation
#### **Smart Contracts**

Full, comprehensive documentation is available here: [https://docs.zama.ai/fhevm](https://docs.zama.ai/fhevm).
- 🔧 [**Hardhat Template**](https://github.com/zama-ai/fhevm-hardhat-template)
Smart contracts testing and development
- 💻 [**fhEVM Contracts**](https://github.com/zama-ai/fhevm-contracts)
Library of standardized fhEVM contracts.

#### **Frontend frameworks**

- 🌐 [**React.js Template**](https://github.com/zama-ai/fhevm-react-template)
Simplify your FHE dApp development with a clean and optimized React.js template.
- ⚡ [**Next.js Template**](https://github.com/zama-ai/fhevm-next-template)
Build server-rendered, scalable dApps with FHE support using this Next.js template.
- 🖼️ [**Vue.js Template**](https://github.com/zama-ai/fhevm-vue-template)
Create modular, responsive dApps with FHE capabilities using Vue.js.

---

### 🚀 **Kickstart Your Project Today!**

Leverage these templates to accelerate your development process and bring your ideas to life faster.

<p align="right">
<a href="#about" > ↑ Back to top </a>
</p>

### Blockchain Implementation
## Blockchain Implementation

To support fhEVM in an EVM-based blockchain, the **fhevm-go** library can be used as it implements all the needed FHE functionalities.
It is available here: [fhevm-go](https://github.com/zama-ai/fhevm-go)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure fhevm-go is still maintained, maybe you should change this to point to fhevm-backend. wdyt @immortal-tofu @leventdem

Expand Down Expand Up @@ -197,57 +240,11 @@ test/tfheOperations/tfheOperations.ts
<a href="#about" > ↑ Back to top </a>
</p>

#### Tests

The easiest way to understand how to write/dev smart contract and interact with them using **fhevmjs** is to read and explore the available tests in this repository.

##### Fast start

```bash
# in one terminal
npm run fhevm:start
# in another terminal
npm i
cp .env.example .env
npm run test:mock
```

</details>

##### Run test on a real fhEVM

```bash
npm run test -- --network sepolia
```

#### Adding new operators

Operators can be defined as data inside `codegen/common.ts` file and code automatically generates solidity overloads.
Test for overloads must be added (or the build doesn't pass) inside `codegen/overloadsTests.ts` file.

#### Mocked mode

The mocked mode allows faster testing and the ability to analyze coverage of the tests. In this mocked version, encrypted types are not really encrypted, and the tests are run on the original version of the EVM, on a local hardhat network instance. To run the tests in mocked mode, you can use directly the following command:

```bash
npm run test:mock
```

To analyze the coverage of the tests (in mocked mode necessarily, as this cannot be done on the real fhEVM node), you can use this command :

```bash
npm run coverage:mock
```

Then open the file `coverage/index.html`. You can see there which line or branch for each contract which has been covered or missed by your test suite. This allows increased security by pointing out missing branches not covered yet by the current tests.

> [!Note]
> Due to intrinsic limitations of the original EVM, the mocked version differ in few corner cases from the real fhEVM, the main difference is the difference in gas prices for the FHE operations. This means that before deploying to production, developers still need to run the tests with the original fhEVM node, as a final check in non-mocked mode, with `npm run test`.

<p align="right">
<a href="#about" > ↑ Back to top </a>
</p>

### Citations

To cite fhEVM or the whitepaper in academic papers, please use the following entries:
Expand Down
3 changes: 3 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
- [Branching in FHE](guides/conditions.md)
- [Generate random numbers](guides/random.md)
- [Error handling](guides/error_handling.md)
- [Gas estimation](guides/gas.md)
- [Trivial encrypt](guides/trivial_encrypt.md)
- [Debug decrypt](guides/debug_decrypt.md)
- [Frontend](guides/frontend/README.md)
- [Build a web application](guides/frontend/webapp.md)
- [Build with Node](guides/frontend/node.md)
Expand Down
6 changes: 3 additions & 3 deletions docs/fundamentals/acl/acl_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ The ACL system allows you to define two types of permissions for accessing ciphe

```solidity
import "fhevm/lib/TFHE.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

contract SecretGiver is MockZamaFHEVMConfig {
contract SecretGiver is SepoliaZamaFHEVMConfig {
SecretStore public secretStore;

constructor() {
Expand All @@ -56,7 +56,7 @@ contract SecretGiver is MockZamaFHEVMConfig {
```

```
contract SecretStore is MockZamaFHEVMConfig {
contract SecretStore is SepoliaZamaFHEVMConfig {
euint16 public secretResult;

function storeSecret(euint16 callerSecret) public {
Expand Down
26 changes: 7 additions & 19 deletions docs/fundamentals/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,24 @@ This configuration contract initializes the **fhEVM environment** with required
**Import based on your environment:**

```solidity
// For Mock testnet
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

// For Ethereum Sepolia
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

// For Ethereum Mainnet (when ready)
import { EthereumZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
```

**Purpose:**

- Sets encryption parameters such as cryptographic keys and supported ciphertext types.
- Ensures proper initialization of the FHEVM environment.

**Example: using mock configuration**
**Example: using Sepolia configuration**

```solidity
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

contract MyERC20 is MockZamaFHEVMConfig {
contract MyERC20 is SepoliaZamaFHEVMConfig {
constructor() {
// Additional initialization logic if needed
}
Expand All @@ -58,30 +52,24 @@ To perform decryption or reencryption, your contract must interact with the **Ga
**Import based on your environment**

```solidity
// For Mock testnet
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";

// For Ethereum Sepolia
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";

// For Ethereum Mainnet (when ready)
import { EthereumZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
```

**Purpose**

- Configures the Gateway for secure cryptographic operations.
- Facilitates reencryption and decryption requests.

**Example: Configuring the gateway with mock settings**
**Example: Configuring the gateway with Sepolia settings**

```solidity
import "fhevm/lib/TFHE.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import "fhevm/gateway/GatewayCaller.sol";

contract Test is MockZamaFHEVMConfig, MockZamaGatewayConfig, GatewayCaller {
contract Test is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
constructor() {
// Gateway and FHEVM environment initialized automatically
}
Expand Down
30 changes: 15 additions & 15 deletions docs/fundamentals/decryption/decrypt.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Here’s an example of how to request decryption in a contract:
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import "fhevm/gateway/GatewayCaller.sol";

contract TestAsyncDecrypt is MockZamaFHEVMConfig, MockZamaGatewayConfig, GatewayCaller {
contract TestAsyncDecrypt is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
ebool xBool;
bool public yBool;

Expand All @@ -55,8 +55,8 @@ contract TestAsyncDecrypt is MockZamaFHEVMConfig, MockZamaGatewayConfig, Gateway
1. **Configuration imports**: The configuration contracts are imported to set up the FHEVM environment and Gateway.

```solidity
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
```

2. **`GatewayCaller` import**:\
Expand All @@ -75,15 +75,15 @@ Remember our [**Encrypted Counter**](../../getting_started/first_smart_contract.
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import "fhevm/gateway/GatewayCaller.sol";

/// @title EncryptedCounter3
/// @notice A contract that maintains an encrypted counter and is meant for demonstrating how decryption works
/// @dev Uses TFHE library for fully homomorphic encryption operations and Gateway for decryption
/// @custom:experimental This contract is experimental and uses FHE technology with decryption capabilities
contract EncryptedCounter3 is MockZamaFHEVMConfig, MockZamaGatewayConfig, GatewayCaller {
contract EncryptedCounter3 is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
/// @dev Decrypted state variable
euint8 counter;
uint8 public decryptedCounter;
Expand Down Expand Up @@ -133,14 +133,14 @@ Here’s a sample test for the Encrypted Counter contract using Hardhat:

```ts
import { awaitAllDecryptionResults, initGateway } from "../asyncDecrypt";
import { createInstances } from "../instance";
import { createInstance } from "../instance";
import { getSigners, initSigners } from "../signers";
import { expect } from "chai";
import { ethers } from "hardhat";

describe("EncryptedCounter3", function () {
before(async function () {
await initSigners(2); // Initialize signers
await initSigners(); // Initialize signers
this.signers = await getSigners();
await initGateway(); // Initialize the gateway for decryption
});
Expand All @@ -150,26 +150,26 @@ describe("EncryptedCounter3", function () {
this.counterContract = await CounterFactory.connect(this.signers.alice).deploy();
await this.counterContract.waitForDeployment();
this.contractAddress = await this.counterContract.getAddress();
this.instances = await createInstances(this.signers); // Set up instances for testing
this.instances = await createInstance(); // Set up instances for testing
});

it("should increment counter multiple times and decrypt the result", async function () {
it("should increment counter and decrypt the result", async function () {
// Create encrypted input for amount to increment by
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
const input = this.instances.createEncryptedInput(this.contractAddress, this.signers.alice.address);
input.add8(5); // Increment by 5 as an example
const encryptedAmount = await input.encrypt();

// Call incrementBy with encrypted amount
const tx = await this.counterContract.incrementBy(encryptedAmount.handles[0], encryptedAmount.inputProof);
await tx.wait();

const tx4 = await this.counterContract.connect(this.signers.carol).requestDecryptCounter({ gasLimit: 5_000_000 });
const tx4 = await this.counterContract.connect(this.signers.carol).requestDecryptCounter();
await tx4.wait();

// Wait for decryption to complete
await awaitAllDecryptionResults();

// Check decrypted value
// Check decrypted value (should be 3: initial 0 + three increments)
const decryptedValue = await this.counterContract.getDecryptedCounter();
expect(decryptedValue).to.equal(5);
});
Expand Down
6 changes: 3 additions & 3 deletions docs/fundamentals/decryption/decrypt_details.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ For example, see this snippet where we add two `uint256`s during the request cal
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
import "fhevm/gateway/GatewayCaller.sol";

contract TestAsyncDecrypt is MockZamaFHEVMConfig, MockZamaGatewayConfig, GatewayCaller {
contract TestAsyncDecrypt is SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig, GatewayCaller {
euint32 xUint32;
uint32 public yUint32;

Expand Down
Loading
Loading