foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Cast 2d \ 2h not returning consistent results

Open RonTuretzky opened this issue 10 months ago • 0 comments

Component

Cast

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

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (f625d0f 2024-04-02T00:16:42.810315000Z)

What command(s) is the bug in?

cast 2d \ 2h

Operating System

macOS (Intel)

Describe the bug

cast 2d 0x09845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c returns 4304691653437447671144768329537717612774901428585623103913861666989519717164 however cast 2h 4304691653437447671144768329537717612774901428585623103913861666989519717164 returns 0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c

However, these two outputs are not equivalent,as the first starts with 0x09 and the latter starts with 0x9

This behavior is also demonstrated in python

>>> a = 0x09845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c
>>> a
4304691653437447671144768329537717612774901428585623103913861666989519717164
>>> hex(a)
'0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c'

This breaks expected behavior, for example , method 10 on this contract

(getOperatorFromId)

returns the expected value for 0x09845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c, and return null for 0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c

This is also demonstrated when using cast

❯ cast c 0xc4A6E362e8Bd89F28Eb405F9Aa533784884B9c4F "function getOperatorFromId(bytes32)"  0x09845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c -r https://holesky.drpc.org
0x00000000000000000000000042bbfc9c9d78265a96a003dd858ed96fe7d757b7

❯ cast c 0xc4A6E362e8Bd89F28Eb405F9Aa533784884B9c4F "function getOperatorFromId(bytes32)"  0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c -r https://holesky.drpc.org
Error: 
parser error:
0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c
                                                                 ^
Odd number of digits

Context:
- parser error:
0x9845e7f93d27198144355dbac3f0cdc34d74f78f40c9a37f0969a924e04c32c
                                                                 ^
Odd number of digits

RonTuretzky avatar Apr 14 '24 12:04 RonTuretzky