-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,049 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "973f8632", | ||
"metadata": {}, | ||
"source": [ | ||
"# EVM State" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "784a59d7", | ||
"metadata": {}, | ||
"source": [ | ||
"The EVM is a state machine. A valid Ethereum program or valid bytecode can manipulate that state." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "200c45d3", | ||
"metadata": {}, | ||
"source": [ | ||
"A specific opcode is an operation that manipulates that state." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "36a04101", | ||
"metadata": {}, | ||
"source": [ | ||
"### Program Counter (pc)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ce9fe248", | ||
"metadata": {}, | ||
"source": [ | ||
"The program counter points to the next opcode that the EVM is going to execute." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8bd37067", | ||
"metadata": {}, | ||
"source": [ | ||
"### Stack / Memory / Storage" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a8d57b1b", | ||
"metadata": {}, | ||
"source": [ | ||
"All of them are part of the EVM state. And are the areas where the EVM manipulates and stores data." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "19633bd5", | ||
"metadata": {}, | ||
"source": [ | ||
"### Program" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "05ec82bf", | ||
"metadata": {}, | ||
"source": [ | ||
"This is where we store the bytecode of the current program. It can not change during execution, which makes it immutable." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9776396a", | ||
"metadata": {}, | ||
"source": [ | ||
"### Sender" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "eaac339b", | ||
"metadata": {}, | ||
"source": [ | ||
"Address of the account currently executing this program. Equivalent to `msg.sender` in Solidity." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "eea13249", | ||
"metadata": {}, | ||
"source": [ | ||
"### Program" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5347aaca", | ||
"metadata": {}, | ||
"source": [ | ||
"This is where we store the bytecode of the current program. It can not change during execution, which makes it immutable." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e07bf794", | ||
"metadata": {}, | ||
"source": [ | ||
"### Gas" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6c61487c", | ||
"metadata": {}, | ||
"source": [ | ||
"We need to keep track how much gas we currently have and how much we already consumed. Most opcodes make the gas counter go down." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8b45b305", | ||
"metadata": {}, | ||
"source": [ | ||
"### Value" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a52bd4e8", | ||
"metadata": {}, | ||
"source": [ | ||
"How much Ether (wei) this current execution can consume." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5abc90e8", | ||
"metadata": {}, | ||
"source": [ | ||
"### Calldata" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0d427d61", | ||
"metadata": {}, | ||
"source": [ | ||
"Is the input to our program." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "85538f4f", | ||
"metadata": {}, | ||
"source": [ | ||
"### Flags" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "38d9e555", | ||
"metadata": {}, | ||
"source": [ | ||
"We are going to keep track of two flags. The `stop_flag` and `revert_flag`. If one of them is `True` the current execution is going to stop." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "446fb931", | ||
"metadata": {}, | ||
"source": [ | ||
"### Returndata" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d39d4223", | ||
"metadata": {}, | ||
"source": [ | ||
"The EVM can return data after execution. We store this data in `return`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0f5076db", | ||
"metadata": {}, | ||
"source": [ | ||
"### Logs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e90bba27", | ||
"metadata": {}, | ||
"source": [ | ||
"There are several opcodes that emit logs when executed. The result of these logs is saved here." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "ac69f3ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class State:\n", | ||
" def __init__(self,\n", | ||
" sender,\n", | ||
" program,\n", | ||
" gas,\n", | ||
" value,\n", | ||
" calldata=[]):\n", | ||
" self.pc = 0\n", | ||
" \n", | ||
" self.stack = Stack()\n", | ||
" self.memory = Memory()\n", | ||
" self.storage = Storage()\n", | ||
" \n", | ||
" self.sender = sender\n", | ||
" self.program = program\n", | ||
" self.gas = gas\n", | ||
" self.value = value\n", | ||
" self.calldata = calldata\n", | ||
" \n", | ||
" self.stop_flag = False\n", | ||
" self.revert_flag = False\n", | ||
" \n", | ||
" self.returndata = []\n", | ||
" self.logs = []" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.