The buyOutEstateNFT function incorrectly distributes payments when a beneficiary buys out an NFT. Instead of sending each of the other beneficiaries their full share of the NFT's value, it sends a reduced amount, leaving excess funds unallocated in the contract. This results in beneficiaries receiving less than their entitled share and the contract retaining funds that should have been distributed.
The buyOutEstateNFT function calculates the total payment (finalAmount) as (value / N) * (N - 1), where N is the number of beneficiaries (divisor), representing the amount the buyer must pay to compensate the other N - 1 beneficiaries for their shares. However, when distributing this amount, the function sends finalAmount / N to each of the N - 1 other beneficiaries instead of the correct share, value / N. This leads to underpayment per beneficiary and a total distribution less than finalAmount, with the remainder left in the contract.
Vulnerable Code:
Underpayment to Beneficiaries: Each of the N - 1 other beneficiaries receives less than their fair share (value / N), undermining the intended payout mechanism.
Funds Left in Contract: The difference between finalAmount and the total distributed amount remains locked in the contract, inaccessible to beneficiaries.
Potential Disputes: The buyer pays the correct total amount, but the flawed distribution may lead to disagreements or loss of trust among beneficiaries.
Deploy the contract with 3 beneficiaries.
Mint an NFT with value = 90 and assetToPay set to an ERC20 token.
After inheritance is set (isInherited = true), one beneficiary calls buyOutEstateNFT.
The function calculates finalAmount = (90 / 3) * 2 = 60.
It transfers 60 units from the buyer to the contract.
In the loop, it sends 60 / 3 = 20 to each of the 2 other beneficiaries, totaling 40.
The remaining 20 units stay in the contract, and each beneficiary receives 20 instead of the expected 30.
Manual review
Modify the buyOutEstateNFT function to correctly calculate and distribute each beneficiary’s share:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.