Skip to main content

Overview

FHERC20 introduces a new permission model called operators that replaces the traditional ERC20 allowance system. Instead of approving specific amounts (which would leak information about balances), FHERC20 uses time-based operator permissions that grant full access until an expiration timestamp.

Privacy Preserving

No amount-specific approvals means no information leakage about how much you’re willing to let others spend.

Time-Based Expiration

Operators have automatic expiration using Unix timestamps, reducing the need for explicit revocation.

Full Access

Operators can move any amount of tokens (up to your balance) without needing separate approvals for each transaction.

Simple Management

One function to grant, extend, or revoke operator permissions with intuitive timestamp-based control.

Why Operators Instead of Allowances?

The Problem with Traditional Allowances

Standard ERC20 uses the approve() function to grant spending permissions:
This approach has privacy issues for confidential tokens:
  • ❌ Reveals how much you’re willing to let someone spend
  • ❌ Requires updating allowances frequently
  • ❌ Can leak information about your balance
  • ❌ Doesn’t work well with encrypted amounts

The Operator Solution

FHERC20 operators grant permission without revealing amounts:
This approach is privacy-preserving:
  • ✅ No amount information revealed
  • ✅ Time-based expiration is automatic
  • ✅ Simple on/off permission model
  • ✅ Works perfectly with encrypted values

Setting Operators

Function Signature

Parameters:
  • operator: Address to grant operator permissions to
  • until: Unix timestamp when the permission expires (uint48 supports dates until year 8921556)

Basic Usage

Use uint48(block.timestamp + duration) to calculate expiration times. The uint48 type is large enough for practical use while being gas-efficient.

Checking Operator Status

Function Signature

Parameters:
  • holder: Address of the token holder
  • spender: Address to check operator status for
Returns:
  • true if spender is currently an authorized operator for holder
  • false if not authorized or permission has expired

Usage Examples


Using Operator Permissions

Once granted operator status, an address can use confidentialTransferFrom() to move tokens:

Complete Example


Internal Implementation

Storage

Operators are stored in a mapping with their expiration times:

Setting an Operator

Checking Operator Status

Transfer From Check

Before allowing a confidentialTransferFrom, the contract verifies operator status:

Operator Patterns

Pattern 1: Short-Lived Permissions

Grant operator permissions for specific transactions:

Operator vs Allowance Comparison


Security Considerations

Operator Has Full Access

An operator can transfer all of a holder’s tokens, not just a specific amount. Only grant operator permissions to trusted addresses.
Best practices:
  • Use short expiration times when possible
  • Only authorize trusted contracts or addresses
  • Monitor operator grants in your UI
  • Consider implementing additional checks in contracts

Time-Based Expiration

Operator permissions automatically expire based on blockchain timestamp:
Advantages:
  • Automatic cleanup
  • No gas cost for revocation
  • Predictable expiration
Considerations:
  • Block timestamps can vary slightly
  • Account for clock skew in time calculations
  • Use buffer time for critical operations

Front-Running Protection

Operator changes are atomic and immediate:
Unlike ERC20’s approve/transferFrom race condition, operator changes are safe from front-running because:
  • No amount is specified
  • Permission is binary (yes/no)
  • Time-based expiration is deterministic

Multiple Operators

A holder can have multiple operators simultaneously:
Consider:
  • Each operator has full access
  • Permissions are independent
  • Track all active operators
  • Implement operator limits if needed