Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop n64 in favor of using BigInt #821

Open
nodech opened this issue Jun 16, 2023 · 0 comments · May be fixed by #822
Open

Drop n64 in favor of using BigInt #821

nodech opened this issue Jun 16, 2023 · 0 comments · May be fixed by #822

Comments

@nodech
Copy link
Contributor

nodech commented Jun 16, 2023

Now that BigInts are available in node since v10.4, we can stop using https://github.com/chjj/n64.
Since bcoin-org/bufio#3 and some fixes [email protected] also support BigInts, that we can use to replace serializers.

The value currently in Output.value, ScriptNum, Coin are Numbers which don't allow arithmetic operations after Number.MAX_SAFE_INTEGER and that's the current limit, where it should actually be full u64. Also simplifies the maintenance for the project, as n64 is using nan for the C implementation and can always break (different from napi which has some guarantees to breaking API).

Output.value is safe because consensus.MAX_MONEY is lower than Number.MAX_SAFE_INTEGER(2^53-1).
ScriptNum on the other hand can be anything within the range(-2^63-1 ~ 2^63 - 1) even though operands themselves should be int32 - results can overflow into int64.
https://github.com/bitcoin/bitcoin/blob/7f0b79ea132d22ad5212c1d3ff4325715ca5ac12/src/script/script.h#L222-L231

@nodech nodech linked a pull request Jun 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant