1

I've been studying how ethereum works and it is really difficult (for me) to find info about how and where the storage of smart contracts is stored, that is, the data structures that live inside the smart contracts, for instace the mappings. Do they also reside inside the blocks?

And that leads me to another question: a smart contract is "killable" with the selfdestruct function, so all the data stored inside it is also destroyed? Or even simpler, we can delete an array as we can read in the docs of Solidity. This doesn't go against the principle of Blockchain "where nothing can be changed/deleted?"

Thanks in advance

0

And that leads me to another question: a smart contract is "killable" with the selfdestruct function, so all the data stored inside it is also destroyed?

This depends on the definition of destroying.

  • Smart contract state becomes inaccessible from smart contracts

  • The information is available on the archive nodes

When information has been published on a blockchain it is pretty much assumed it cannot be unpublished, without taking down all 10,000+ Ethereum nodes.

0

the data structures that live inside the smart contracts, for instace the mappings. Do they also reside inside the blocks?

No, blocks are stored in flat files in chaindata/ancient directory.

The account info (which fits within 128 bytes) is stored on disk in a structure called Merkle Patricia Trie (a tree)

// Account is the Ethereum consensus representation of accounts.
// These objects are stored in the main account trie.
type Account struct {
    Nonce    uint64
    Balance  *big.Int
    Root     common.Hash // merkle root of the storage trie
    CodeHash []byte
}

The Root field you are seeing above is the hash of the contract storage trie (another tree). For every contract there is one trie where it stores data. So, when you write in solidity :

owner = address("0xabcd.....")

what happens is that it converts the owner symbol to the hash and stores the value of the address in this contract storage trie. So, if you want to read all variables of a contract you just have to walk the trie , node by node. (but there is no API for that)

For suicide check this answer:

How selfdestruct() works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.