DEFAULT_ADMIN_ROLE of BribeVault can steal tokens from users’ wallets
The BribeVault contract allows an address with the DEFAULT_ADMIN_ROLE to grant itself the depositor role, then use depositBribeERC20 to pull tokens from any user who has approved the contract, and finally withdraw those tokens via emergencyWithdrawERC20. A malicious or compromised admin could therefore steal all approved tokens up to the allowance limit.
Submitted by WatchPug, also found by danb, Dravee, Alex the Entreprenerd, gzeon, IllIllI, jayjonah8, kenzo, pauliax, cmichel, csanuragjain, and z3s
The current design/implementation allows the DEFAULT_ADMIN_ROLE of BribeVault to steal funds from any address that approved this contract up to allowance:
As a DEFAULT_ADMIN_ROLE, the attack is simply do the following steps:
1. `grantDepositorRole()` to self;
2. `BribeVault#depositBribeERC20()` and transfer funds from victim's wallet;
3. `emergencyWithdrawERC20()`.
This can be effectively used as a backdoor/attack vector for a malicious/compromised wallet with DEFAULT_ADMIN_ROLE of BribeVault to steal all the tokens from users’ wallets for these users who have approved BribeVault.
function depositBribeERC20(
bytes32 bribeIdentifier,
bytes32 rewardIdentifier,
address token,
uint256 amount,
address briber
) external onlyRole(DEPOSITOR_ROLE) {
require(bribeIdentifier.length > 0, "Invalid bribeIdentifier");
require(rewardIdentifier.length > 0, "Invalid rewardIdentifier");
require(token != address(0), "Invalid token");
require(amount > 0, "Amount must be greater than 0");
require(briber != address(0), "Invalid briber");
Bribe storage b = bribes[bribeIdentifier];
address currentToken = b.token;
require(
// If bribers want to bribe with a different token they need a new identifier
currentToken == address(0) || currentToken == token,
"Cannot change token"
);
// Since this method is called by a depositor contract, we must transfer from the account
// that called the depositor contract - amount must be approved beforehand
IERC20(token).safeTransferFrom(briber, address(this), amount);
...
function grantDepositorRole(address depositor)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
require(depositor != address(0), "Invalid depositor");
_grantRole(DEPOSITOR_ROLE, depositor);
emit GrantDepositorRole(depositor);
}
Proof of Concept
Given:
- Alice (the victim) has approved
BribeVaultto spendWBTC; - Alice has
100e8 WBTCin their wallet balance.
A malicious/compromised DEFAULT_ADMIN_ROLE of BribeVault can do the following to steal tokens from users’ wallets.
grantDepositorRole()to self;depositBribeERC20()with:token=WBTC,amount=100e8, andbriber= Alice;emergencyWithdrawERC20()with:token=WBTC,amount=100e8.
As a result, the 100e8 WBTC belongs Alice is now stolen by the Hacker.
The steps above can be repeated for all tokens and users, effectively stealing all the token balances from all the wallets that approved BribeVault up to the allowance limit, which usually is unlimited.
Recommended Mitigation Steps
- Consider using
TokemakBribeinstead ofBribeVaultto hold users’ allowances; - Consider making sure that the
fromparameter oftransferFromcan only bemsg.sender; - Consider using a multi-sig for the
DEFAULT_ADMIN_ROLEofBribeVault.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
Fully agree with the finding and appreciate the level of detail.
Because the exploit is contingent on a malicious owner, I believe Medium Severity to be more appropriate.
Alex the Entreprenerd (judge) commented:
The
emergencyWithdrawERC20without any check is a rug vector, protected exclusively by the multisig. While depositors may opt into this system, that doesn’t mean that it’s trust is fully reliant on the mulsitig, which means the code has trust assumptions by design.These trust assumptions make medium severity 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 lets a depositor specify an arbitrary 'briber' address as the source of transferFrom, and the admin can grant themselves the depositor role and later withdraw the funds.
Impact
A malicious or compromised admin could steal all tokens from users who have approved BribeVault, up to their allowance limits, which are often unlimited.
What the attacker needed
Victim has approved BribeVault to spend tokens; attacker controls DEFAULT_ADMIN_ROLE
The fix
The report recommends using TokemakBribe instead, restricting the 'from' parameter of transferFrom to msg.sender, and using a multi-sig for the DEFAULT_ADMIN_ROLE.
How it was found
- The admin grants themselves the depositor role.
- The admin calls depositBribeERC20 with the victim's address as the briber, pulling the victim's approved tokens into the contract.
- The admin calls emergencyWithdrawERC20 to transfer the tokens out to themselves.
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 can be given permission to spend tokens from your wallet, up to a limit you set (the allowance). This report shows that the contract's admin can abuse that permission to move your tokens to themselves, because the admin can give themselves a special role that lets them trigger transfers from any address that approved the contract.
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.