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.
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
- Alice calls
_setAccountantContract()with parameter input as 0. - The
_accountantstate variable is now 0. - Alice/or a contract calls
mintFresh()with input address 0 and mintAmount 1000. (assuming function is external, reporting a separate issue on the mutability) - This passes the
if (minter == address(_accountant))and proceeds to mint 1000 CTokens to address(0) - Alice then calls
redeemFresh()with her address as theredeemerparameter, and redeemTokensIn as 1000. - 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
- Alice calls
borrowFresh()to borrow 500 CTokens from contract. - Then Alice calls
_setAccountantContract()with parameter input as 0. - The
_accountantstate variable is now 0. - With
_accountantbeing set to 0, Alice callsrepayBorrowFresh()having the payer be address 0, borrower being her address and 500 as repayAmount. - 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");
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has shown how, due to a misconfiguration, if the
accountantis 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.
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
- Call the accountant setter with the zero address as the new accountant.
- Call the mint function with the zero address as the minter and a chosen amount.
- 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.