Current fee table values are all shifted left 79 bits in order to have precision for all feeFactors.
This leads that the maximum feeFactorShifted value is 10**31 << 79, with a bit length of 182.
Taking into account that maximum transferred amountFloat could be 0xFFFF, with a bit length of 113 bits, computing amount * feeFactorShifted could overflow snark Field maximum bits length (253) since 182 + 113 = 295 > 253.
Error is not triggered since num2bits template does not checks overflows and therefore, it could led to applying an erroneous feeAmount
Solution
fee table would be changed to not reach an overflow situation
shifted would be applied to fee table if precision is needed
sanity check on fee computed: fee computed < 2^{129
Implementation
generalize fee-table-selector into a mux256
isolate computing fee into a single circuit compute-fee
update balance-updater with above circuit abstractions
Describe issue
Current fee table values are all shifted left 79 bits in order to have precision for all
feeFactors
. This leads that the maximumfeeFactorShifted
value is10**31 << 79
, with a bit length of 182.Taking into account that maximum transferred
amountFloat
could be0xFFFF
, with a bit length of 113 bits, computingamount * feeFactorShifted
could overflow snark Field maximum bits length (253) since182 + 113 = 295 > 253
. Error is not triggered sincenum2bits
template does not checks overflows and therefore, it could led to applying an erroneousfeeAmount
Solution
fee computed < 2^{129
Implementation
fee-table-selector
into amux256
compute-fee
balance-updater
with above circuit abstractions