mirror of
https://github.com/zama-ai/fhevm-solidity.git
synced 2026-01-10 04:57:59 -05:00
ci/test-dev-image-v0.1.9-alpha
fhEVM
A Solidity library for interacting with an fhEVM blockchain.
Install
npm install fhevm
or
yarn install fhevm
Usage
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity >=0.8.13 <0.8.20;
import "fhevm/lib/TFHE.sol";
contract Counter {
euint32 counter;
function add(bytes calldata encryptedValue) public {
euint32 value = TFHE.asEuint32(encryptedValue);
counter = TFHE.add(counter, value);
}
function getCounter(bytes32 publicKey) returns (bytes memory) {
return TFHE.reencrypt(counter, publicKey);
}
}
See our documentation on https://docs.zama.ai/homepage/ for more examples.
Development Guide
Install dependencies (Solidity libraries and dev tools)
npm install
Note: Solidity files are formatted with prettier.
Generate TFHE lib and tests
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/Common.sol
lib/Precompiles.sol
lib/Impl.sol
lib/TFHE.sol
contracts/tests/TFHETestSuiteX.sol
test/tfheOperations/tfheOperations.ts
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.
Test
npm test
Description
Languages
TypeScript
99.4%
Python
0.5%