Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

unforgiven - function _contractFallback() is always revert because IERC677Receiver has wrong function signature for onTokenTransfer() #152

Closed
sherlock-admin opened this issue Jan 8, 2024 · 8 comments
Labels
Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jan 8, 2024

unforgiven

medium

function _contractFallback() is always revert because IERC677Receiver has wrong function signature for onTokenTransfer()

Summary

because IERC677Receiver has wrong function signature for onTokenTransfer() so the transferAndCall() will always revert if it calls onTokenTransfer() of the target contract(which correctly implement the ERC)

Vulnerability Detail

This is transferAndCall() code:

    function transferAndCall(address _to, uint256 _value, bytes calldata _data) public returns (bool success) {
        super.transfer(_to, _value);
        emit Transfer(msg.sender, _to, _value, _data);
        if (Address.isContract(_to)) {
            _contractFallback(_to, _value, _data);
        }
        return true;
    }

    // PRIVATE
    function _contractFallback(address _to, uint256 _value, bytes calldata _data) private {
        IERC677Receiver receiver = IERC677Receiver(_to);
        receiver.onTokenTransfer(msg.sender, _value, _data);
    }

as you can see it uses IERC677Receiver to call onTokenTransfer() function of the to address. This is IERC677Receiver:

interface IERC677Receiver {
    function onTokenTransfer(address _sender, uint256 _value, bytes calldata _data) external;
}

the issue is that function signature of the onTokenTransfer() is not according to the ERC677 and it doesn't define the return value of the function and if a target contract implements ERC677 correctly then it's gonna return the bool variable and because function signature is wrong in ERC677Token so solidity would revert that call and the whole transaction would revert. as result ERC677Token won't gonna work according to the EIP.

Impact

token ERC677Token would always revert in transferAndCall() function if the to is contract and that contract implements EIP correctly.

Code Snippet

https://github.com/sherlock-audit/2023-12-truflation/blob/37ddbb69e0c7fb6510f1ec99162fd9172ec44733/truflation-contracts/src/token/ERC677Token.sol#L26-L29
https://github.com/sherlock-audit/2023-12-truflation/blob/37ddbb69e0c7fb6510f1ec99162fd9172ec44733/truflation-contracts/src/interfaces/IERC677Receiver.sol#L4-L6

Tool used

Manual Review

Recommendation

change IERC677Receiver to be like this:

interface IERC677Receiver {
    function onTokenTransfer(address _sender, uint256 _value, bytes calldata _data) external returns(bool);
}
@ryuheimat ryuheimat added Will Fix The sponsor confirmed this issue will be fixed Sponsor Confirmed The sponsor acknowledged this issue is valid labels Jan 9, 2024
@github-actions github-actions bot added Medium A valid Medium severity issue Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Jan 12, 2024
@sherlock-admin2
Copy link
Contributor

1 comment(s) were left on this issue during the judging contest.

Shaheen commented:

Not sure, maybe a valid medium

@IllIllI000
Copy link
Collaborator

This is invalid. The function signature that the actual 667 code uses does not have a bool, and the delployed link contracts also do not have bools on both Eth and Base mainnets

@ryuheimat
Copy link

@IllIllI000 ethereum/EIPs#677
The standard EIP677 requires bool return value i think.

@ryuheimat
Copy link

@IllIllI000 https://github.com/truflation/truflation-contracts/pull/8
I've updated in this PR anyways, and let's discuss again if we merge this or not.

@IllIllI000
Copy link
Collaborator

You've linked to an open issue in the EIP repo, from which a standard is usually created. In this case, the filer closed the issue without it becoming a standard, so whatever its contents at that point were, aren't really relevant.

@ryuheimat
Copy link

@IllIllI000 I agree with this, then we can mark this issue as invalid,

@ryuheimat ryuheimat added Sponsor Disputed The sponsor disputed this issue's validity and removed Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Jan 12, 2024
@nevillehuang
Copy link
Collaborator

@IllIllI000 Could I understand what is the purpose of the fallback function? From my understanding it is to ensure tokens are correctly received within a smart contract correct? So even if a boolean return value is not implemented, can it be assumed that the callback function would correct revert based on its logic if tokens are not successfully received?

@IllIllI000
Copy link
Collaborator

IllIllI000 commented Jan 12, 2024

The purpose of EIP677's transferAndCall() is essentially to be a multicall whose task is to perform a normal transfer(), followed by an arbitrary function call on the recipient. The assumption of the EIP is that the function called after the transfer will require tokens, and any user that calls it without those tokens will get a failure. The token itself reverts on failure to transfer, so what happens afterwards doesn't seem relevant to this function, given that the expected behavior depends on the function being called by the callback afterwards, is not known ahead of time.

@nevillehuang nevillehuang removed the Medium A valid Medium severity issue label Jan 12, 2024
@sherlock-admin2 sherlock-admin2 changed the title Noisy Mercurial Hornet - function _contractFallback() is always revert because IERC677Receiver has wrong function signature for onTokenTransfer() unforgiven - function _contractFallback() is always revert because IERC677Receiver has wrong function signature for onTokenTransfer() Jan 17, 2024
@sherlock-admin2 sherlock-admin2 added Non-Reward This issue will not receive a payout and removed Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity
Projects
None yet
Development

No branches or pull requests

5 participants