RedactCore.sol
Overview
RedactCore.sol is the central management contract for the Redact protocol. It handles the deployment and tracking of confidential tokens (ConfidentialERC20) and manages special cases like ConfidentialETH. The contract maintains a registry of all deployed confidential tokens and their relationships with underlying ERC20 tokens.
Key Concepts
Token Registry
Maintains a mapping between ERC20 tokens and their confidential wrappers
Uses
EnumerableMapfor efficient iteration and lookupPrevents duplicate deployments of confidential wrappers
Special Token Handling
Manages ConfidentialETH (eETH) as a special case
Tracks stablecoins separately for potential special handling
Maintains WETH integration for ETH operations
Access Control
Implements
Ownable2Stepfor secure ownership managementRestricts critical operations to the contract owner (EX: renaming ConfidentialERC20s)
External Functions
View Functions
getFherc20(address erc20)
Returns the address of the confidential wrapper for a given ERC20 token
Returns
address(0)if no wrapper existsUsed to look up confidential token addresses
getIsStablecoin(address erc20)
Returns whether a token is registered as a stablecoin
Used for special handling of stablecoin tokens
getIsWETH(address erc20)
Returns whether a token is the WETH contract
Used for ETH-specific operations
getDeployedFherc20s()
Returns an array of all deployed confidential tokens
Includes both the original ERC20 and its confidential wrapper
Useful for UI integration and monitoring
State-Changing Functions
deployFherc20(IERC20 erc20)
Deploys a new ConfidentialERC20 wrapper for the specified token
Prevents deployment for:
Already wrapped tokens
Stablecoins
WETH (handled separately)
Emits
Fherc20Deployedevent
updateStablecoin(address stablecoin, bool isStablecoin)
Updates the stablecoin status of a token
Restricted to contract owner
Emits
StablecoinUpdatedevent
updateFherc20Symbol(ConfidentialERC20 fherc20, string memory updatedSymbol)
Updates the symbol of a deployed confidential token
Restricted to contract owner
Emits
Fherc20SymbolUpdatedevent
Special Cases
ConfidentialETH (eETH)
Pre-configured during contract deployment
Uses WETH as the underlying token
Handles native ETH wrapping/unwrapping
Special gas optimizations for ETH operations
Stablecoins
Can be marked as stablecoins for special handling
Prevents deployment of confidential wrappers for stablecoins
Allows for future implementation of stablecoin-specific features
Prepares for a future unified encrypted stablecoin.
Events
Fherc20Deployed(address indexed erc20, address indexed fherc20)
Fherc20Deployed(address indexed erc20, address indexed fherc20)Emitted when a new confidential token is deployed
Includes both the original and confidential token addresses
StablecoinUpdated(address indexed erc20, bool isStablecoin)
StablecoinUpdated(address indexed erc20, bool isStablecoin)Emitted when a token's stablecoin status is updated
Includes the token address and new status
Fherc20SymbolUpdated(address indexed fherc20, string symbol)
Fherc20SymbolUpdated(address indexed fherc20, string symbol)Emitted when a confidential token's symbol is updated
Includes the token address and new symbol
Error Handling
Custom Errors
Invalid_AlreadyDeployed(): Attempted to deploy wrapper for already wrapped tokenInvalid_Stablecoin(): Attempted to deploy wrapper for stablecoinInvalid_WETH(): Invalid WETH address providedInvalid_eETH(): Invalid eETH address provided
Integration Guide
Deployment
Deploy WETH contract if not already deployed
Deploy ConfidentialETH (eETH) contract
Deploy RedactCore with WETH and eETH addresses
Adding New Tokens
Check if token is already wrapped using
getFherc20If not wrapped, call
deployFherc20with the token addressMonitor
Fherc20Deployedevent for confirmation
UI Integration
Use
getDeployedFherc20sto list all available confidential tokensUse
getFherc20to look up specific token wrappersHandle special cases for ETH and stablecoins appropriately
Security Considerations
Access Control
Critical functions restricted to owner
Two-step ownership transfer process
Careful management of stablecoin status
Deployment Safety
Prevention of duplicate deployments
Validation of WETH and eETH addresses
Protection against stablecoin wrapping
Token Management
Secure symbol updates
Proper event emission for tracking
Safe handling of special cases
Last updated

