Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Yeah, I guess you have a point. From the point of view of the function, nothing is wrong. Except it is accepting an out-of-range value as parameter (and the overflow happens 'naturally', so that it becomes in-range). Still, the problem remains. So, I gather it's just not possible to solve this problem 100%, it will always be possible to overflow using user input. I'll just wait a few more minutes to see if a new answer appears. Thanks.
Sorry for being unclear. I mean that b will be "squeezed" into a uint8 before the 'require(b <= a);' line is executed. When b is received as a parameter that has to be a uint8, it will immediately overflow (260 in a uint8 will become 4, because a uint8 cannot be greater than 255).
But when the number 260 is fit into a uint8, it overflows and becomes 4. By the time the require line is executed, b is already 4 (because it had to fit into a uint8 to be a valid parameter of the function). Isn't that what happens?