Skip to content

Commit

Permalink
env opcodes desc
Browse files Browse the repository at this point in the history
  • Loading branch information
shafu0x committed Mar 1, 2024
1 parent 6cd6898 commit f31d22a
Show file tree
Hide file tree
Showing 6 changed files with 1,049 additions and 5 deletions.
Binary file modified _build/.doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion _build/html/searchindex.js

Large diffs are not rendered by default.

258 changes: 258 additions & 0 deletions content/.ipynb_checkpoints/05_1_state-checkpoint.ipynb
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
}
34 changes: 34 additions & 0 deletions content/05_1_state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,38 @@
"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",
Expand Down Expand Up @@ -177,6 +209,7 @@
"source": [
"class State:\n",
" def __init__(self,\n",
" sender,\n",
" program,\n",
" gas,\n",
" value,\n",
Expand All @@ -187,6 +220,7 @@
" 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",
Expand Down
Loading

0 comments on commit f31d22a

Please sign in to comment.