Commit Hash: b5dd7b0
Description:
The
contribute
function in the RustFund smart contract updates the fund's state after performing a transfer operation, creating a reentrancy vulnerability. The function increments theamount_raised
state variable only after executing an external call to transfer SOL from the contributor to the fund account. By updating state after the transfer, the contract becomes vulnerable to reentrancy attacks where a malicious actor could recursively call back into thecontribute
function before the initial execution completes.
Impact:
An attacker could exploit this vulnerability to:
Have a single contribution counted multiple times
Artificially inflate the amount_raised value beyond their actual contribution
Manipulate the fundraising metrics to potentially trigger premature goal achievement
Create accounting inconsistencies between actual funds held and reported amounts
This vulnerability threatens the integrity of the fundraising system and could lead to financial losses for the protocol or its users.
Proof of Concept:
Recommended Mitigation:
To prevent reentrancy attacks in the
contribute
function, implement the Checks-Effects-Interactions (CEI) pattern by updating the fund's state before performing the external SOL transfer. This ensures that any reentrant calls will operate on the updated state, eliminating the possibility of double-counting contributions. Additionally, consider adding a reentrancy guard to explicitly block recursive calls if needed, though CEI alone does suffice in this case.Here's the corrected version of the
contribute
function:
The reentrancy attacks occur when the contract modifies state and makes an external call, allowing the attacker to reenter. The `contribute` function doesn't perform an external call. For the SOL transfer the function uses a system program, not an external call to another smart contract. Therefore, there is no attack vector for reentrancy.
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.