Skip to main content

Command Palette

Search for a command to run...

Eternal MEV : Can Fully Homomorphic Encryption Power Private DeFi?

Updated
9 min read
Eternal MEV : Can Fully Homomorphic Encryption Power Private DeFi?

Would it be OK for you ? if all the people around the world were able to see your bank loans and collateral assets ? No privacy ? this is the current situation in DeFi though we've eliminated the problem of centralized limitations the one lacking issue is privacy.

While transparency enables trust less verification, it also exposes sensitive financial state to the entire network. Large positions, borrowing activity, collateral ratios, and liquidation risk become visible to competitors, market observers, and automated trading bots, making financial privacy difficult to achieve in today's DeFi ecosystem.

Can we build DeFi where computation remains public
but financial data stays private?

To build a DeFi with a feature of financial data being private we can use Fully Homomorphic Encryption (FHE) before we move further let's understand

  • What Fully Homomorphic Encryption (FHE) actually is ?

  • Cryptographic Magic behind FHE ?

  • Why FHE is beyond ZK proofs ?

  • Does FHE eliminates MEV ?

  • Will the Cross-Chain Interoperability be disrupted by FHE ?

The Foundations of Confidential Finance

So what is FHE?

FHE is a cryptographic system that lets you compute on encrypted data without the requirement of data to be decrypted. So it is like performing actions without knowing what data you have or is shared with you.

The key idea behind:

Magic Mechanism :

  • Homomorphic public-key encryption scheme consists of four algorithms:

    • KeyGen​: Generates a public/private key pair (pk,sk).

    • Encrypt​: Encrypts a plaintext using the public key pk.

    • Decrypt: Decrypts a ciphertext using the secret key sk.

    • Evaluate​: The special homomorphic operation that allows computation directly on encrypted data.

    The Evaluate algorithm takes:

    • the public key pk,

    • a circuit C from an allowed set of circuits CE,

    • a collection of ciphertexts Ψ = 〈ψ1, . . . , ψt〉; it outputs a ciphertext ψ

Remember All four algorithms must run in time polynomial in the security parameter λ. Additionally, Evaluate algorithm must run in time polynomial in both λ and the size of the circuit C.

Correctness Requirement

The scheme is considered correct for circuits in C​ if the following condition holds:

  • Generate Keys:
  • Encrypt plaintexts:
  • Evaluate circuit C directly on the ciphertexts:
  • similarity of output:

in simple representation we could also define FHE as :

The magic is that Evaluate​ produces a ciphertext that decrypts to exactly the same value you would have obtained by executing C on the original plaintext.

Why FHE Goes Beyond zk-Proofs

zero knowledge proofs works the same then what makes FHE a level above ??

Zero-knowledge proofs (ZKPs) are designed to prove whether a statement about data is true or false without revealing the underlying data itself. However, they do not allow someone to modify or compute on encrypted data without first accessing the plaintext. In traditional encrypted systems, performing computations often requires repeated decryption and re-encryption, which can be computationally expensive and time-consuming. This is where Fully Homomorphic Encryption (FHE) becomes valuable. FHE enables computations to be performed directly on encrypted data, allowing users to process and verify information without ever revealing the underlying plaintext.

Does FHE eliminates MEV ?

MEV refers to Maximal extractable value. There exists lots of MEV bots since blockchain is transparent this creates an opportunity for persons to earn profit by various ways . These bots actually works by monitoring transactions.

FHE can significantly reduce some forms of MEV, but it does not eliminate MEV altogether. With FHE, transaction details (amounts, prices, strategies, etc.) could remain encrypted while validators process them. This makes it much harder for bots to inspect transactions and exploit them before execution.

Though FHE is successful in reducing the MEV bots but not all MEV bots comes from seeing transaction contents some MEV arises from transaction ordering, block production rights, arbitrage between markets etc..

Even if transaction contents are encrypted, whoever controls ordering may still extract value.

Will the Cross-Chain Interoperability disrupted by FHE ?

The answer is no, Infact FHE has the potential to significantly enhance it. Cross-chain interoperability focuses on enabling different blockchains to communicate, transfer assets, and share state information, while FHE focuses on allowing computations to be performed directly on encrypted data.

By integrating FHE into cross-chain protocols, sensitive information such as wallet balances, trading strategies, collateral positions, or transaction details can remain encrypted throughout the communication and computation process. This allows blockchains to verify and process cross-chain messages without exposing the underlying data to validators, relayers, or other network participants.

Building Private DeFi

As a developer building DeFi is really good experience one should work on. Lets build a private DeFi. You don't need to implement FHE cryptography yourself. A handful of tool kits handle the heavy lifting so you can write something close to normal Solidity.

Step 1 : A Confidential Token

For the requirement to swap privately we need tokens that do hide balances. For this we can use ERC-7894 you can read about the ERC-7894 from : https://bit.ly/4em3rwj

//solidity 
import "fhevm/lib/TFHE.sol";

contract ConfidentialToken {
    mapping(address => euint64) private balances;

function mint(address to, einput encryptedAmount, bytes calldata proof) external {
    euint64 amount = TFHE.asEuint64(encryptedAmount, proof);
    balances[to] = TFHE.add(balances[to], amount);
}

function transfer(address to, einput encryptedAmount, bytes calldata proof) external {
    euint64 amount = TFHE.asEuint64(encryptedAmount, proof);

    ebool canPay = TFHE.le(amount, balances[msg.sender]);

    euint64 amountToSend = TFHE.select(canPay, amount, TFHE.asEuint64(0));

    balances[msg.sender] = TFHE.sub(balances[msg.sender], amountToSend);
    balances[to] = TFHE.add(balances[to], amountToSend);
}

function balanceOf(address user) external view returns (euint64) {
    return balances[user];
}
}

