Skip to content

Commit

Permalink
doc: add memory section (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Mar 9, 2024
1 parent fa87d65 commit 77a77f1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions documentation/src/crates/interpreter/memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# EVM Memory

Is a memory localized to the current Interpreter context. Interpreter context is a call or create frame. It is used by opcodes to store or format data that are more then 32 bytes long, for example calls to format input, return output or for logs data. Revm has a shared memory between all the Interpreters but Interpreter loop only see the part it is allocated to it.

Extending memory is paid by the gas. It consumes 3 gas per word plus square of the number of words added devided by `512` (`3*N+ N^2/512`). There is no limit on the size of the memory, but it is limited by logaritmic growth of the gas cost. For 30M there is a calculated max memory of 32MB (Blog post by ramco: [Upper bound for transaction memory](https://xn--2-umb.com/22/eth-max-mem/)).

## Opcodes

Here is a list of all opcodes that are reading or writing to the memory. All read on memory can still change the memory size by extending it with zeroes. Call opcodes are specific as they read input before the call but also write their output after the call (if call is okay and there is a ouput to write) to the memory.

These opcodes read from the memory:
* RETURN
* REVERT
* LOG
* KECCAK256
* CREATE
* CREATE2
* CALL
* CALLCODE
* DELEGATECALL
* STATICCALL

These opcodes change the memory:
* EXTCODECOPY
* MLOAD
* MSTORE
* MSTORE8
* MCOPY
* CODECOPY
* CALLDATACOPY
* RETURNDATACOPY
* CALL
* CALLCODE
* DELEGATECALL
* STATICCALL

0 comments on commit 77a77f1

Please sign in to comment.