Created
July 18, 2023 10:49
-
-
Save TehilaFavourite/1bca4b71dc31073ea9823b821703e206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract InvalidOperationExample { | |
uint256[] public myArray; | |
function invalidOperation() public { | |
// Division by zero | |
uint256 a = 10; | |
uint256 b = 0; | |
uint256 divisionResult = a / b; // Will cause a division by zero exception | |
// Array index out-of-bounds | |
myArray = new uint256[](3); | |
myArray[0] = 1; | |
myArray[1] = 2; | |
myArray[2] = 3; | |
uint256 value = myArray[3]; // Accessing index 3 (out-of-bounds), will cause an array index out-of-bounds exception | |
// Type conversion issue | |
uint8 num1 = 200; | |
uint8 num2 = 100; | |
uint8 result = num1 + num2; // Invalid implicit conversion from uint16 to uint8, will cause a type conversion issue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment