The onlyBeneficiaryWithIsInherited
modifier in the InheritanceManager
contract exhibits a gas-based Denial-of-Service (DoS) vulnerability. Specifically, when a non-beneficiary attempts to call a function protected by this modifier, the loop iterates through all beneficiaries, leading to extremely high gas consumption. This can make transactions prohibitively expensive or even unexecutable under network gas limits.
The issue arises due to the linear search through the beneficiaries
array. If msg.sender
is not found within the list, the loop executes fully, consuming gas proportional to the number of stored beneficiaries.
Proof of Code:
Place the following code in InheritanceManagerTest.t.sol
Action | Gas Used |
---|---|
Adding 2 beneficiaries | 100,341 |
Adding 1,000 beneficiaries | 23,714,044 |
Calling InheritanceManager::appointTrustee as a beneficiary (1st call) |
25,585 |
Calling InheritanceManager::appointTrustee as a non-beneficiary (2nd call) |
631,872 |
Calling InheritanceManager::appointTrustee as a beneficiary (3rd call) |
631,427 |
The third call (InheritanceManager::appointTrustee
by a beneficiary) is prohibitively expensive, confirming the DoS vulnerability.
Denial-of-Service: If the list of beneficiaries is large, transactions can become too expensive to execute.
Financial Loss: Users may incur high gas costs attempting transactions.
Foundry
Optimize the Loop: Instead of iterating through all beneficiaries, use a mapping(address => bool)
to track beneficiary status. Example:
Restrict Array Growth: Implement a reasonable cap on the number of beneficiaries.
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.