Reject text: IC0503: Canister ypg3d-6qaaa-aaaah-aasgq-cai trapped explicitly: arithmetic overflow

I recently started getting this error:

index.js:2 Error: Call was rejected:
  Request ID: 2d36e3ff2aac0cb1cedc70eb318ed103e8ccf9db2d168f570ac371aaf8679e8b
  Reject code: 4
  Reject text: IC0503: Canister ypg3d-6qaaa-aaaah-aasgq-cai trapped explicitly: arithmetic overflow

    at uo (index.js:2)
    at async r (index.js:2)
    at async Object.Oa [as mutationFn] (index.js:2)

and I’m not quite sure what the problem can be or how to debug this. Do you guys have any idea what I can start looking into? Thanks in advance?

The bug can be reproduced by:

The thing is, it works half the time, so I really don’t know what goes wrong. Any help is greatly appreciated!

1 Like

Tbh not sure who to even ask. Let me ping some folks.

maybe there is overflow bug in your motoko/rust code.

1 Like

Definitely Motoko. You might be using bounded types (Nat8 etc.) and they are overflowing, or you might be using Nat and some subtraction turns out to underflow.

1 Like

That’s great! Then it shouldn’t be that hard to find. Is there a way to know which line or which function causes the overflow? How do you guys normally debug something like this?

The line number is not included in the error message to not blow up the canister size too much (although some clever tricks might alleviate that).

So code reading and Debug.print debugging (local only) is currently your best bet.

4 Likes

I’m having the same problem, does anyone know how to fix it?