0

I have several smart contracts which needs to be added on genesis.json file. The smart contract contains arrays, and mappings (from uint and address to struct). The struct contains strings and several uint numbers.

These contracts are regularly updated, and we need to regenerate storage slot accordingly. Based on solidity documentation, ( https://docs.soliditylang.org/en/v0.8.13/internals/layout_in_storage.html ) we are currently manually observing the properties present in smart contract and calculating possible values of storage slots and writing it to genesis file. Position of variables and length of strings are hardcoded to simplify the process.

Is there an approach to dynamically generate storage for a given smart contract. Use of hardhat, local blockchain, geth or libraries like etherjs is also possible to add, if required.

ashu
  • 1,197
  • 2
  • 14
  • 30

2 Answers2

0

The contents of genesis.json determine the state of the first block. Other blocks only contain stage changes - and by iterating one block after another the node calculates the current state.

So if you change the genesis file after the network was already initialized (the first block was produced), it doesn't have effect on the current state because the genesis was already processed.


Having said that, some emulators allow you to override the current state using non-standardized methods of these emulators.

For example Hardhat setStorageAt or Ganache setAccountStorageAt.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • Yes, but we are in development of private blockchain network, which is not yet deployed to production. So we simply reboot the chain after deleting the datadir folder. What we need is something to support our development so we can automate process of genesis generation – ashu Jun 13 '23 at 10:47
0

You can create the contracts storage dump with 0xweb tool.

npm i 0xweb -g
0xweb c dump 0x<contract> \
    --sources path/to/solidity/file.sol \
    --output dumps/my-contract \
    --endpoint http://127.0.0.1:8485

The file dumps/my-contract.csv will contain slot-value data, smth. like:

0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000009e545e3c0baab3e08cdfd552c960a1050f373042
0x00001180cffa4a5305cd3dd3b4663c2ba1e10800f30bb94f3db08d33face04d0, 0x0000000000000000000000000000000000000000000000000000000000000005
...

And it will be trivial with the additional script to get the values and save them to genesis.json

tenbits
  • 7,568
  • 5
  • 34
  • 53