Skip to content
Access control Audit finding Intermediate

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.

WatchPug Follow

Originally disclosed on Code4rena

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.

BribeVault.sol#L164-L187

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);
    ...

BribeVault.sol#L80-L88

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 BribeVault to spend WBTC;
  • Alice has 100e8 WBTC in their wallet balance.

A malicious/compromised DEFAULT_ADMIN_ROLE of BribeVault can do the following to steal tokens from users’ wallets.

  1. grantDepositorRole() to self;
  2. depositBribeERC20() with: token = WBTC, amount = 100e8, and briber = Alice;
  3. 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

  1. Consider using TokemakBribe instead of BribeVault to hold users’ allowances;
  2. Consider making sure that the from parameter of transferFrom can only be msg.sender;
  3. Consider using a multi-sig for the DEFAULT_ADMIN_ROLE of BribeVault.

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 emergencyWithdrawERC20 without 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.


The original report as published on Code4rena, by WatchPug. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. The admin grants themselves the depositor role.
  2. The admin calls depositBribeERC20 with the victim's address as the briber, pulling the victim's approved tokens into the contract.
  3. 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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Redacted Cartel contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.