jlopp / bitcoin-transaction-size-calculator

A simple web tool for calculating the weight and size of a bitcoin transaction with specific properties
https://jlopp.github.io/bitcoin-transaction-size-calculator/
MIT License
41 stars 8 forks source link

Just for record, the number 18446744073709551615 in getSizeOfVarInt() is not working as intended #14

Open tadeubas opened 2 months ago

tadeubas commented 2 months ago

JavaScript uses the IEEE 754 double-precision floating-point format for numbers, 18446744073709551615 is larger than this maximum safe integer value. Specifically, it's the maximum value for a 64-bit unsigned integer, which JavaScript does not handle precisely with its standard number type. You can make this test on your browser console, just type the number and it will show 18446744073709552000 instead.

We would need to change the code to work with the BigInt type to handle such large integers. This issue was created just 4 fun 😝

jlopp commented 2 months ago

Is it actually possible to trigger this overflow via the form, though?

Looks like the max value we allow for each integer input field is 99999 and even when I max that out on every field, none of the math ends up approaching anywhere near javascript's max integer.

tadeubas commented 2 months ago

Sure, it was 4 fun because this value exists in the code here: https://github.com/jlopp/bitcoin-transaction-size-calculator/blob/master/index.html#L68