Skip to content
Access control Audit finding Beginner

MiningService.setBonding should use BONDING role instead of REINVESTOR one

The setBonding function in MiningService used the REINVESTOR_ROLE instead of the BONDING_ROLE when swapping roles, so the bonding role could not be managed after initialisation. An attacker could not directly exploit this, but it meant the intended access control for the bonding role was not enforced.

hyh Follow

Originally disclosed on Code4rena

Submitted by hyh

BONDING_ROLE cannot be managed after it was initialized.

Proof of Concept

setBonding set the wrong role via _swapRole:

https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/MiningService.sol#L116

Recommended Mitigation Steps

Set BONDING_ROLE instead of REINVESTOR_ROLE in setBonding function:

Now:

function setBonding(address _bonding)
  public
  onlyRole(ADMIN_ROLE, "Must have admin privs")
{
  require(_bonding != address(0), "Cannot use address 0");
  _swapRole(_bonding, bonding, REINVESTOR_ROLE);
  bonding = _bonding;
}

To be:

function setBonding(address _bonding)
  public
  onlyRole(ADMIN_ROLE, "Must have admin privs")
{
  require(_bonding != address(0), "Cannot use address 0");
  _swapRole(_bonding, bonding, BONDING_ROLE);
  bonding = _bonding;
}

0xScotch (sponsor) confirmed

The original report as published on Code4rena, by hyh. 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 a copy-paste error: the setBonding function called _swapRole with REINVESTOR_ROLE instead of BONDING_ROLE.

What the attacker needed

Admin privileges required to call setBonding

The fix

The setBonding function should use BONDING_ROLE instead of REINVESTOR_ROLE.

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.

Smart contracts often use roles to control who can do what. This contract has a function to change the bonding address, but it mistakenly gave the new address the wrong role. That meant the correct role for bonding was never updated, so the system could not properly manage who was allowed to bond.

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 hyh

View all

137 more disclosed reports, best first.

More from Malt Protocol - Versus 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.