solidity/test/libsolidity/semanticTests/viaYul/detect_mul_overflow.sol

38 lines
2.2 KiB
Solidity
Raw Normal View History

contract C {
function f(uint a, uint b) public pure returns (uint x) {
x = a * b;
}
function g(uint8 a, uint8 b) public pure returns (uint8 x) {
x = a * b;
}
}
// ====
2020-09-15 14:16:30 +00:00
// compileViaYul: also
// ----
// f(uint256,uint256): 5, 6 -> 30
// f(uint256,uint256): -1, 1 -> -1
2020-10-13 11:28:39 +00:00
// f(uint256,uint256): -1, 2 -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): 0x8000000000000000000000000000000000000000000000000000000000000000, 2 -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 2 -> -2
2020-10-13 11:28:39 +00:00
// f(uint256,uint256): 2, 0x8000000000000000000000000000000000000000000000000000000000000000 -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): 2, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> -2
2020-10-13 11:28:39 +00:00
// f(uint256,uint256): 0x0100000000000000000000000000000000, 0x0100000000000000000000000000000000 -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): 0x0100000000000000000000000000000000, 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000
// f(uint256,uint256): 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 0x0100000000000000000000000000000000 -> 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000
// f(uint256,uint256): 0x0100000000000000000000000000000001, 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> -1
// f(uint256,uint256): 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 0x0100000000000000000000000000000001 -> -1
2020-10-13 11:28:39 +00:00
// f(uint256,uint256): 0x0100000000000000000000000000000002, 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 0x0100000000000000000000000000000002 -> FAILURE, hex"4e487b71", 0x11
// f(uint256,uint256): -1, 0 -> 0
// f(uint256,uint256): 0, -1 -> 0
// g(uint8,uint8): 5, 6 -> 30
2020-10-13 11:28:39 +00:00
// g(uint8,uint8): 0x80, 2 -> FAILURE, hex"4e487b71", 0x11
// g(uint8,uint8): 0x7F, 2 -> 254
// g(uint8,uint8): 2, 0x7F -> 254
2020-10-13 11:28:39 +00:00
// g(uint8,uint8): 0x10, 0x10 -> FAILURE, hex"4e487b71", 0x11
// g(uint8,uint8): 0x0F, 0x11 -> 0xFF
2020-10-13 11:28:39 +00:00
// g(uint8,uint8): 0x0F, 0x12 -> FAILURE, hex"4e487b71", 0x11
// g(uint8,uint8): 0x12, 0x0F -> FAILURE, hex"4e487b71", 0x11
// g(uint8,uint8): 0xFF, 0 -> 0
// g(uint8,uint8): 0, 0xFF -> 0