foundry-rs/forge-std

feat(StdStorage): support writing to packed storage slots

Open

#32 创建于 2022年3月25日

在 GitHub 查看
 (0 评论) (1 反应) (0 负责人)Solidity (1,041 star) (499 fork)user submission
enhancementhelp wanted

描述

For local development, I currently use uint256 everywhere so I can use the forge-std helpers to easily set slot values. However, eventually I want to start packing variables without these helpers and the tests breaking.

I think the easiest way to do this is to leverage the solc storage layout to get the info we need. From @brockelmore:

ye so this actually gets interesting now that i have a dynamic mapping cuz we can actually represent json directly in solidity (kek). we could add a cheatcode to get the storage layout into memory then you could pass in the layout with relative ease for a slot and know youre doing it correctly. in the short term if this is something u want and can easily provide the positioning + left and right padding we can support it

something like .packed(left, right)

where each is number of bits on the left and right

which eventually would ideally be grabbable in code via cheatcode

Since storage layout is not included by default, we either need to throw an error if the storage layout isn't present, or recompile the specified contract with that flag on the fly

For contracts that aren't local (e.g. if testing against a forked network), I think we'd be limited to only setting vars in packed slots if the contract is verified on Etherscan so we can pull the source and compile with storage layout enabled

贡献者指南