Description:
The function InheritanceManager::buyOutEstateNFT() is responsible for allowing a beneficiary to buy out a Real Estate NFT by paying its total value, which is then distributed among the other beneficiaries. However, there is a miscalculation in the way funds are distributed:
The function incorrectly uses finalAmount / divisor to determine the share for each beneficiary. Instead, it should use beneficiaries.length - 1, because the buyer is not supposed to receive a share. This results in an underpayment to each beneficiary.
Impact:
The impact overall is High beacuse afect the lost of funds for the Beneficiaries and at the same time the likelihood of the vulnerability is High as it will always happen.
Proof of Concept:
Example:
NFT Value: $100
Number of Beneficiaries: 4
Expected Share per Beneficiary: $100 / 4 = $25 each
Current Incorrect Calculation: $100 / 4 × 3 = $75 (distributed among 3)
Actual Amount Received per Beneficiary: $75 / 4 = $18.75
This breaks the protocol's invariant that each non-buying beneficiary must receive an equal and fair share.
```javascript
function test_audit_Return_added_to_loop() public {
vm.deal(address(im), 10e18);
vm.startPrank(owner);
string memory _description = "pepe";
uint256 _value = 1000000;
address _asset = address(usdc);
im.createEstateNFT(_description, _value, _asset);
uint256 valueOfNft = im.getNftValue(1);
console.log(valueOfNft);
console.log(nft.ownerOf(1));
im.addBeneficiery(address(user1));
im.addBeneficiery(address(user2));
im.addBeneficiery(address(user3));
im.addBeneficiery(address(user4));
uint256 deadLine2 = im.getDeadline();
console.log(deadLine2);
vm.warp(deadLine2 + 90 days);
vm.stopPrank();
vm.startPrank(user4);
im.inherit();
im.withdrawInheritedFunds(address(0));
usdc.mint(address(user4), 10e6);
usdc.approve(address(im), type(uint256).max);
im.buyOutEstateNFT(1);
vm.stopPrank();
}
```
Recommended Mitigation:
To mitigate this calculation error, just divide by beneficiaries.length - 1 and the distribution will be right
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.