User loses collateral converted to pendingBalance when cash() or list() is called
Submitted by Trust, also found by Lambda
Description
In OptimisticListingOpensea, there are several functions which update pendingBalances of a proposer:
list()cash()propose()
Unfortunately, in list() and cash() the = operator is used instead of += when writing the new pendingBalances. For example:
function cash(address _vault, bytes32[] calldata _burnProof) external {
// Reverts if vault is not registered
(address token, uint256 id) = _verifyVault(_vault);
// Reverts if active listing has not been settled
Listing storage activeListing = activeListings[_vault];
// Reverts if listing has not been sold
if (!_verifySale(_vault)) {
revert NotSold();
} else if (activeListing.collateral != 0) {
uint256 collateral = activeListing.collateral;
activeListing.collateral = 0;
// Sets collateral amount to pending balances for withdrawal
pendingBalances[_vault][activeListing.proposer] = collateral;
}
...
pendingBalances is not guaranteed to be zero. There could be funds from previous proposals which are not yet collected. Propose updates pendingBalance correctly:
// Sets collateral amount to pending balances for withdrawal
pendingBalances[_vault][proposedListing.proposer] += proposedListing.collateral;
So, when propose is followed by another propose(), the pendingBalance is updated correctly, but in cash and list we don’t account for pre-existing balance. This issue would manifest even after the fix suggested in the issue “User can send a proposal and instantly take back their collateral” because reject functions would increment the pendingBalance and then it would be overriden.
Impact
User loses collateral converted to pendingBalance when cash() or list() is called.
Proof of Concept
- User calls
propose()and gets pendingBalance = x - User calls
propose()with an improved proposal and gets pendingBalance = 1.5x - proposal is successfull and the listing purchased the NFT
cash()is called to convert the Raes to ETH amount from the sell. pendingBalance is overridden by the current “collateral” value. pendingBalance = 0.5x- User loses x collateral value which is stuck in the contract
Recommended Mitigation Steps
Change the = operator to += in list() and cash().
mehtaculous (Tessera) confirmed and commented:
Agree with High severity. Solution is to replace
=with+=for bothlistandcashfunctions.
stevennevins (Tessera) mitigated:
https://github.com/fractional-company/modular-fractional/pull/202
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in Tessera - Versus contest. Code4rena made it public on 18 April 2023. Found in the 2022-12-tessera audit contest (finding H-07), also found by 1 other warden.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.