pragma solidity 0.4.18; // Contract to test unsigned integer underflows and overflows // note: uint in solidity is an alias for uint256 // 1.Overflow Sample Test // 1) Overflow_contract Deploy // 2) max call -> 2**256-1 // 3) overflow() call -> overflow excute // 4) max call -> 0 // 2. Underflow Sample Test //. 1) Underflow_contract Deploy // 2) zero call -> 0 // 3) underflow() call -> overflow excute // 4) zero call -> 2**256-1 contract Overflow_contract { uint public max = 2**256-1; // max will end up at 0 function overflow() public { max += 1; } } contract Underflow_contract { uint public zero = 0; // zero will end up at 2**256-1 function underflow() public { zero -= 1; } } contract OffByOne_contract { uint[] public arr = [1, 1, 1, 1, 1]; function getArr() public view returns (uint[] memory) { return arr; } function offbyone() public { for(uint i = 0;i<arr.length;i++) { arr[i] = i; } } }
0.4.18