In a contract used for testing Gnosis MultiSigWallet, I found this piece of code:
/*
* This modifier is present in some real world token contracts, and due to a solidity
* bug it was not compatible with multisig wallets
*/
modifier onlyPayloadSize(uint size) {
require(msg.data.length == size + 4);
_;
}
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
/// @return Returns success of function call.
function transfer(address _to, uint256 _value) onlyPayloadSize(2 * 32)
public
returns (bool success)
{
require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
}
The documentation of the onlyPayloadSize
modifier is extremely unclear to me.
Can somebody please explain the following:
- What exactly is the purpose of this modifier?
- Why is it used only in the
trasnsfer
function? - Why is it used with a specific size of 64 (
2 * 32
)? - Why is this modifier present only in a test contract, and not in the actual
MultiSigWallet
contract? Does this by any chance imply that I should add this modifier in every contract in my system, designated for access only via an instance of theMultiSigWallet
contract? If I don't have any such contract with a standardtransfer
method (i.e., an ERC20 contract), can I rest assure that I don't need this modifier anywhere else in my system?
Thank you!