the two functions mint and transfer functions never see the actual uint64 instead they receive an einput which is then converted into an euint64 ciphertext using TFHE.asEuint64, along with a proof that the user encrypted it correctly (this prevents someone from submitting a forged ciphertext). The balance check uses TFHE.le to produce an encrypted boolean rather than a plain bool, and TFHE.select is used instead of a require statement — reverting on "insufficient balance" would itself leak information (an observer could infer the sender's balance was below the transfer amount), so the contract instead silently sends zero tokens if the check fails.

STEP 2: Swap contract

contract PrivateSwap {
    ConfidentialToken public tokenA;
    ConfidentialToken public tokenB;


euint64 private reserveA;
euint64 private reserveB;

constructor(address _tokenA, address _tokenB) {
    tokenA = ConfidentialToken(_tokenA);
    tokenB = ConfidentialToken(_tokenB);
}

function swapAforB(einput encryptedAmountIn, einput encryptedMinOut, bytes calldata proof) external {
    euint64 amountIn = TFHE.asEuint64(encryptedAmountIn, proof);
    euint64 minOut = TFHE.asEuint64(encryptedMinOut, proof);

   amountOut = (reserveB * amountIn) / (reserveA + amountIn)
    euint64 newReserveA = TFHE.add(reserveA, amountIn);
    euint64 numerator = TFHE.mul(reserveB, amountIn);
    euint64 amountOut = TFHE.div(numerator, newReserveA);

    // slippage   protection

    ebool meetsMin = TFHE.ge(amountOut, minOut);
    euint64 finalAmountOut = TFHE.select(meetsMin, amountOut, TFHE.asEuint64(0));
    euint64 finalAmountIn = TFHE.select(meetsMin, amountIn, TFHE.asEuint64(0));

    reserveA = TFHE.add(reserveA, finalAmountIn);
    reserveB = TFHE.sub(reserveB, finalAmountOut);

    
}
}

as you can see here there is no amountIn or amountout visible and no require(amountout >= minout) present unlike traditional Uniswap-style contracts..

Step 3: The Frontend

import { createInstance } from "fhevmjs";

async function swapTokens(amountIn, minOut) {
  const fhevm = await createInstance({ chainId: 8009, networkUrl: RPC_URL });

  // Encrypt the trade amount and slippage tolerance client-side
  const encryptedAmountIn = fhevm.encrypt64(amountIn);
  const encryptedMinOut = fhevm.encrypt64(minOut);

  const tx = await privateSwapContract.swapAforB(
    encryptedAmountIn.handle,
    encryptedMinOut.handle,
    encryptedAmountIn.inputProof
  );

  console.log("Swap submitted:", tx.hash);
}

async function getMyBalance() {
  const encryptedBalance = await confidentialToken.balanceOf(userAddress);

  const balance = await fhevm.decrypt(confidentialToken.address, encryptedBalance);
  console.log("My balance:", balance);
}```

The crucial detail here is that amountIn and minOut never leave the browser as plaintext — they're encrypted with the network's public key before the transaction is even built

These is how we build a private DeFi for swapping crypto currencies.Though FHE is a great cryptographic system it comes along with some challenges

Challenge Why It's Hard Current Approach
Gas costs of FHE ops Encrypted multiplication and division are far more expensive than plaintext equivalents Coprocessors and off-chain FHE execution, with only verification on-chain
Throughput Encrypted networks currently run at a fraction of normal EVM TPS GPU-accelerated coprocessors, with ASIC roadmaps targeting much higher throughput
Decryption trust Someone has to hold the keys to decrypt results when needed Threshold decryption networks split key shares across many independent nodes
Composability Encrypted values from one contract need to be usable in another Standardized encrypted types (ERC-7984) so confidential tokens plug into confidential DEXs, lending markets, etc.
Auditing & debugging You can't simply log encrypted intermediate values to debug Local "mock" FHE modes that run in plaintext during development, switched to real ciphertexts before deployment

The Future: Where Private DeFi founded itself

Private DeFi could really be a standard part of ecosystem rather than just a niche feature. Decentralized exchanges may be able to hide trade details and order books, making it much harder for attackers to exploit users through techniques like sandwich attacks. Lending protocols could keep collateral amounts, loan sizes, and health factors private while still ensuring loans remain secure. Emerging standards like ERC-7984 aim to make private tokens as easy to use and integrate as today's ERC-20 tokens, allowing users to move confidential assets seamlessly across wallets, exchanges, and lending platforms.

Conclusion-Point of Understanding:

Private DeFi isn't about hiding that a transaction happened — the chain still records it. It's about hiding the details: how much, to whom, and at what price. FHE lets that math run correctly without anyone, including the validators executing it, ever seeing the underlying numbers. The confidential swap above is intentionally minimal, but the pattern — encrypted inputs, TFHE.select instead of require, and re-encryption for the end user — is the same pattern you'll find in confidential lending, private payroll, or sealed-bid auctions. Once you've built one, the rest of private DeFi starts to look like variations on a theme. at the end, I would like to recommend a research paper about FHE. I hope you'll surely enjoy understanding it .

Link of Research Paper : https://bit.ly/3S1kfBb