Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions hello-fhevm/contracts/HelloFHEVM.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/*
* Helloβ€―FHEVM – a minimal confidential contract
* β€’ Stores an encrypted counter (euint64) on‑chain.
* β€’ Anyone can increment the counter with an encrypted value.
* β€’ Provides helpers to read the raw ciphertext or the decrypted count.
*
* Uses Zama’s TFHE library from the @zama/fhevm package.
*/
import "fhevm/lib/TFHE.sol";

contract HelloFHEVM {
// Encrypted 64‑bit unsigned integer stored as ciphertext
euint64 private encryptedCount;

// Initialise the counter to an encrypted zero
constructor() {
encryptedCount = TFHE.encryptUint64(0);
}

// Increment the encrypted counter with an encrypted value
function increment(euint64 _value) external {
encryptedCount = TFHE.add(encryptedCount, _value);
}

// Return the raw ciphertext (still encrypted)
function getEncryptedCount() external view returns (euint64) {
return encryptedCount;
}

// Decrypt the counter for the caller (via fhevmjs off‑chain)
function getDecryptedCount() external view returns (uint64) {
return TFHE.decryptUint64(encryptedCount);
}
}
41 changes: 41 additions & 0 deletions hello-fhevm/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions hello-fhevm/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
25 changes: 25 additions & 0 deletions hello-fhevm/frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
{
ignores: [
"node_modules/**",
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
],
},
];

export default eslintConfig;
26 changes: 26 additions & 0 deletions hello-fhevm/frontend/lib/helloFHEVM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ethers } from "ethers";
import { TFHE } from "fhevmjs";

const rpc = process.env.NEXT_PUBLIC_FHEVM_RPC!;
const contractAddress = process.env.NEXT_PUBLIC_CONTRACT_ADDRESS!;

// ABI – only the functions we’ll call from the UI
const abi = [
"function setSecret(uint32 _value) external",
"function increment(euint64 _value) external",
"function requestDecryption() external",
"function getEncryptedCount() external view returns (uint256)",
"function lastDecrypted() external view returns (uint64)",
];

export const getContract = (signer?: ethers.Signer) => {
const provider = new ethers.JsonRpcProvider(rpc);
const signerOrProvider = signer ?? provider;
return new ethers.Contract(contractAddress, abi, signerOrProvider);
};

/** Helper: encrypt a plain uint64 β†’ ciphertext (uint256) */
export const encryptUint64 = (value: number): string => {
// `TFHE.encryptUint64` returns a hex string prefixed with 0x
return TFHE.encryptUint64(BigInt(value));
};
7 changes: 7 additions & 0 deletions hello-fhevm/frontend/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
Loading