0

I can't see underflow happening in latest Remix compiler. I have used the following code:

pragma solidity ^0.5.1;

    contract test {
    event testV(uint indexed value1);
    uint val= 0;

     function testf() public {


                  val--;

        emit testV(val); 
    }
}

Can somebody please guide me how to show underflow in Remix because this is an important smart contract vulnerability?

Zulfi.

1

Deploy the contract, execute the function and check the output in the console:

enter image description here

  • Start value: 0
  • Final value (Dec): 115792089237316195423570985008687907853269984665640564039457584007913129639935
  • Final value (Hex): 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

If you prefer to see as a function output:

contract Underflow {
    uint val= 0;
    function testf() public view returns (uint){
        return val-1;
    }
}
  • I am getting: "from": "0x5e72914535f202659083db3a02c984188fa26e9f", "topic": "0x6b89e470d678c7bbcfb2aabdca0bd6d3eb405f199e68d051d4f27b6aca1fa675", "event": "testV", "args": { "0": "115792089237316195423570985008687907853269984665640564039457584007913129639935", "value1": "115792089237316195423570985008687907853269984665640564039457584007913129639935", "length": 1 } } ], I am not getting start value & Final Value. How are you getting? On the LHS it says: Solidity State val: 0uint256. Is unint same as uint256? – zak100 Jun 7 at 22:19
  • 1
    You are getting the same, check the image. Start value and final value are not outputs of remix, it's something that I've used to name the value of the variable before and after the execution of the function. uint is alias for uint256: solidity.readthedocs.io/en/latest/types.html#integers – alberto Jun 8 at 0:31

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.