Skip to content
Access control Audit finding Intermediate

DEPOSITOR_ROLE can be granted by the deployer of BribeVault and transfer briber’s approved ERC20 tokens to bribeVault by specifying any bribeIdentifier and rewardIdentifier

The BribeVault contract lets any address holding DEPOSITOR_ROLE pull an approved ERC20 amount from a briber using arbitrary bribe and reward identifiers. A malicious or compromised depositor could therefore move a user's approved tokens into the vault, and the admin role could later withdraw them.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

In the depositBribeERC20() function of the TokemakBribe contract, the briber can specify a proposal, and then call the depositBribeERC20 function of the bribeVault contract to deposit the reward.

    function depositBribeERC20(
        address proposal,
        address token,
        uint256 amount
    ) external {
        uint256 currentRound = _round;
        require(
            proposalDeadlines[proposal] > block.timestamp,
            "Proposal deadline has passed"
        );
        require(token != address(0), "Invalid token");
        require(amount > 0, "Bribe amount must be greater than 0");

        bytes32 bribeIdentifier = generateBribeVaultIdentifier(
            proposal,
            currentRound,
            token
        );
        bytes32 rewardIdentifier = generateRewardIdentifier(
            currentRound,
            token
        );

        IBribeVault(bribeVault).depositBribeERC20(
            bribeIdentifier,
            rewardIdentifier,
            token,
            amount,
            msg.sender
        );

But in the depositBribeERC20 function of the bribeVault contract, the address with DEPOSITOR_ROLE can transfer the briber’s approved ERC20 tokens to bribeVault by specifying any bribeIdentifier and rewardIdentifier via safeTransferFrom.

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

DEPOSITOR_ROLE can be granted by the deployer of BribeVault.

    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

BribeVault.sol#L164-L205

Recommended Mitigation Steps

The depositBribeERC20 function of the TokemakBribe contract needs to first transfer the briber’s tokens to the TokemakBribe contract, and then transfer the tokens to the bribeVault contract in the depositBribeERC20 function of the bribeVault contract. Make sure the first parameter of safeTransferFrom is msg.sender.

TokemakBribe.depositBribeERC20()

    function depositBribeERC20(
        address proposal,
        address token,
        uint256 amount
    ) external {
        uint256 currentRound = _round;
        require(
            proposalDeadlines[proposal] > block.timestamp,
            "Proposal deadline has passed"
        );
        require(token != address(0), "Invalid token");
        require(amount > 0, "Bribe amount must be greater than 0");

        bytes32 bribeIdentifier = generateBribeVaultIdentifier(
            proposal,
            currentRound,
            token
        );
        bytes32 rewardIdentifier = generateRewardIdentifier(
            currentRound,
            token
        );
+       IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

        IBribeVault(bribeVault).depositBribeERC20(
            bribeIdentifier,
            rewardIdentifier,
            token,
            amount,
            msg.sender
        );

bribeVault.depositBribeERC20()

    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);
+	IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

kphed (Redacted Cartel) disputed and commented:

This isn’t a concern since the “depositor” role can only be granted by admin (protocol multisig) - depositors will only be bribe contracts that we’ve written and deployed.

In the future, we may grant the depositor role to contracts that are written and deployed by 3rd parties, but they would all be thoroughly vetted in some manner and need to conform to the BribeVault’s interface.

Thanks again for participating in our contest cccz, looking forward to more feedback/suggestions/comments.

Alex the Entreprenerd (judge) commented:

While this may not be a concern for the sponsor, the smart contract is supposed to be given allowance, this allowance can then be used by the DEPOSITOR_ROLE to perform a transfer.

The smart can then allow the DEFAULT_ADMIN_ROLE to withdraw the funds.

Ultimately the ability to deposit being permissioned and it’s ability to pull unlimited funds is a strong admin privilege, which I’d recommend the sponsor to remove.

A similar deposit flow with less strict permissions can be found in most Yield Farming Vaults, see Badger Vaults for example: Badger-Finance/Vault.sol#L671.


The original report as published on Code4rena, by cccz. 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 vault pulls tokens from the briber address supplied by the caller instead of from the calling depositor contract, so the depositor role controls whose allowance is spent.

Impact

A depositor-role address could move a briber's approved tokens into the vault, where the admin role could withdraw them; the sponsor argued the role is only given to vetted contracts, so the practical risk is limited.

What the attacker needed

Briber approves the vault for tokens; attacker holds DEPOSITOR_ROLE

The fix

The depositor contract should first pull the tokens from the briber into itself, and the vault should then transfer from the calling depositor (msg.sender) rather than from the briber address.

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 briber approves the vault to spend their tokens, which is like signing a cheque that the vault can fill in later. The deposit function trusts whoever holds a special depositor role to decide how much to take and from whom, so that role can take the approved tokens without the briber's fresh consent. The project said only its own vetted contracts get that role, so the risk depends on who holds it.

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 cccz

View all

104 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.