1

If a function call involves a memory variable, does the data in memory get added to the blockchain history?

If no, how come others can validate the transaction? Is the data only deleted after a block gets added? Doesn't that mean that when syncing the chain, I can't actually verify the results of function calls involving memory variables?

If yes (data in memory variables does get added to the blockchain history), how come memory is any cheaper than storage? And is there an easy way to access that data for a specific transaction?

1 Answer 1

0

Memory isn't persisted in the blockchain.

The memory behavior is defined in Ethereum's Yellow paper, section 9.4.1 Machine State.

Before a transaction is executed the memory is initialized to zeros and at the end of the transaction its content is discarded. All nodes will start the execution from the same initial state so at after each opcode the content of memory will be the same.

3
  • let's say sometime last year someone called a function whose only argument is a memory variable. The function pays him 1 ETH iff the supplied argument hashes to a certain value. Looking at the blockchain today, we see the person actually received 1 ETH. Is there any way for us to tell today whether the person actually supplied the right value, or whether we're looking at a blockchain with an erroneous transaction? Commented Sep 1, 2021 at 8:04
  • It's clear that memory is not added to the state of the EVM. But it seems to me that all transactions that got added to a block have to be part of the blockchain history, including function arguments declared as memory variables. Otherwise we can't verify the validity of the transaction history (see above). Right? Commented Sep 1, 2021 at 8:12
  • @JonasMetzger A transaction's input parameters are in the transaction data field that is persisted in the blockchain. Before the transaction execution the input parameters are copied to the calldata readonly memory. Solidity's memory qualifier only means the parameters will be copied from the calldata to the executable memory.
    – Ismael
    Commented Sep 1, 2021 at 15:54

Your Answer

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

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