Incorrect msg.value handling in claim function prevents ETH refunds #97
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-109
edited-by-warden
🤖_04_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L264-L304
https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L327-L346
https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L352-L383
https://github.com/code-423n4/2024-08-phi/blob/8c0985f7a10b231f916a51af5d506dd6b0c54120/src/PhiFactory.sol#L723-L758
Vulnerability details
In the
claim
function, when a user wants to claim art and transfers ETH, the function internally calls eitherthis.merkleClaim
orthis.signatureClaim
, passing themintFee
as the value. However, because these calls use thethis
keyword, they are treated as external calls. This causesmsg.value
to reset, meaning that in thesignatureClaim
and_processClaim
functions,msg.value
will only equal themintFee
. As a result, when the refund is calculated in the_processClaim
function, it is always zero, sinceetherValue_
always equalsmintFee
. Consequently, users are unable to receive refunds for any excess ETH sent with their claim.Impact
This issue prevents users from receiving refunds for any ETH they send beyond the required
mintFee
. If a user mistakenly sends more ETH than required, they will lose the excess amount because the contract incorrectly calculates the refund as zero. This could lead to significant financial losses for users.Proof of Concept
Add following logs into the PhiFactory
These two into the claim() function
This one into the signatureClaim function
This one into the _processClaim function
Add this code to the
PhiFactory.t.sol
file and run the following command:forge test -vvv --match-test POC
:Here logs for all functions in the transaction
Tools Used
Manual Review
Forge
Recommended Mitigation Steps
To correct this issue, the internal function calls should avoid using the
this
keyword, ensuring thatmsg.value
remains intact throughout the transaction. Alternatively, themintFee
should be passed and handled separately without altering the original msg.value. This will allow the contract to correctly calculate and refund any excess ETH sent by the user during the claim process.Assessed type
ETH-Transfer
The text was updated successfully, but these errors were encountered: