The MembershipFactory
contract relies on unchecked calls to transferFrom
for ERC-20 token transfers, which may fail silently if a token does not revert on failure but instead returns false
. This vulnerability allows transactions to appear successful even if no tokens are transferred, leading to potential loss or misallocation of funds. This oversight could create exploitable scenarios where required funds are not transferred as expected, compromising the contract’s intended operation and increasing risk for users.
The MembershipFactory
contract calls the transferFrom
function directly on an IERC20
token, assuming that a failed transfer will throw an error. However, certain tokens do not revert when transfer
or transferFrom
operations fail, and instead, they return a false
value. If these return values are not checked, the contract may believe the transfer was successful, even though no tokens were actually moved.
In this case, a malicious user could attempt to call functions that rely on these unchecked transfers, potentially gaining benefits without actually transferring any tokens. This can lead to operational inconsistencies and undermine the security of the token handling within the smart contract.
Affected Line of Code
MembershipFactory.sol: Line 146
MembershipFactory.sol: Line 147
Transaction failures without notification, leading to mismanaged user funds and disrupted functionality. This vulnerability is likely to be encountered, especially if users interact with tokens that do not revert on failed transfers. While some ERC-20 tokens follow a non-standard approach and return false
on failure, it is impossible to ensure that all tokens used with the contract adhere to a revert-on-failure approach. This makes the unchecked transfer vulnerability a significant and likely threat.
Unchecked transfers introduce the following risks:
Silent Transaction Failures: If the token transfer fails and returns false
, the contract will not revert, and the transaction will appear successful to the user and the contract. This results in incomplete or invalid transfers without any notification, potentially affecting contract integrity and user trust.
Misallocation of Funds: Certain functions may rely on these transfers to ensure funds are collected or redistributed as expected. If a transfer fails without detection, the contract logic could proceed based on the incorrect assumption that funds have been moved as required, leading to a breakdown in fund management.
Exploitable Loophole: A malicious user could exploit this vulnerability to bypass payment requirements or obtain benefits from the contract without making the required token transfers, affecting the overall integrity and security of the platform.
Proof of Concept
If a user or attacker interacts with the contract using a token that does not revert on failed transfers, they could simulate a transfer call to bypass payments or required transfers:
A user calls a function in MembershipFactory
that executes:
Suppose this transfer fails due to insufficient balance, but the token does not revert and instead returns false
.
Without checking the return value, the contract considers the transfer successful, and the function proceeds, even though no funds have been transferred.
Manual Review
Implement Safe Transfers: Use OpenZeppelin’s SafeERC20 library, which includes safeTransfer and safeTransferFrom functions that check for success and revert on failure, ensuring funds are only considered transferred if successful.
Updated code:
Ensure Robust Token Interaction: To prevent similar issues, ensure all external token interactions use SafeERC20’s safe methods, mitigating silent failures and improving the contract's security and reliability.
Implementing these changes will safeguard the contract against silent failures, ensuring all token transfers are securely handled and improving the contract’s overall resilience to user and token variability.
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.