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 22 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
122 changes: 56 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ _Learn more use cases in the [list of examples](https://docs.zama.ai/fhevm/tutor

### Installation

For now, fhEVM is implemented on evmos.

```bash
# Using npm
npm install fhevm
Expand All @@ -101,9 +99,6 @@ yarn add fhevm
pnpm add fhevm
```

_Find more details on implementation instructions in [this repository](https://github.com/zama-ai/fhevm-evmos)._
<br></br>

### A Simple Example

```solidity
Expand All @@ -112,19 +107,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);
euint8 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,27 +137,62 @@ _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 smart contracts using these resources:

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

For a comprehensive list of demos and tutorials, visit our [tutorials page](https://docs.zama.ai/fhevm/tutorials/see-all-tutorials).
- 🤖 [**ZAMA Solidity Developer (Modified ChatGPT Model)**](https://chatgpt.com/g/g-67518aee3c708191b9f08d077a7d6fa1-zama-solidity-developer)
Accelerate your smart contract development with AI-powered assistance.

### Documentation
### **Development templates**

Full, comprehensive documentation is available here: [https://docs.zama.ai/fhevm](https://docs.zama.ai/fhevm).
Start building faster with pre-configured templates tailored for various frameworks:

#### **Smart Contracts**

- 🔧 [**Hardhat Template**](https://github.com/zama-ai/fhevm-hardhat-template)
Smart contracts testing and development <- primary entry point for developers wanting to develop smart contracts on fhEVM
Copy link
Member

Choose a reason for hiding this comment

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

can you put the last part with the arrow in bold and italic? I think it would make it even clearer. We really want to avoid many support questions from new devs not understanding how to start and trying directly to run tests from fhevm repo instead of hardhat-template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the README is not the primary entry point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if https://github.com/zama-ai/fhevm -> is the primary entry point we have communication issues elsewhere

jatZama marked this conversation as resolved.
Show resolved Hide resolved
- 💻 [**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)

To integrate fhevm-go into any EVM-based blockchain, you can follow the [Integration Guide](https://docs.zama.ai/fhevm-go/getting_started/integration).

Expand Down Expand Up @@ -197,57 +233,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 @@ -22,6 +22,7 @@
- [Configuration](fundamentals/configure.md)
- [Supported types](fundamentals/types.md)
- [Operations on encrypted types](fundamentals/operations.md)
- [asEbool, asUintXX and asEBytesXX operations](fundamentals/asXXoperation.md)
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
- [Access Control List](fundamentals/acl/README.md)
- [ACL examples](fundamentals/acl/acl_examples.md)
- [Encrypted Inputs](fundamentals/inputs.md)
Expand All @@ -38,6 +39,8 @@
- [Branching in FHE](guides/conditions.md)
- [Generate random numbers](guides/random.md)
- [Error handling](guides/error_handling.md)
- [Gas estimation](guides/gas.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
156 changes: 156 additions & 0 deletions docs/fundamentals/asXXoperation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# asEbool, asUintXX and asEbytesXX operations
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved

This documentation covers the `asEbool`, `asEuintXX`, and `asEbytesXX` operations provided by the TFHE library for working with encrypted data in the fhEVM. These operations are essential for converting between plaintext and encrypted types, as well as handling encrypted inputs.
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved

The operations can be categorized into three main use cases:

1. **Trivial encryption**: Converting plaintext values to encrypted types
2. **Type casting**: Converting between different encrypted types
3. **Input handling**: Processing encrypted inputs with proofs

## 1. Trivial input
Copy link
Member

Choose a reason for hiding this comment

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

Should be "Trivial Encryption" everywhere, not trivial input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we had a discussion with Levent on this it's a bit easier to clasify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or you know what yeah will just convert to trivial encrypt

Copy link
Member

Choose a reason for hiding this comment

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

as you wish, but I think Trivial encryption makes more sense because few lines earlier you already used trivial encryption, so let's not use different terminologies for same concept


Trivial input simply put is a plain text in a format of a ciphertext.

### Overview

Trivial input is the process of converting plaintext values into encrypted types (ciphertexts) compatible with TFHE operators. Although the data is in ciphertext format, it remains publicly visible on-chain, making it useful for operations between public and private values.

This type of casting involves converting plaintext (unencrypted) values into their encrypted equivalents, such as:

- `bool` → `ebool`
- `uint` → `euintXX`
- `bytes` → `ebytesXX`

poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
> **Note**: When doing trivial encrypt, the data is made compatible with FHE operations but remains publicly visible on-chain unless explicitly encrypted.
Copy link
Member

Choose a reason for hiding this comment

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

trivial encryption

jatZama marked this conversation as resolved.
Show resolved Hide resolved

#### **Example**

```solidity
euint64 value64 = TFHE.asEuint64(7262); // Trivial encrypt a uint64
ebool valueBool = TFHE.asEbool(true); // Trivial encrypt a boolean
```

### Trivial encryption of `ebytesXX` types

The `TFHE.padToBytesXX` functions facilitate this trivial encryption process for byte arrays, ensuring compatibility with `ebytesXX` types. These functions:

- Pad the provided byte array to the appropriate length (`64`, `128`, or `256` bytes).
- Prevent runtime errors caused by improperly sized input data.
- Work seamlessly with `TFHE.asEbytesXX` for trivial encryption.

> **Important**: Trivial encryption does NOT provide any privacy guarantees. The input data remains fully visible on the blockchain. Only use trivial encryption when working with public values that need to interact with actual encrypted data.

#### Workflow

1. **Pad Input Data**:
Use the `padToBytesXX` functions to ensure your byte array matches the size requirements.
2. **Encrypt the Padded Data**:
Use `TFHE.asEbytesXX` to encrypt the padded byte array into the corresponding encrypted type.
3. **Grant Access**:
Use `TFHE.allowThis` and `TFHE.allow` to define access control for the encrypted data.
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
jatZama marked this conversation as resolved.
Show resolved Hide resolved

### Example: Trivial Encryption with `ebytesXX`

Below is an example demonstrating how to encrypt and manage `ebytes64`, `ebytes128`, and `ebytes256` types:

```solidity
function trivialEncrypt() public {
// Encrypt a 64-byte array
ebytes64 yBytes64 = TFHE.asEbytes64(
TFHE.padToBytes64(
hex"19d179e0cc7e816dc944582ed4f5652f5951900098fc2e0a15a7ea4dc8cfa4e3b6c54beea5ee95e56b728762f659347ce1d4aa1b05fcc5"
)
);
TFHE.allowThis(yBytes64);
TFHE.allow(yBytes64, msg.sender);

// Encrypt a 128-byte array
ebytes128 yBytes128 = TFHE.asEbytes128(
TFHE.padToBytes128(
hex"13e7819123de6e2870c7e83bb764508e22d7c3ab8a5aee6bdfb26355ef0d3f1977d651b83bf5f78634fa360aa14debdc3daa6a587b5c2fb1710ab4d6677e62a8577f2d9fecc190ad8b11c9f0a5ec3138b27da1f055437af8c90a9495dad230"
)
);
TFHE.allowThis(yBytes128);
TFHE.allow(yBytes128, msg.sender);

// Encrypt a 256-byte array
ebytes256 yBytes256 = TFHE.asEbytes256(
TFHE.padToBytes256(
hex"d179e0cc7e816dc944582ed4f5652f5951900098fc2e0a15a7ea4dc8cfa4e3b6c54beea5ee95e56b728762f659347ce1d4aa1b05fcc513e7819123de6e2870c7e83bb764508e22d7c3ab8a5aee6bdfb26355ef0d3f1977d651b83bf5f78634fa360aa14debdc3daa6a587b5c2fb1710ab4d6677e62a8577f2d9fecc190ad8b11c9f0a5ec3138b27da1f055437af8c90a9495dad230"
)
);
TFHE.allowThis(yBytes256);
TFHE.allow(yBytes256, msg.sender);
}
```

## 2. Casting between encrypted types

This type of casting is used to reinterpret or convert one encrypted type into another. For example:

- `euint32` → `euint64`
- `ebytes128` → `ebytes256`

Casting between encrypted types is often required when working with operations that demand specific sizes or precisions.

> **Important**: When casting between encrypted types:
>
> - Casting from smaller types to larger types (e.g. `euint32` → `euint64`) preserves all information
> - Casting from larger types to smaller types (e.g. `euint64` → `euint32`) will truncate and lose information

The table below summarizes the available casting functions:

| From type | To type | Function |
| --------- | -------- | ---------------- |
| `euintX` | `euintX` | `TFHE.asEuintXX` |
| `ebool` | `euintX` | `TFHE.asEuintXX` |
| `euintX` | `ebool` | `TFHE.asEboolXX` |
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved

{% hint style="info" %}
Casting between encrypted types is efficient and often necessary when handling data with differing precision requirements.
{% endhint %}

### **Workflow for encrypted types**

```solidity
// Casting between encrypted types
euint32 value32 = TFHE.asEuint32(value64); // Cast to euint32
ebool valueBool = TFHE.asEbool(value32); // Cast to ebool
```

## 3. Encrypted input

### Overview

Encrypted input casting is the process of interpreting a handle (ciphertext reference) and its proof as a specific encrypted type. This ensures the validity of the input before it is used in computations.

Encrypted inputs is in depth explained in the following section: [encrypted inputs](./inputs.md)

#### Example

```solidity
euint64 encryptedValue = TFHE.asEuint64(einputHandle, inputProof); // Interpret einputHandle as euint64
```

#### Details

Encrypted input casting validates:

1. The input handle references a valid ciphertext.
2. The accompanying proof matches the expected type.

For more information, see the [Encrypetd inputs documentation](./inputs.md)

## Overall operation summary

| Casting Type | Function | Input Type | Output Type |
| ------------------------ | ----------------------- | ----------------- | ----------- |
| Trivial input | `TFHE.asEuintXX(x)` | `uintX` | `euintX` |
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
jatZama marked this conversation as resolved.
Show resolved Hide resolved
| | `TFHE.asEbool(x)` | `bool` | `ebool` |
| | `TFHE.asEbytesXX(x)` | `bytesXX` | `ebytesXX` |
| Conversion between types | `TFHE.asEuintXX(x)` | `euintXX`/`ebool` | `euintYY` |
| | `TFHE.asEbool(x)` | `euintXX` | `ebool` |
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
| Encrypted input | `TFHE.asEuintXX(x, y)` | `einput`, proof | `euintX` |
jatZama marked this conversation as resolved.
Show resolved Hide resolved
| | `TFHE.asEbool(x, y)` | `einput`,proof | `ebool` |
jatZama marked this conversation as resolved.
Show resolved Hide resolved
| | `TFHE.asEbytesXX(x, y)` | `einput`,proof | `ebytesXX` |
poppyseedDev marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading