A critical bug exists in the buyOutEstateNFT function of the InheritanceManager contract. The function incorrectly distributes funds to beneficiaries, resulting in significant portions of tokens becoming permanently locked in the contract. This implementation error leads to direct financial loss for beneficiaries and creates an imbalance in the inheritance system.
The buyOutEstateNFT function contains a flawed distribution mechanism that incorrectly calculates the amount each beneficiary should receive. After transferring the full finalAmount to the contract, the function then distributes finalAmount / divisor to each beneficiary (except the buyer). This results in:
Double division of the original payment amount
Incorrect distribution of funds
A substantial portion of tokens becoming permanently locked in the contract
The vulnerable code:
The key issue is that after calculating finalAmount, the function further divides this amount by divisor when distributing to each beneficiary, essentially applying division twice to the original value.
This vulnerability has severe financial implications:
Permanent Fund Lock: Significant portions of tokens become permanently stranded in the contract with no recovery mechanism.
Beneficiary Loss: Beneficiaries receive much less than their intended share of the inheritance.
Protocol Imbalance: The locked funds create an economic imbalance in the protocol.
Scaling Issue: The problem worsens as the number of beneficiaries increases.
Consider an estate NFT worth 3,000,000 tokens with 2 beneficiaries:
value = 3,000,000
divisor = 2 (beneficiaries)
multiplier = 1 (beneficiaries.length - 1)
finalAmount = (3,000,000 / 2) * 1 = 1,500,000
The buyer transfers 1,500,000 tokens to the contract. Then in the distribution loop:
Each beneficiary (excluding the buyer) receives: finalAmount / divisor = 1,500,000 / 2 = 750,000
With 1 non-buyer beneficiary, 750,000 tokens are distributed
Result: 750,000 tokens (50% of the payment) remain locked in the contract permanently
The following test output confirms this vulnerability:
With more beneficiaries, the problem compounds:
For 5 beneficiaries and a 1,000,000 token NFT:
finalAmount = (1,000,000 / 5) * 4 = 800,000
Each non-buyer receives: 800,000 / 5 = 160,000
Total distributed: 160,000 * 4 = 640,000
Locked funds: 800,000 - 640,000 = 160,000 (20% of payment)
Alternatively, a simpler solution if the compensation should be equal among non-buying beneficiaries:
Manual review
foundry test setup
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.