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

cast index string does not work #6692

Closed
2 tasks done
eunseong-theori opened this issue Jan 2, 2024 · 3 comments · Fixed by #7261
Closed
2 tasks done

cast index string does not work #6692

eunseong-theori opened this issue Jan 2, 2024 · 3 comments · Fixed by #7261
Labels
T-bug Type: bug

Comments

@eunseong-theori
Copy link

eunseong-theori commented Jan 2, 2024

Component

Cast

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (da2392e 2023-08-02T09:00:14.068523319Z)

What command(s) is the bug in?

cast index

Operating System

Linux

Describe the bug

cast index error if the key_type is a string. (https://book.getfoundry.sh/reference/cast/cast-index)

The cast index uses abi.encode to calculate slots for the mapping type (https://github.com/foundry-rs/foundry/blob/master/crates/cast/src/lib.rs#L1664C75-L1664C75), but it doesn't work for string .

abi.encodePakced works instead of abi.encode for string.

The contract code: https://arbiscan.io/address/0xA32E7eA512525B89171F3b48C7F01bD933d17c59#readContract

root@user:/home/user# cast index string "hello" 1
0x3556fc8e3c702d4479a1ab7928dd05d87508462a12f53307b5407c969223d1f8
root@user:/home/user# cast storage 0xA32E7eA512525B89171F3b48C7F01bD933d17c59 0x3556fc8e3c702d4479a1ab7928dd05d87508462a12f53307b5407c969223d1f8 -r https://arbitrum-one.publicnode.com
0x0000000000000000000000000000000000000000000000000000000000000000
root@user:/home/user# chisel
Welcome to Chisel! Type `!help` to show available commands.
➜ keccak256(abi.encodePacked("hello",uint256(1)))
Type: bytes32
└ Data: 0x8404bb4d805e9ca2bd5dd5c43a107e935c8ec393caa7851b353b3192cd5379ae
➜ 
(To exit, press Ctrl+C again)
➜ 
root@user:/home/user# cast storage 0xA32E7eA512525B89171F3b48C7F01bD933d17c59 0x8404bb4d805e9ca2bd5dd5c43a107e935c8ec393caa7851b353b3192cd5379ae -r https://arbitrum-one.publi
cnode.com
0x776f726c6400000000000000000000000000000000000000000000000000000a

This issue applies to bytes types as well as strings.

@eunseong-theori eunseong-theori added the T-bug Type: bug label Jan 2, 2024
@gakonst gakonst added this to Foundry Jan 2, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Jan 2, 2024
@mattsse
Copy link
Member

mattsse commented Jan 17, 2024

thoughts @DaniPopes ?

@rbtree-theori
Copy link

When is this gonna fixed? I'm even surprised that another person from my company already reported this like two months ago.
Also bytes is not handled in a proper way.

@mattsse
Copy link
Member

mattsse commented Feb 28, 2024

@DaniPopes mind taking a look at this?

I think strings/bytes <32 are packed? https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html#bytes-and-string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants