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

docs(chisel): document uint256 cast quirk of abi.encode(1-2) causing wrap-around instead of -1 as int256 #1287

Open
2 tasks done
zitup opened this issue Aug 20, 2024 · 4 comments
Labels
A-chisel Area: chisel good first issue Good for newcomers T-new Type: new docs

Comments

@zitup
Copy link

zitup commented Aug 20, 2024

Component

Chisel

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

0.2.0

What command(s) is the bug in?

1 - 2

Operating System

macOS (Intel)

Describe the bug

The result of 1 - 2 in Chisel is the max value of uint256, but it's -1 in forge test or remix.

Solc version is 0.8.26.

@zitup zitup added the T-to-fix Type: issue in docs label Aug 20, 2024
@zitup zitup changed the title bug: incorrect result of 1 - 2 in Chisel bug[Chisel]: incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug[Chisel]: incorrect result of 1 - 2 bug[Chisel]: incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug[Chisel]: incorrect result of 1 - 2 bug[Chisel]: incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug[Chisel]: incorrect result of 1 - 2 bug(Chisel): incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug(Chisel): incorrect result of 1 - 2 bug([Chisel]): incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug([Chisel]): incorrect result of 1 - 2 bug[Chisel]: incorrect result of 1 - 2 Aug 20, 2024
@zitup zitup changed the title bug[Chisel]: incorrect result of 1 - 2 bug(Chisel): incorrect result of 1 - 2 Aug 20, 2024
@mattsse
Copy link
Member

mattsse commented Aug 20, 2024

but it's -1 in forge test or remix.

this can't be for uint256, if you do 1 - 2 then a signed type is inferred.

this might be a limitation due to how the chisel interpreter works, which will use abi.encode(1-2)

@zitup
Copy link
Author

zitup commented Aug 22, 2024

maybe we should find a way to avoid it, after all, it is inconsistent with the compiler's behavior

@zerosnacks zerosnacks changed the title bug(Chisel): incorrect result of 1 - 2 bug(chisel): incorrect result of evaluation of 1 - 2 Aug 23, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Aug 26, 2024

For additional context: int256(1) - int256(2) (or int256(1) - 2)) in Chisel does correctly yield -1. This seems to be related to 1 and 2 being cast to uint256 by default and then correctly wrapping around.

I think this ticket can be resolved by documenting this quirk in the Foundry Book: https://book.getfoundry.sh/reference/chisel/

Beyond that I don't see a point of action here

@zerosnacks zerosnacks added the good first issue Good for newcomers label Aug 26, 2024
@zerosnacks zerosnacks changed the title bug(chisel): incorrect result of evaluation of 1 - 2 docs(chisel): document uint256 cast quirk of abi.encode(1-2) causing wrap-around instead of -1 as int256 Aug 26, 2024
@zitup
Copy link
Author

zitup commented Aug 27, 2024

For additional context: int256(1) - int256(2) (or int256(1) - 2)) in Chisel does correctly yield -1. This seems to be related to 1 and 2 being cast to uint256 by default and then correctly wrapping around.

I think this ticket can be resolved by documenting this quirk in the Foundry Book: https://book.getfoundry.sh/reference/chisel/

Beyond that I don't see a point of action here

What I think is chisel should be as consistent with evm as possible 🤔

@zerosnacks zerosnacks transferred this issue from foundry-rs/foundry Sep 12, 2024
@zerosnacks zerosnacks added T-new Type: new docs A-chisel Area: chisel and removed T-to-fix Type: issue in docs labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-chisel Area: chisel good first issue Good for newcomers T-new Type: new docs
Projects
No open projects
Status: Todo
Development

No branches or pull requests

3 participants