chronaeon / beigepaper

Rewrite of the Yellowpaper in non-Yellowpaper syntax.
MIT License
785 stars 85 forks source link

The world state is divided by blocks; each new block representing a new world state. #14

Closed aenhsaihan closed 5 years ago

aenhsaihan commented 5 years ago

I have a colleague who is refuting this statement in your paper.

His main point of contention was that the world state is a couple hundred GB in size while a block is just several MB.

Just wanted to raise the issue and get your point of view.

morenoh149 commented 5 years ago

It depends on how you define "new world state".

If you define it as combining the previous state (the chain) plus a diff (the newest block).

Or if you define it as purely the diff (the latest block).

It's probably more important to agree on how it's all working rather than debate what should be considered a new world state.

psionski commented 5 years ago

Hi, @morenoh149

I thought the world state and the chain are different things? For example the world state is "account A has 10 ETH, account B has 0 ETH", while the chain is something like "A sends 5 ETH to B" (so basically inputs to state transition functions, not state), and when nodes see this they update the (internal, implicit) world state?

The yellow paper says it like this:

Ethereum, taken as a whole, can be viewed as a transaction-based state machine: we begin with a genesis state and incrementally execute transactions to morph it into some final state.

Then further down:

The world state (state), is a mapping between addresses (160-bit identifiers) and account states (a data structure serialised as RLP, see Appendix B). Though not stored on the blockchain, it is assumed that [...]

The way it's said in your paper, seems to suggest transactions actually contain world state (or fragments thereof). This is what I found confusing...

morenoh149 commented 5 years ago

Ha this isn't my paper. I'm just a GitHub junkie.

The diagram seems to agree with @psionski that the evm world state is outside of the blockchain

So my first comment was wrong.

https://github.com/ethereumbook/ethereumbook/blob/develop/13evm.asciidoc#ethereum-state says

The world state is a mapping of Ethereum addresses (160-bit values) to accounts. At the lower level, each Ethereum address represents an account comprising an ether balance, a nonce, the account’s storage, and the account’s program code. An externally owned account will always have no code and an empty storage.

When a transaction results in smart contract code execution, an EVM is instantiated with all the information required in relation to the current block being created and the specific transaction being processed. In particular, the EVM’s program code ROM is loaded with the code of the contract account being called, the program counter is set to zero, the storage is loaded from the contract account’s storage, the memory is set to all zeros, and all the block and environment variables are set. (...) At this point, you can think of the EVM running on a sandboxed copy of the Ethereum world state, with this sandboxed version being discarded completely if execution cannot complete for whatever reason. However, if execution does complete successfully, then the real-world state is updated to match the sandboxed version, including any changes to the called contract’s storage data, any new contracts created, and any ether balance transfers that were initiated.

Note that because a smart contract can itself effectively initiate transactions, code execution is a recursive process. (...) Each instantiation has its sandbox world state initialized from the sandbox of the EVM at the level above.

chronaeon commented 5 years ago

@aenhsaihan yes, this is inaccurate. Thanks for reporting!

Thanks @morenoh149 and @psionski for furthering the discussion and educating me!

How would each of you finish this sentence?

The World State is divided [incremented?] by _____; each new ____ represents a new World State.

Can it be finished even? Or should I re-word the whole thing?

morenoh149 commented 5 years ago

I'd try The world state is a mapping of Ethereum addresses to accounts. and skip the second part.

chronaeon commented 5 years ago

Fixed in 5fd62d57896372ff0e8334aa08b32585f92037ca