The inherit
function in the InheritanceManager
contract, designed to transfer control of the contract to the beneficiaries after a period of owner inactivity, has a critical flaw in its handling of cases with only a single beneficiary. In this scenario, any address can claim ownership, not just the intended beneficiary, leading to a complete bypass of the intended inheritance mechanism.
inherit
Function:
Purpose: To transfer ownership of the contract to the beneficiaries after a specified period of owner inactivity (defined by TIMELOCK
).
Logic:
Checks if the current time is past the deadline
.
If there's only one beneficiary (beneficiaries.length == 1
), it directly assigns ownership to msg.sender
.
If there are multiple beneficiaries (beneficiaries.length > 1
), it sets isInherited
to true
, allowing beneficiaries to distribute funds.
If there are no beneficiaries, it reverts with InvalidBeneficiaries()
.
Flaw: The condition beneficiaries.length == 1
only checks the number of beneficiaries and doesn't verify if msg.sender
is that specific beneficiary.
Code:
Add this test to the test suite InheritanceManagerTest
at path test/InheritanceManagerTest.t.sol
and run the command forge test --mt test_inheritByAttacker
:
From the test, an attacker was able to call the inherit
function even though he has not interacted with the contract before or added to beneficiry list
Loss of Funds: A malicious actor can become the owner and transfer all funds out of the contract.
Unauthorized Control: An unintended party can take control of the contract, locking out the original owner and intended beneficiaries.
Manual Code Review
Foundry for PoC
Check msg.sender
Against the Beneficiary: Modify the inherit
function to verify that msg.sender
is the single beneficiary when beneficiaries.length == 1
.
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.