hyperledger-solang/solang

No exception is thrown on overflow during testing via Anchor Framework

YanhuiJessica opened this issue · 1 comments

Describe the bug
I started a project following Getting started with Solang. I have tried some math calculations that would overflow, but found that all tests passed.

To Reproduce
Steps to reproduce the behavior:

  1. anchor init example --solidity
  2. Overwrite the flip() function with the following lines (example/solidity/example.sol)
function flip() public {
   uint32 x = 2147483648;
   uint32 y = 2147483648;
   uint32 z = x + y;
   print("z: {}".format(z));
   value = !value;
}
  1. anchor test All tests passed
  2. example/.anchor/program-logs/F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC.example.log
Streaming transaction logs mentioning F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC. Confirmed commitment
Transaction executed in slot 2:
  Signature: N3wupwfD5JcQLAVznxcqLXYB5wqqzoGGzmNyqMRwSqMjVsXJt8FZqu6ZjUg51pqdcMRMgBuut2kUvHwGGt5g97K
  Status: Ok
  Log Messages:
    ...
    Program log: Hello, World!
    ...
Transaction executed in slot 3:
  Signature: 4pL9WzzwpVp8CVbzFarEgcyXhCAUW7b661VGqWeUGHbwD8M4XT6ccprzu6nKXcCv7vCrS883jaBaptJ5Yg56orJJ
  Status: Ok
  Log Messages:
    Program F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC invoke [1]
    Program log: z: 0
    ...

Expected behavior
Throws an exception on overflow.

Hyperledger Solang version
v0.3.1

The const folding pass is at fault here. The addition is done at compile time, but the overflow is not detected.