Despite the presence of security libraries like SafeERC20 and ReentrancyGuardUpgradeable, the protocol remains vulnerable to a sophisticated attack chain. This attack exploits the tx.origin authentication bypass in the setPerpVault function combined with precision vulnerabilities in share calculations to systematically drain user funds. The attack begins with a phishing-enabled administrative compromise and uses mathematical manipulation to extract value, bypassing some but not all of the protections provided by the imported libraries.
tx.origin Authentication Bypass in setPerpVault: Despite using Ownable2StepUpgradeable, the function mistakenly uses tx.origin for authentication, creating a fundamental entry point for attackers.
Precision Loss in Share Calculations: The _withdraw function performs division operations before multiplication in critical calculations, leading to significant precision loss that can be exploited even when using SafeERC20.
Unchecked Token Transfer Return Values: While SafeERC20 is imported, not all token transfer operations use the library's safe functions consistently, leaving some transfers vulnerable to silent failures.
Rounding Errors in _handleReturn: The function performs division operations with potential precision loss, creating opportunities for value extraction even with reentrancy protection in place.
Inconsistent Usage of SafeERC20: Although the library is imported, some transfer operations may bypass the safe wrappers, creating inconsistencies that can be exploited.
The attack progresses through several sophisticated stages:
Initial Compromise: The attacker creates a phishing contract and tricks an admin into interacting with it. When the admin calls a function on this malicious contract, it calls setPerpVault on the actual protocol. Since authentication uses tx.origin (the admin's address) rather than msg.sender (the malicious contract), the check passes and the attacker gains control of the vault parameter.
Malicious Vault Deployment: The attacker deploys a counterfeit vault contract that mimics the interface of the legitimate vault but contains manipulated math that exploits precision vulnerabilities.
Precision Exploitation: With the vault under their control, the attacker executes precisely calculated deposits and withdrawals. Each operation is designed to create favorable rounding errors in share calculations. Since share-to-asset conversions involve division operations, each transaction causes small amounts of value to accumulate in the manipulated vault.
Value Extraction: The attacker repeats this process multiple times, gradually extracting value from the precision errors. Even though ReentrancyGuardUpgradeable prevents reentrancy attacks, it cannot prevent the mathematical extraction that happens across separate legitimate transactions.
Final Theft: Once sufficient value has accumulated through these precision errors, the attacker withdraws the stolen funds from their malicious vault.
The attack is particularly insidious because it operates within the apparent boundaries of normal protocol operations. Each individual transaction appears legitimate, but the cumulative effect of precision manipulation leads to substantial theft.
Complete administrative compromise of the vault system
Systematic extraction of user funds through precision manipulation
Potential drain of significant protocol value over time
Financial losses affecting all users with deposits
Undermining of user trust in the protocol
Long-term protocol insolvency if the attack continues undetected
PoC:
Manual code analysis
Solidity security pattern verification
Mathematical precision vulnerability analysis
Access control validation testing
Replace tx.origin with msg.sender for all authentication checks:
Ensure all mathematical operations preserve precision by performing multiplication before division:
Verify that SafeERC20 is consistently used for all token operations:
Implement minimum threshold checks to prevent precision attacks with small amounts:
Use consistent rounding policies that favor the protocol's security:
Enhance access control with additional checks and time-locks for critical operations:
Add extensive validation of vault addresses before setting them:
Add comprehensive event logging and monitoring system:
Lightchaser: Medium-5
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.