
On April 19, Hedgey Finance experienced a devastating exploit that reverberated across both the Ethereum Mainnet and the Arbitrum network. The exploit resulted in staggering losses, totaling approximately $44.7 million.
Background
The exploit unfolded through a series of transactions, culminating in a loss of $2.1 million on the Ethereum Mainnet and $42.6 million worth of assets on the Arbitrum network.
Root Cause of hack
1) The exploit's root cause lay in a vulnerability: the absence of input validation on users' parameters, enabling unauthorized token approvals.
2) The attacker initiated the exploit by executing a $1.3 million USDC flash loan from Balancer.
3) Exploiting the vulnerable contract's createLockedCampaign function, the attacker manipulated the claimLockup parameter to gain approval for USDC token transfers to their address.
```
function createLockedCampaign(bytes16 id, Campaign memory campaign, ClaimLockup memory claimLockup, Donation memory donation) external nonReentrant {
require(!usedIds[id], "in use");
usedIds[id] = true;
require(campaign.token != address(0), "0_address");
require(campaign.manager != address(0), "0_manager");
require(campaign.amount > 0, "0_amount");
require(campaign.end > block.timestamp, "end error");
require(campaign.tokenLockup != TokenLockup.Unlocked, "!locked");
require(claimLockup.tokenLocker != address(0), "invalide locker");
TransferHelper.transferTokens(campaign.token, msg.sender, address(this), campaign.amount + donation.amount);
if (donation.amount > 0) {
if (donation.start > 0) {
SafeERC20.safeIncreaseAllowance(IERC20(campaign.token), donation.tokenLocker, donation.amount);
ILockupPlans(donation.tokenLocker).createPlan(donationCollector, campaign.token, donation.amount, donation.start, donation.cliff, donation.rate, donation.period);
} else {
TransferHelper.withdrawTokens(campaign.token, donationCollector, donation.amount);
}
emit TokensDonated(id, donationCollector, campaign.token, donation.amount, donation.tokenLocker);
}
claimLockups[id] = claimLockup;
SafeERC20.safeIncreaseAllowance(IERC20(campaign.token), claimLockup.tokenLocker, campaign.amount);
campaigns[id] = campaign;
emit ClaimLockupCreated(id, claimLockup);
emit CampaignStarted(id, campaign);
}4) Subsequently, the attacker nullified the campaign using the cancelCampaign function, enabling them to reclaim the approved and unclaimed assets.
function cancelCampaign(bytes16 campaignId) external nonReentrant {
Campaign memory campaign = campaigns[campaignId];
require(campaign.manager == msg.sender, "!manager");
delete campaigns[campaignId];
delete claimLockups[campaignId];
TransferHelper.withdrawTokens(campaign.token, msg.sender, campaign.amount);
emit CampaignCancelled(campaignId);
}
5) The attacker executed yet another transaction, likely to avoid being front-run by bots, to leverage the USDC approvals to transfer the approved tokens from the victim contract to themselves.
6) The attacker executed additional transactions, possibly to circumvent detection by bots, utilizing the USDC approvals to transfer tokens from the victim contract to their own address.
Result
The consequences of the exploit were severe. The victim contract on the Ethereum Mainnet suffered substantial asset depletion, including losses of USDC, NOBL, and MASA tokens. To obscure their tracks, the attacker converted all stolen funds to DAI before transferring them to an externally owned account (EOA).
At the time of writing, the EOA holds approximately $2,173,325 worth of assets, representing a fraction of the total losses incurred.
Lessons Learned
The Hedgey Finance exploit serves as a stark reminder of the critical importance of robust security measures in decentralized finance (DeFi) protocols.
- Input validation and parameter verification are fundamental safeguards against exploitation.
- Comprehensive auditing and continuous monitoring are essential to detect and mitigate vulnerabilities before they can be exploited.
- The speed and scale of DeFi transactions necessitate heightened vigilance and proactive risk management strategies.
Read more about OpenLeverage $236K Exploit
Author : Piyush shukla