Skip to content
Access control Audit finding Intermediate

accountant address can be set to zero by anyone leading to loss of funds/tokens

The access check in the function that sets the accountant contract only runs when the new accountant is not the zero address, so anyone can set the accountant to zero. This lets users mint or repay tokens for free and causes the accounting contract to lose funds.

cryptphi Follow

Originally disclosed on Code4rena

Submitted by cryptphi

https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L14-L21 https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L31 https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L96 https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L178 https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L258

In CNote._setAccountantContract(), the require() check only works when address(_accountant) != address(0) , leading to the ability to set _accountant state variable to the zero address, as well as setting admin to zero address.

The following below are impacts arising from above:

A. Users can gain underlying asset tokens for free by minting CToken in mintFresh() then calling redeemFresh()

Proof of Concept

  1. Alice calls _setAccountantContract() with parameter input as 0.
  2. The _accountant state variable is now 0.
  3. Alice/or a contract calls mintFresh() with input address 0 and mintAmount 1000. (assuming function is external, reporting a separate issue on the mutability)
  4. This passes the if (minter == address(_accountant)) and proceeds to mint 1000 CTokens to address(0)
  5. Alice then calls redeemFresh() with her address as the redeemer parameter, and redeemTokensIn as 1000.
  6. Assume exchangeRate is 1, Alice would receive 1000 tokens in underlying asset.

B. Users could borrow CToken asset for free

A user can borrow CToken asset from the contract, then set _accountant to 0 after. With _accountant being set to 0 , the borrower , then call repayBorrowFresh() to have _accountant (address 0) to repay back the borrowed tokens assuming address(0) already has some tokens, and user’s borrowed asset (all/part) are repaid.

Proof of Concept

  1. Alice calls borrowFresh() to borrow 500 CTokens from contract.
  2. Then Alice calls _setAccountantContract() with parameter input as 0.
  3. The _accountant state variable is now 0.
  4. With _accountant being set to 0, Alice calls repayBorrowFresh() having the payer be address 0, borrower being her address and 500 as repayAmount.
  5. Assume address 0 already holds 1000 CTokens, Alice’s debt will be fully repaid and she’ll gain 500 CTokens for free.

C. Accounting contract could loses funds/tokens

When the _accountant is set to 0, CTokens/CNote will be sent to the zero address making the Accounting contract lose funds whenever doTransferOut is called.

Recommended Mitigation Steps

Instead of a if (address(_accountant) != address(0)) statement, an additional require check to ensure accountant_ parameter is not 0 address can be used in addition to the require check for caller is admin.

Change this

if (address(_accountant) != address(0)){
            require(msg.sender == admin, "CNote::_setAccountantContract:Only admin may call this function");
        }

to this

require(msg.sender == admin, "CNote::_setAccountantContract:Only admin may call this function");
require(accountant_ != address(0), "accoutant can't be zero address");

tkkwon1998 (Canto) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has shown how, due to a misconfiguration, if the accountant is set to 0, users will be able to extra additional value (repay tokens for free).

Because this is contingent on a misconfiguration, I believe Medium Severity to be more appropriate.


The original report as published on Code4rena, by cryptphi. 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 admin-only require check is nested inside a condition that is false when the new accountant is the zero address, so the zero-address case skips authorisation entirely.

Impact

Users could obtain underlying tokens for free by minting and redeeming, borrow without repaying, and the accounting contract could lose funds sent to the zero address.

What the attacker needed

None

The fix

The function should always require that the caller is the admin and should also reject a zero-address accountant.

How it was found

  1. Call the accountant setter with the zero address as the new accountant.
  2. Call the mint function with the zero address as the minter and a chosen amount.
  3. Call the redeem function as yourself for the same amount to receive underlying tokens.

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 has a special helper address called the accountant. The code that changes this helper only checks that the caller is an admin if the new helper is not the zero address. Because of that, anyone can change the helper to the zero address, which is a placeholder that holds no real owner. Once it is zero, the contract's normal safety checks can be bypassed, letting people get tokens without paying.

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 cryptphi

View all

7 more disclosed reports, best first.

More from Canto

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.