Skip to content
Access control Audit finding Intermediate

Access restrictions on CompoundToNotionalV2.notionalCallback can be bypassed

The notionalCallback function in CompoundToNotionalV2 only checks that the sender parameter equals the contract's own address, but an attacker can pass sender = this to bypass this check. An attacker can then call the function with a victim's account, causing the victim's approved tokens to be transferred to the contract and stuck, effectively burning them.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The CompoundToNotionalV2.notionalCallback is supposed to only be called from the verified contract that calls this callback. But, the access restrictions can be circumvented by simply providing sender = this, as sender is a parameter of the function that can be chosen by the attacker.

function notionalCallback(
    address sender,
    address account,
    bytes calldata callbackData
) external returns (uint256) {
// @audit sender can be passed in by the attacker
require(sender == address(this), "Unauthorized callback");

An attacker can call the function passing in an arbitrary account whose tokens are then transferred to the contract. The account first has to approve this contract but this can happen with accounts that legitimately want to call the outer function and have to send a first transaction to approve the contract, but then an attacker front-runs the actual transaction.

It’s at least a griefing attack: I can pass in a malicious cTokenBorrow that returns any token of my choice (through the .underlying() call) but whose repayBorrowBehalf is a no-op.

This will lead to any of the victim’s approved tokens becoming stuck in the contract, essentially burning them:

// @audit using a malicious contract, this can be any token
address underlyingToken = CTokenInterface(cTokenBorrow).underlying();
bool success = IERC20(underlyingToken).transferFrom(account, address(this), cTokenRepayAmount);
require(success, "Transfer of repayment failed");

// Use the amount transferred to repay the borrow
// @audit using a malicious contract, this can be a no-op
uint code = CErc20Interface(cTokenBorrow).repayBorrowBehalf(account, cTokenRepayAmount);

Note that the assumption at the end of the function ”// When this exits a free collateral check will be triggered” is not correct anymore but I couldn’t find a way to make use of it to lead to an invalid account state.

Recommend fixing the authorization check.

jeffywu (Notional) confirmed

The original report as published on Code4rena, by cmichel. 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

The authorization check relies on a user-supplied parameter (sender) instead of verifying the actual caller (msg.sender).

Impact

The attacker can cause any of the victim's approved tokens to become stuck in the contract, effectively burning them; this is at least a griefing attack.

What the attacker needed

Victim has approved the contract to spend tokens; attacker can front-run the victim's transaction

The fix

The authorization check should be fixed to verify the actual caller (msg.sender) instead of a user-supplied parameter.

How it was found

  1. Victim approves the contract to spend their tokens as part of a legitimate interaction.
  2. Attacker front-runs the victim's actual transaction.
  3. Attacker calls notionalCallback with sender set to the contract's address and account set to the victim's address.
  4. Attacker provides a malicious cTokenBorrow contract that returns a token of choice and whose repayBorrowBehalf does nothing.
  5. The contract transfers the victim's approved tokens to itself and the repayBorrowBehalf call does nothing, leaving the tokens stuck.

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.

This contract has a function that is supposed to be callable only by the contract itself. But the check uses a value that the caller provides, so anyone can pretend to be the contract. An attacker can then use this to take tokens that a victim has approved for the contract and lock them forever.

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 cmichel

View all

196 more disclosed reports, best first.

More from Notional 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.