1

Recently, I studied about EVM storage and LevelDB as a state database. And here's my question. I'm confused about relationship between levelDB and EVM storage. When a transaction that activates a specific smart contract is generated, the EVM uses the CA's codeHash value to find the corresponding contract in levelDB and does the state variable information of the contract enter the storage of the EVM?? And when the transaction ends, is the storage of EVM updated again with the contract information of the new transaction?? If so, what does it mean to say that EVM storage are persistent? Can anyone tell me what happens in levelDB and EVM storage when a transaction that changes the smart contract's state variable occurs?

1 Answer 1

0

LevelDB is a key-value database. It is an implementation detail of the go-ethereum client.

The "Ethereum World State" (EWS) for each address has its balance, nonce, bytecode's hash, storage's root. Geth uses LevelDB to store the EWS.

When a contract is executed it uses the bytecode hash to load the contract, and the storage's root to load the contract storage.

If the execution has completed successfully the entry of the contract in EWS is updated with new storage's root.

2
  • Thanks for the reply. Then there is no virtual space called "storage" on the EVM?? When I say "virtual space" here, I mean the virtual space implemented as code, such as EVM memory and EVM stack. I wonder if I have the wrong concept. I thought there was a space called "storage" on the EVM as well. However, looking at the go-ethereum/core/vm repo below, there is memory and stack, but no storage. That's why I asked... github.com/ethereum/go-ethereum/tree/master/core/vm May 26 at 10:42
  • @the.ETHEREUM Each contract has its own storage, a key-value database. Look at the opSstore and opSload in github.com/ethereum/go-ethereum/blob/master/core/vm/….
    – Ismael
    May 27 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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