Transfer condition in Dai ERC20

This is snippet from DAI contract(0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa in Kovan)

function transferFrom(address src, address dst, uint wad)  public returns (bool) {
        require(balanceOf[src] >= wad, "Dai/insufficient-balance");
        if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
            require(allowance[src][msg.sender] >= wad, "Dai/insufficient-allowance");
            allowance[src][msg.sender] = sub(allowance[src][msg.sender], wad);
        }
        balanceOf[src] = sub(balanceOf[src], wad);
        balanceOf[dst] = add(balanceOf[dst], wad);
        emit Transfer(src, dst, wad);
        return true;
}

Why does it need the second condition allowance[src][msg.sender] != uint(-1)? (uint(-1) is max of uint256). Is it enough to check src != msg.sender? Any security reason?

1 Like

Hi @swkim109,

I assume from reading this snippet that uint(-1) is a magic number for unlimited allowance, and allowance is only reduced if it isn’t set to this unlimited magic number.

1 Like