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

U256 type can get negative value #97

Open
RostislavLitovkin opened this issue Oct 11, 2024 · 2 comments
Open

U256 type can get negative value #97

RostislavLitovkin opened this issue Oct 11, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@RostislavLitovkin
Copy link
Contributor

var address = "unixuHLc4UoAjwLpkQHUWy2NpT5LV4tUqJFnFVNyLaeqBfq22";

var publicKey = Utils.GetPublicKeyFrom(address);

var value = new U256();

int p = 0;

value.Decode(publicKey.Reverse().ToArray(), ref p);

Console.WriteLine(value.Value); // -26843990603843339315797176730311565364345939525783601353920003531657203886725

U256 should never be negative.

@RostislavLitovkin RostislavLitovkin added the bug Something isn't working label Oct 11, 2024
@RostislavLitovkin
Copy link
Contributor Author

Workaround I found for getting the correct value:

Console.WriteLine(new BigInteger(publicKey, true, true));

@darkfriend77 darkfriend77 added enhancement New feature or request and removed bug Something isn't working labels Oct 14, 2024
@darkfriend77
Copy link
Member

darkfriend77 commented Oct 14, 2024

NetStandard 2.0 doesn't support the isUnsigned option. The trade-off is to mimic a larger array to achieve a BigInteger with the most significant bit not set. However, this leads to an inconsistency between the BigInteger value and the byte representation.

I'm unsure if we should address this, as the use case seems quite constructed and likely irrelevant.

a47945d#diff-d9432c6f40e795d58bd62982772a902b84fac034ad1ef8c55ac543a4d4f8086eR80

darkfriend77 added a commit that referenced this issue Nov 9, 2024
* fixed wrong indexing bitseq
updated nodetest to allow specific rpcs

* Reverse and FromBitString and ToBitString moved to static utils.

* fixed comment

* fixed comment

* fixed for versions bigger then NET2.0 #97

* added the negative number test

* next release

* removed old enum extension from usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants