Skip to content
Access control Audit finding Intermediate

lending-market/Note.sol Wrong implementation of access control

The Note contract's access control for minting tokens is flawed: the first caller of _mint_to_Accountant becomes the accountant and can mint the maximum token supply to themselves. An attacker could front-run the legitimate setup to take control and mint all tokens.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by catchup, Lambda, p4st13r4, and Tutturu

https://github.com/Plex-Engineer/lending-market/blob/b93e2867a64b420ce6ce317f01c7834a7b6b17ca/contracts/Note.sol#L13-L31

function _mint_to_Accountant(address accountantDelegator) external {
    if (accountant == address(0)) {
        _setAccountantAddress(msg.sender);
    }
    require(msg.sender == accountant, "Note::_mint_to_Accountant: ");
    _mint(msg.sender, type(uint).max);
}

function RetAccountant() public view returns(address) {
    return accountant;
}

function _setAccountantAddress(address accountant_) internal {
    if(accountant != address(0)) {
        require(msg.sender == admin, "Note::_setAccountantAddress: Only admin may call this function");
    }
    accountant = accountant_;
    admin = accountant;
}

_mint_to_Accountant() calls _setAccountantAddress() when accountant == address(0), which will always be the case when _mint_to_Accountant() is called for the first time.

And _setAccountantAddress() only checks if msg.sender == admin when accountant != address(0) which will always be false, therefore the access control is not working.

L17 will then check if msg.sender == accountant, now it will always be the case, because at L29, accountant was set to msg.sender.

tkkwon1998 (Canto) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how, due to a flaw in logic, via a front-run, anyone can become the accountant and mint all the totalSupply to themselves.

While I’m not super confident on severity for the front-run as I’d argue the worst case is forcing a re-deploy, the warden has shown a lack of logic in the checks (msg.sender == admin) which breaks it’s invariants.

For that reason, I think High Severity to be 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 access control check in _setAccountantAddress is only enforced when accountant is already set, so the first caller bypasses it and becomes the accountant.

Impact

An attacker could become the accountant and mint the maximum token supply to themselves, potentially forcing a redeploy; the judge noted the worst case may be a redeploy.

What the attacker needed

Attacker can call the contract before setup; no initial accountant set

The fix

The access control should be enforced regardless of whether accountant is already set, for example by always requiring msg.sender == admin in _setAccountantAddress.

How it was found

  1. Call _mint_to_Accountant before the legitimate accountant is set.
  2. The function sets the caller as the accountant because accountant is zero.
  3. The require check passes because msg.sender equals the newly set accountant.
  4. The function mints the maximum uint value to the caller.

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 smart contract lets a special account (the 'accountant') create new tokens. But the check that ensures only the admin can set the accountant is skipped the first time, so anyone can call the function first and become the accountant. Then they can create an unlimited number of tokens for themselves.

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