• Stars
    star
    387
  • Rank 110,971 (Top 3 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Solidity library for interacting with an fhEVM blockchain.


๐Ÿ“ƒ Read white paper | ๐Ÿ“’ Read documentation | ๐Ÿ’› Community support


Bring confidential smart contracts to your blockchain with fhEVM

There used to be a dilemma in blockchain: keep your application and user data on-chain, allowing everyone to see it, or keep it privately off-chain and lose contract composability. Thanks to a breakthrough in homomorphic encryption, Zamaโ€™s fhEVM makes it possible to run confidential smart contracts on encrypted data, guaranteeing both confidentiality and composability.

Zamaโ€™s fhEVM enables confidential smart contracts using fully homomorphic encryption (FHE)

  • End-to-end encryption of transactions and state: Data included in transactions is encrypted and never visible to anyone.
  • 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-exist alongside public one, and doesn't impact existing dapps.

Developers can write confidential smart contracts without learning cryptography

  • 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.

You can take a look at our list of examples.

Powerful features available out of the box

  • 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

fhEVM implementation

For now, fhEVM is implemented on evmos. You can find all the resources related to this implementation on this repository.

Install

# Using npm
npm install fhevm

# Using Yarn
yarn add fhevm

# Using pnpm
pnpm add fhevm

Usage

// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity 0.8.19;

import "fhevm/lib/TFHE.sol";

contract Counter {
  euint32 counter;

  function add(bytes calldata encryptedValue) public {
    euint32 value = TFHE.asEuint32(encryptedValue);
    counter = counter + value;
  }

  function getCounter(bytes32 publicKey) returns (bytes memory) {
    return TFHE.reencrypt(counter, publicKey);
  }
}

See our documentation on https://docs.zama.ai/fhevm/writing-contract/getting_started for more details.

Development Guide

Install dependencies (Solidity libraries and dev tools)

npm install

Note: Solidity files are formatted with prettier.

Generate TFHE lib

npm run codegen

WARNING: Use this command to generate Solidity code and prettier result automatically!

Files that are generated now (can be seen inside codegen/main.ts)

lib/Impl.sol
lib/TFHE.sol
contracts/tests/TFHETestSuiteX.sol
test/tfheOperations/tfheOperations.ts

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

# in one terminal
npm run fhevm:start
# in another terminal
npm i
cp .env.example .env
./scripts/faucet.sh
npm test

Docker

We provide a docker image to spin up a fhEVM node for local development.

npm run fhevm:start
# stop
npm run fhevm:stop

Faucet

For development purposes, we provide a ready to use wallet. In order to use it, prepare the .env file that contains the mnemonic.

cp .env.example .env

This allows the developer to use a few accounts, each account can get coins:

npm run fhevm:faucet:alice
npm run fhevm:faucet:bob
npm run fhevm:faucet:carol

Run test

npm test

Error: insufficient funds

Ensure the faucet command was succesful.


Run tests for network1 network

# codegen for network1 network
TARGET_NETWORK=Network1 npx ts-node codegen/main.ts && npm run prettier
# run tests for network1 network, assumes network1 rpc already running locally
npx hardhat test --network localNetwork1

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.

Contributing

There are two ways to contribute to the Zama fhEVM:

  • you can open issues to report bugs or typos, or to suggest new ideas
  • you can ask to become an official contributor by emailing [email protected]. (becoming an approved contributor involves signing our Contributor License Agreement (CLA)) Only approved contributors can send pull requests, so please make sure to get in touch before you do!

Credits

This library uses several dependencies and we would like to thank the contributors of those libraries.

Need support?

License

This software is distributed under the BSD-3-Clause-Clear license. If you have any questions, please contact us at [email protected].

More Repositories

1

concrete

Concrete: TFHE Compiler that converts python programs into FHE equivalent
C++
911
star
2

concrete-ml

Concrete ML: Privacy Preserving ML framework using Fully Homomorphic Encryption (FHE), built on top of Concrete, with bindings to traditional ML frameworks.
Python
881
star
3

tfhe-rs

TFHE-rs: A Pure Rust implementation of the TFHE Scheme for Boolean and Integer Arithmetics Over Encrypted Data.
Rust
860
star
4

bounty-program

Zama Bounty Program: Contribute to the FHE space and Zama's open source libraries and get rewarded ๐Ÿ’ฐ
233
star
5

concrete-numpy

Concrete-Numpy: A library to turn programs into their homomorphic equivalent.
Python
219
star
6

awesome-zama

A curated list of amazing Fully Homomorphic Encryption (FHE) resources created by the team at Zama.
204
star
7

concrete-core

Concrete Core contains a set of low-level primitives which can be used to implement Fully Homomorphically Encrypted (FHE) programs.
Rust
73
star
8

fhevm-go

fhevm-go is an open-source library used to easily integrate the fhEVM into an EVM-compatible blockchain.
Go
21
star
9

concrete-fft

Rust
15
star
10

fhevmjs

A dapp SDK for the fhEVM ecosystem
TypeScript
13
star
11

concrete-ntt

Rust
13
star
12

verifiable-fhe-paper

Verifiable FHE prototype
Rust
13
star
13

hnp-examples

Repository to store hnp usage examples
11
star
14

go-ethereum

fhEVM reference implementation
Go
8
star
15

demo_z8z

Demo using Concrete library to implement exact homomorphic computation with 3-bit integers
Rust
8
star
16

fhevm-decryptions-db

The fhEVM Decryptions Database is a key-value database of decryption results.
Rust
8
star
17

fhe-tutorials

Jupyter Notebook
8
star
18

evmos

Go
7
star
19

fhe-biometrics

Jupyter Notebook
7
star
20

fhevm-hardhat-template

fhEVM hardhat template
TypeScript
6
star
21

fhe_game_of_life

Rust
6
star
22

fhevm-tfhe-cli

TFHE-rs CLI tool for the fhEVM
Rust
4
star
23

ethcc23-workshop

Python
4
star
24

concrete-fftw

C
4
star
25

fhevm-L1-demo

Shell
4
star
26

fhevmjs-react-template

TypeScript
3
star
27

concrete-compiler-internal-llvm-project

Internal fork of llvm-project for concrete-compiler-internal
2
star
28

concrete-example-client-server

Rust
2
star
29

ethermint

A component of the fhEVM stack. Fork of the original ethermint repository.
Go
1
star
30

.github

1
star
31

fhevmjs-vue-template

Vue
1
star