Swap functionality to sell rewards is too permissive and could cause accidental or intentional loss of value
The applyRewards function allows the rewarder to approve any token to any spender and execute arbitrary calls, rather than restricting swaps to the 0x protocol. This gives the rewarder excessive power that could be used accidentally or intentionally to harm the protocol.
Submitted by adriro, also found by d3e4
While the intention is to use the 0x protocol to sell rewards, the implementation doesn’t provide any basic guarantee this will correctly happen and grants the rewarder arbitrary control over the tokens held by the strategy.
Impact
Rewards earned in the VotingStrategy contract are exchanged for ETH and deposited back into the protocol. As indicated by the documentation, the intention is to swap these rewards for ETH using the 0x protocol:
Votium rewards are claimed with claimRewards() using merkle proofs published by votium every 2 weeks. applyRewards() sells rewards on 0x and deposits them back into afEth (and ultimately back into the safEth & votium strategies), making the afEth price go up.
However, the implementation of applyRewards() shallowly executes a series of calls to arbitrary targets:
272: function applyRewards(SwapData[] calldata _swapsData) public onlyRewarder {
273: uint256 ethBalanceBefore = address(this).balance;
274: for (uint256 i = 0; i < _swapsData.length; i++) {
275: // Some tokens do not allow approval if allowance already exists
276: uint256 allowance = IERC20(_swapsData[i].sellToken).allowance(
277: address(this),
278: address(_swapsData[i].spender)
279: );
280: if (allowance != type(uint256).max) {
281: if (allowance > 0) {
282: IERC20(_swapsData[i].sellToken).approve(
283: address(_swapsData[i].spender),
284: 0
285: );
286: }
287: IERC20(_swapsData[i].sellToken).approve(
288: address(_swapsData[i].spender),
289: type(uint256).max
290: );
291: }
292: (bool success, ) = _swapsData[i].swapTarget.call(
293: _swapsData[i].swapCallData
294: );
295: if (!success) {
296: emit FailedToSell(_swapsData[i].sellToken);
297: }
298: }
299: uint256 ethBalanceAfter = address(this).balance;
300: uint256 ethReceived = ethBalanceAfter - ethBalanceBefore;
301:
302: if (address(manager) != address(0))
303: IAfEth(manager).depositRewards{value: ethReceived}(ethReceived);
304: else depositRewards(ethReceived);
305: }
This not only fails to provide any guarantee that 0x will be used (and that it will be used correctly), but grants a lot of power to the rewarder which can be used accidentally or purposely to negatively impact the protocol. The rewarded role can grant any token approval to any spender and execute arbitrary calls on behalf of the VotingStrategy.
Recommendation
Provide better guarantees in the implementation of applyRewards() that 0x will be used to swap rewards, to ensure a more transparent and less error prone solution.
- Instead of granting arbitrary allowance to any spender, set this to the 0x entrypoint.
- Change arbitrary calls to the 0x protocol entrypoint.
- Data sent to the 0x contract could also be validated, for example to ensure the output token is ETH.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The applyRewards function does not restrict the spender or call target to the 0x protocol, allowing arbitrary approvals and calls.
Impact
The rewarder could accidentally or intentionally cause loss of value by approving tokens to a malicious spender or calling a malicious contract.
What the attacker needed
Rewarder role is compromised or malicious
The fix
The implementation should be changed to only approve the 0x entrypoint and only call the 0x protocol, optionally validating that the output token is ETH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract function lets a privileged role (the rewarder) approve any token to any address and make any call. This is like giving someone a blank cheque: they could accidentally or deliberately send tokens to the wrong place or approve a malicious contract. The report suggests limiting these actions to only the intended 0x exchange.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.