I was reading about the short address attack and decided to replicate and test the possible solutions.
What I know about short address attack is if you skip n characters of your address, you end up supplying 68-(n/2) bytes to your transfer
function and the evm appends zeros to makes if 68 bytes. And the end result is your value changes by n<<8
. This was just a high-level overview.
Now I trid to test the same with a test toke (with decimal places =2) . The transfer function of the contract goes by:
function transfer(address _to, uint256 _value) {
require (balanceOf[msg.sender] > _value) ;
require (balanceOf[_to] + _value > balanceOf[_to]);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
Transfer(msg.sender, _to, _value);
}
I used remix connected to my private test-net to check for this attack.
I had an address 0x7ecd024742458287b9cd97015ff265d04a316f20
. I called the transfer function of contract with arguments:
transfer("0x7ecd024742458287b9cd97015ff265d04a316f2", 1);
As per my understanding, I was expecting the supplied address will get 256 coins (if short address attack is replicated). But instead I got the error:
transact to browser/TestShortAddAttack.sol:MyToken.transfer errored: Gas required exceeds block gas limit: 6000000. An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation).
Why is the transaction consuming this much gas? Is this issue has been taken care by evm or we need to implement the check (Checking length of msg.data)?