How alexzoid-eth/2023-10-badger-fv works
Purpose and entry points
eBTC is an Ethereum smart-contract protocol, derived from Liquity, that accepts only stETH collateral and issues an ERC-20/ERC-2612 synthetic BTC asset. The deployable protocol is in packages/contracts/contracts; user entry points are packages/contracts/contracts/BorrowerOperations.sol (borrower lifecycle) and packages/contracts/contracts/CdpManager.sol (liquidations/redemptions). Deployment scripts and network parameters live in packages/contracts/mainnetDeployment/eBTCDeployScript.js and packages/contracts/mainnetDeployment/eBTCDeploymentParams.mainnet.js.
Borrowing and CDP lifecycle
BorrowerOperations opens, adjusts, and closes collateralized debt positions (CDPs), moves stETH into system custody, and mints/burns eBTC through authorized paths. It also supports delegated position managers and EIP-3156 flash loans.
• packages/contracts/contracts/BorrowerOperations.sol
• packages/contracts/contracts/Interfaces/IBorrowerOperations.sol
• packages/contracts/contracts/Dependencies/EbtcBase.sol
CDP state, ordering, liquidation, redemption
CdpManager owns non-borrower CDP operations and coordinates system-wide debt/collateral accounting. LiquidationLibrary is delegatecalled by the manager, sharing state through CdpManagerStorage; this delegatecall/storage coupling is a critical code and upgrade boundary. SortedCdps maintains the ICR-ordered doubly linked list that determines redemption order, while HintHelpers supplies approximate insertion hints.
• packages/contracts/contracts/CdpManager.sol
• packages/contracts/contracts/LiquidationLibrary.sol
• packages/contracts/contracts/CdpManagerStorage.sol
• packages/contracts/contracts/SortedCdps.sol
• packages/contracts/contracts/HintHelpers.sol
Collateral custody and surplus isolation
ActivePool holds/accountably tracks system stETH collateral, supports fee-recipient collateral-share claims, and exposes ERC-3156 flash-lending behavior. Liquidation/redemption collateral that belongs to users but is no longer system collateral is isolated in CollSurplusPool; this separation is an explicit accounting boundary.
• packages/contracts/contracts/ActivePool.sol
• packages/contracts/contracts/CollSurplusPool.sol
• packages/contracts/contracts/Interfaces/IActivePool.sol
eBTC token and authorization
EBTCToken is the issued debt asset, implementing ERC-20, permit (ERC-2612), and controlled mint/burn functions. Governor plus inherited authorization contracts assign function capabilities; operations affecting supply, fees, pauses, oracle fallback, and redemption parameters are governed, expected behind multisig/timelock except selected emergency actions.
• packages/contracts/contracts/EBTCToken.sol
• packages/contracts/contracts/Governor.sol
• packages/contracts/contracts/Dependencies/AuthNoOwner.sol
• packages/contracts/contracts/Dependencies/RolesAuthority.sol
Pricing and external dependencies
PriceFeed is a state machine over a primary oracle and configurable fallback oracle, handling oracle failures before CDP health, liquidation, and redemption logic consumes prices. Runtime external dependencies are Ethereum mainnet, stETH, Chainlink, and potentially an arbitrary fallback oracle; Tellor code exists but is stated not to be used.
• packages/contracts/contracts/PriceFeed.sol
• packages/contracts/contracts/Interfaces/IPriceFeed.sol
• packages/contracts/contracts/Interfaces/IFallbackCaller.sol
Leverage and smart-wallet integration
Leverage macros compose external swaps/callbacks with CDP actions. The reference macro is owner-scoped and factory deployed; the delegate target is intended for compatible smart wallets. SimplifiedDiamondLike permits custom callback handling and delegatecall, making caller context and callback validation security-critical.
• packages/contracts/contracts/LeverageMacroBase.sol
• packages/contracts/contracts/LeverageMacroFactory.sol
• packages/contracts/contracts/SimplifiedDiamondLike.sol
Verification and execution environment
Contracts target Solidity 0.8.17 and are developed/tested with Foundry plus Hardhat/JavaScript tooling. CI runs Foundry and contract tests. Security validation includes Echidna/Medusa fuzzing and Certora specs/harnesses, with formal coverage focused on pool, token, and sorted-CDP invariants.
• packages/contracts/foundry.toml
• packages/contracts/hardhat.config.js
• certora/confs/ActivePool_verified.conf
• certora/specs/ActivePool.spec
Main entry points: eBTCDeployScript.js Mainnet Deployment · ActivePool.spec Formal Verification
Components 18
Core protocol
CDP debt, collateral, and settlement.
- Borrower Operations · Opens, adjusts, and closes borrower CDPs.
- CDP Manager · Coordinates liquidations, redemptions, and global accounting.
- Manager Storage · Storage boundary shared with liquidation delegatecall code.
- Liquidation Library · Runs in CdpManager storage context.
- Sorted CDPs · Doubly linked list defining redemption order.
- Hint Helpers
- Active Pool · Tracks system collateral, fee claims, and flash loans.
- Collateral Surplus Pool · Isolates collateral no longer owned by the system.
- eBTC Token · Controlled synthetic-BTC debt token minting and burning.
Governance
Capability-based administrative control.
- Governor · Assigns privileged protocol capabilities.
- Roles Authority
Integrations
Oracle and smart-wallet execution boundaries.
- Price Feed · Selects primary or fallback pricing during oracle failures.
- Chainlink & fallback oracle
- stETH
- Leverage Macro Factory · Deploys owner-scoped leverage macros.
- Smart-wallet Delegate Target · Custom callbacks and delegatecall require validated caller context.
Deployment & assurance
- Mainnet Deployment · Deploys contracts with mainnet parameters.
packages/contracts/mainnetDeployment/eBTCDeployScript.js - Formal Verification · Covers pool, token, and sorted-CDP invariants.
certora/specs/ActivePool.spec
Connections 25
- Borrower Operations → CDP Manager: updates CDPs
- Borrower Operations → Active Pool: moves stETH
- Borrower Operations → eBTC Token: mints / burns
- CDP Manager → Liquidation Library: delegatecalls · Critical shared-storage and upgrade boundary.
- Liquidation Library → Manager Storage: uses
- CDP Manager → Sorted CDPs: maintains ICR order
- Hint Helpers → Sorted CDPs: supplies hints
- CDP Manager → Active Pool: accounts collateral
- CDP Manager → Collateral Surplus Pool: routes user surplus
- CDP Manager → eBTC Token: settles debt
- Borrower Operations → Price Feed: checks CDP health
- CDP Manager → Price Feed: prices liquidation / redemption
- Price Feed → Chainlink & fallback oracle: primary / fallback reads
- stETH → Active Pool: collateral held
- Leverage Macro Factory → Smart-wallet Delegate Target: deploys compatible macro
- Smart-wallet Delegate Target → Borrower Operations: composes CDP actions
- Governor → Roles Authority: uses roles
- Governor → Borrower Operations: authorizes privileged actions
- Governor → CDP Manager: controls parameters
- Governor → eBTC Token: controls supply authority
- Governor → Price Feed: configures fallback
- Mainnet Deployment → Borrower Operations: deploys
- Mainnet Deployment → CDP Manager: deploys
- Mainnet Deployment → Governor: configures governance
- Formal Verification → Active Pool: verifies invariants