Replies: 1 comment 6 replies
-
Unfortunately, you likely cannot do things this way. The struct structure used in storage is not necessarily ABI encoded, so simply fetching those values will generally not work in all cases. You will need to either use (and possibly add) getters to the contract or replicate all the complex Solidity decoding yourself. Here is the info on how bytes and strings are placed in storage: https://docs.soliditylang.org/en/v0.8.17/internals/layout_in_storage.html?highlight=Storage#bytes-and-string This is because the cost of storage is astronomical, so a little extra logic to save a word here and there matter. But it does mean you need a translation layer, which solidity automatically creates. Does that make sense? And answer the question? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First, I saw the other discussion, which was very similar to this one here #2373 however, that was in regards to other variables being packed unrelated to the current struct. Because this is dynamically allocated storage, that should not be an issue.
I have written a base hardhat project for doing the Ethernaut challenges, and one of the things I wrote was a function called fetchInstance which would automatically find your instance address based on the level address. Unfortunately, because of how OpenZeppelin wrote their Ethernaut contract, I have to read private storage to do this. There is a mapping of addresses to a struct
and I used the AbiCoder to decode the struct. The code I wrote initially was working fine for both completed and incomplete levels but suddenly, it started erroring out for certain instances. I have included a minimum example of a good and bad instance that I am trying to decode.
Here is that example code:
So two questions, what is the proper way to decode that struct, and second why does it need three bytes32 strings when it should be entirely packed in two storage slots?
Beta Was this translation helpful? Give feedback.
All reactions