Diagnose a large quotient from Cairo felt division
An on-chain calculation of three divided by two can yield a very large field element. Cairo felt arithmetic operates in a finite field and uses a multiplicative inverse for division.
Reproduce the field operation
Let P be the Starknet field prime. The integer (P + 3) / 2 is an exact integer because P is odd. Doubling it gives P + 3, which reduces to three modulo P. That makes it a field quotient of three by two.
3 / 2 as felt252 = (P + 3) / 2
2 × ((P + 3) / 2) mod P = 3
If the business rule calls for one unit with a remainder of one, use a suitable unsigned integer type and explicit integer division and remainder. A floating-point representation in a front end describes neither result reliably for large values.
Test denominator and amount boundaries
Include non-divisible amounts and the zero denominator in the test suite. Specify a rounding convention for shared fees or token amounts. A value that fits in a felt may need an explicit checked conversion before it can be used as a bounded integer. starknet.io The Cairo Programming Language