Depositor can spend funds of another Depositor
The depositBribeERC20 function in BribeVault.sol allows a depositor to specify an arbitrary briber address, so a malicious depositor could transfer another user's approved tokens without their knowledge. The function also lacks checks for expired proposals and allows mismatched reward and bribe identifiers, leading to incorrect state updates.
Originally disclosed on Code4rena
Submitted by csanuragjain
- One depositor can spend funds of another depositor
- Depositor can deposit in expired proposal
- rewardIdentifier and bribeIdentifier can point to different rounds/tokens
Proof of Concept
One depositor can spend funds of another depositor:
- Malicious depositor can call depositBribeERC20 at BribeVault.sol#L164 with briber as User B (Malicious user can generate bribeIdentifier with his own proposal)
- Assume this User B has approved amount x to this contract
- BribeVault.sol#L187 (IERC20(token).safeTransferFrom(briber, address(this), amount);) will transfer this amount x to the contract due to call at step 1. All this happen without User B knowledge
Expired Proposal:
- Malicious depositor can generate bribeIdentifier of an expired proposal (proposalDeadlines[proposal] < block.timestamp) using generateBribeVaultIdentifier at TokemakBribe.sol#L166
- Malicious depositor can then simply call depositBribeERC20 at BribeVault.sol#L164
- Since there is no deadline check and this function blindly trusts bribeIdentifier, user deposit will be success even though the associated proposal already expired
RewardIdentifier and bribeIdentifier can point to different rounds/tokens:
- Similar to expired proposal, depositor can generate bribeIdentifier and RewardIdentifier with different tokens and rounds.
- Depositor now calls epositBribeERC20 at BribeVault.sol#L164 with the generated bribeIdentifier and RewardIdentifier
- rewardToBribes[rewardIdentifier].push(bribeIdentifier); will update reward for round x and bribeIdentifier will point to round y which is incorrect
Recommended Mitigation Steps
depositBribeERC20 at BribeVault.sol#L164 should only be allowed to be called via TokemakBribe.sol
kphed (Redacted Cartel) disputed and commented:
depositBribeERC20 at BribeVault.sol#L164 should only be allowed to be called via TokemakBribe.sol
Only those with the “depositor” role can call the deposit bribe methods (
depositBribeERC20anddepositBribe). We only grant the role to bribe contracts we own such as TokemakBribe.sol.Thanks again for participating in our contest csanuragjain, looking forward to more feedback/suggestions/comments.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
While the finding is similar to M-02, I believe this more eloquently shows the specific types of admin privileges that the
DEPOSITOR_ROLEhas for the functiondepositBribeERC20.Ultimately the finding is highlighting how things can go wrong and how the
DEPOSITOR_ROLEprovides a high level of admin privilege.Because this is contingent on a malicious admin, I believe Medium Severity to be more appropriate.
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
Likely the depositBribeERC20 function trusts the caller-supplied briber address and bribeIdentifier without validating that the caller is authorised for that briber or that the proposal is active and matches the rewardIdentifier.
Impact
A malicious depositor could spend another user's approved funds and create incorrect reward-to-bribe mappings, but the project disputed this because only trusted bribe contracts are granted the depositor role.
What the attacker needed
The attacker has the depositor role; the victim has approved tokens to the contract
The fix
The function should only be callable by trusted bribe contracts, as the project states it already restricts the depositor role to such contracts.
How it was found
- A malicious depositor calls depositBribeERC20 with the briber set to another user's address.
- The other user has already approved the contract to spend some amount of tokens.
- The contract transfers that amount from the other user to itself without their knowledge.
- The depositor can also generate a bribeIdentifier for an expired proposal and call depositBribeERC20, which succeeds because there is no deadline check.
- The depositor can generate a bribeIdentifier and rewardIdentifier pointing to different rounds or tokens and call depositBribeERC20, causing rewardToBribes to be updated incorrectly.
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 depositor is someone allowed to add funds to a contract. The contract lets them say who the money comes from, so a bad depositor could take money from someone else who had approved the contract. The contract also doesn't check if a proposal is still active or if the reward and bribe identifiers match.
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.