Integration guide
How to integrate Persona into your smart contract
Import IPersona interface
Import the necessary dependencies in your Solidity contract
Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {FHE, euint8, ebool} from "@fhevm/solidity/lib/FHE.sol";
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
import {IPersona} from "./IPersona.sol";
contract MyDApp is ZamaEthereumConfig {
IPersona public persona;
constructor(address personaAddr) {
persona = IPersona(personaAddr);
}
}Register your contract as verifier
Contact Persona admin to register your contract address. Only registered verifiers can call verification functions.
Note: Your contract must be registered by the Persona admin before it can access verification functions. Provide your deployed contract address to the admin.
Users can start using your dApp
Once registered in Persona, users can immediately interact with your dApp. Implement verification logic using FHE operations.
Solidity
// Example: Age-gated voting
function vote() external {
address user = msg.sender;
// Get encrypted boolean: is user 19+?
ebool canVote = persona.isAgeAtLeast(user, 19);
// Conditional state update using FHE.select
euint8 newVotes = FHE.add(votes[user], FHE.asEuint8(1));
votes[user] = FHE.select(canVote, newVotes, votes[user]);
// Transaction always succeeds, state only changes if eligible
}
// Example: Multi-condition airdrop
function claimReward() external {
address user = msg.sender;
// Combine multiple conditions
ebool isMale = persona.isMale(user);
ebool isBelow30 = persona.isAgeBetween(user, 0, 29);
ebool canClaim = FHE.and(isMale, isBelow30);
euint8 newClaims = FHE.add(claimCount[user], FHE.asEuint8(1));
claimCount[user] = FHE.select(canClaim, newClaims, claimCount[user]);
}Privacy protection
Whether a user is eligible or not, the transaction will always execute successfully. The state will only change if the user meets the criteria.
This design ensures that transaction success/failure does not leak information about a user's private attributes (age, gender, etc.), maintaining zero-knowledge privacy guarantees.
Available verification functions
isAgeAtLeast(user, age)Check if user age ≥ specified ageisAgeBetween(user, min, max)Check if user age is in range [min, max]isMale(user)Check if user gender is maleisFemale(user)Check if user gender is femaleAll functions return ebool (encrypted boolean)
Use FHE.select(), FHE.and(), FHE.or() to build conditional logic while maintaining encryption
Complete examples
See PersonaMock.sol for complete implementation examples: