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

solidity::util::formatNumberReadable signed integer support #9601

Closed
leonardoalt opened this issue Aug 11, 2020 · 17 comments
Closed

solidity::util::formatNumberReadable signed integer support #9601

leonardoalt opened this issue Aug 11, 2020 · 17 comments
Labels
easy difficulty good first issue candidate Could be a "good first issue" but something is blocking it or it has open questions. low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. nice to have We don’t see a good reason not to have it but won’t go out of our way to implement it.
Projects

Comments

@leonardoalt
Copy link
Member

Currently that function does not support signed values, causing, for example:
Warning 3944: (110-115): Underflow (resulting value less than -57896044618658097711785492504343953926634992332820282019728792003956564819968) happens here.
That number is actually -2**255, so it could be better formatted.

@axic
Copy link
Member

axic commented Aug 13, 2020

Probably the same issue: #9479 (comment)

@Neyromancer
Copy link

Hi, i will try to work on it.

@cameel cameel added this to New issues in Solidity via automation Nov 22, 2020
@cameel cameel moved this from New issues to Implementation Backlog in Solidity Nov 22, 2020
@Neyromancer
Copy link

Hi, just to clarify. Should the number -57896044618658097711785492504343953926634992332820282019728792003956564819968
be transformed to -2**255
or it can also be represented as
-0x80 * 2**248?
Asking because the number 57896044618658097711785492504343953926634992332820282019728792003956564819968 is now transformed into 0x80 * 2**248.

@cameel
Copy link
Member

cameel commented Dec 6, 2020

In my opinion, if that's the current behavior in the positive case then doing a similar thing in the negative one is fine as well. It's still some improvement.

But, it would be best to just change it in both cases to -2**255/2**255. Unless there's some technical reason preventing this - I haven't really looked at the current implementation yet so there might be something I'm not aware of.

Also note that after implementing it you should update expectations in tests because that's where these numbers are used currently. But don't do it manually - you can just run isoltest and accept the changes it proposes (see Writing and Running Syntax Tests in the docs in case you haven't yet).

@Neyromancer
Copy link

Neyromancer commented Dec 6, 2020

Actually, i think it is technically possible to move from 0x80 * 2 ** 248 to 2 ** 255 so i will try to implement it.

I just was not sure whether to follow the current implementation or to do it in the way it was written in the task, i.e. which number representation to take as a basiс representation. But i understand now.
By the way thank you for the link:)

@Neyromancer
Copy link

if this problem does not block anything. i am still working on it. it took a bit more than expected but guess it is only due to personal reasons.

@cameel
Copy link
Member

cameel commented Feb 2, 2021

There's no hurry. It would be pretty helpful, especially in cases like #10776 (comment) but fixing this is not a priority right now so you can work on it at your own pace.

@cameel
Copy link
Member

cameel commented Jul 6, 2021

@Neyromancer Are you still working on it? Do you need any help?

@Ruko97
Copy link
Contributor

Ruko97 commented May 23, 2022

If this issue hasn't been resolved yet, I am interested to work on it.

@cameel
Copy link
Member

cameel commented May 25, 2022

It's up for the taking. But I'd recommend the other issue you commented on (#9926) because it's more visible to users and should be more satisfying to fix.

@Ruko97
Copy link
Contributor

Ruko97 commented May 29, 2022

Are signed integers implemented in the compiler using u256 as well, or is there another datatype for representing signed integers?

@cameel
Copy link
Member

cameel commented Jun 2, 2022

We have s256 as well.

@cameel
Copy link
Member

cameel commented Jun 2, 2022

But to be clear, this function is not limited to u256/s256. See for example this place in BMC::checkUnderflow(), where it's called. It takes the type from the expression so it can be any of the integer types provided by TypeProvider.

@Ruko97
Copy link
Contributor

Ruko97 commented Jun 4, 2022

It seems that signed integer was not supported in formatNumberReadable because bigint doesn't support the right shift operator. Should i replace the right shift operators with division for all types of integers, or just use division for bigint in a separate condition and keep the right shift operator for the rest of the integer types?

@cameel cameel added the low effort There is not much implementation work to be done. The task is very easy or tiny. label Sep 26, 2022
@cameel cameel added low impact Changes are not very noticeable or potential benefits are limited. nice to have We don’t see a good reason not to have it but won’t go out of our way to implement it. labels Sep 26, 2022
@cameel cameel added good first issue candidate Could be a "good first issue" but something is blocking it or it has open questions. and removed good first issue labels Dec 5, 2022
@cameel
Copy link
Member

cameel commented Dec 5, 2022

@nikola-matic @matheusaaguiar What's the status here? Did these merged PRs fix this issue or is there somehing left to do?

@nikola-matic
Copy link
Collaborator

@nikola-matic @matheusaaguiar What's the status here? Did these merged PRs fix this issue or is there somehing left to do?

Should be, but @matheusaaguiar spent a lot more time on this, so let's wait for him to chime in.

@matheusaaguiar
Copy link
Collaborator

The mentioned PRs have fixed this fixed this issue.

Solidity automation moved this from Implementation Backlog to Done Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy difficulty good first issue candidate Could be a "good first issue" but something is blocking it or it has open questions. low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited. nice to have We don’t see a good reason not to have it but won’t go out of our way to implement it.
Projects
No open projects
Solidity
  
Done
Development

No branches or pull requests

7 participants