A bug exists in the buyOutEstateNFT function of the InheritanceManager contract. The function performs integer division before multiplication when calculating payment amounts, resulting in precision loss due to truncation. This allows users to purchase estate NFTs at lower prices than intended, causing financial loss to the protocol and beneficiaries.
In Solidity, when performing integer division, any fractional results are truncated (rounded down). If division is performed before multiplication, this truncation error gets amplified, potentially leading to significant discrepancies in financial calculations.
The vulnerable code in the buyOutEstateNFT function:
The function calculates the payment amount by first dividing the NFT value by the number of beneficiaries and then multiplying by one less than the number of beneficiaries. This order of operations leads to potential value loss due to integer division truncation.
This vulnerability allows users to purchase NFTs at reduced prices, causing:
Direct Financial Loss: Beneficiaries receive less compensation than intended for the estate NFT.
Economic Imbalance: The protocol consistently undervalues assets, leading to systemic underpricing.
Exploitation Potential: Malicious users can target NFTs with values that maximize the truncation error.
Consider an NFT valued at 3,000,001 tokens with 3 beneficiaries:
Current Implementation (Vulnerable):
Correct Implementation:
The discrepancy in this example is only 0.67 tokens, but with larger values and certain combinations of divisors and multipliers, the impact can be substantial.
NFT value is 3-000-000
While this fix addresses the immediate issue, consider implementing additional safeguards:
Add thorough documentation explaining the formula and its purpose
Consider using a fixed-point arithmetic library for enhanced precision
Add sufficient tests that verify correct calculation with various input values
Implement event emissions to log all payment calculations for transparency
By addressing this vulnerability, the protocol ensures fair pricing for estate NFTs and protects both the beneficiaries and the integrity of the inheritance system.
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.