Can someone help me on what exactly the modifier is doing in this contract and why the message data length is increased by 4?

contract NonPayloadAttackableToken {
    modifier onlyPayloadSize(uint size) {
        assert(msg.data.length == size + 4);

    function transfer(address _to, uint256 _value) onlyPayloadSize(2 * 32) {
    // do stuff

The + 4 is because the hash of the function signature is 4 bytes, so the modifier is only checking the length of the function payload. This modifier seems to be validating that the msg is size bytes, ignoring the function signature.

  • Ok I figured. I just was not sure. The 4 bytes are used as a hash signature. – S. Ansari May 3 '18 at 19:59
  • @S.Ansari if the answer is helpfull please consider to accept it – Badr Bellaj May 3 '18 at 20:07
  • @BadrBellaj need to get more up to speed with stackexchange etiquette lol – S. Ansari May 3 '18 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.