or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
ZKEVM - Bytes Copy
In EVM, there are many opcodes able to copy some chunk of bytes from different source to stack or memory:
CALLDATALOAD
- push32
bytes from calldata as a word to stackCALLDATACOPY
- copy*
bytes from calldata to memoryCODECOPY
- copy*
bytes from current bytecode to memoryEXTCODECOPY
- copy*
bytes from external bytecode to memoryRETURNDATACOPY
- copy*
bytes from returndata to memoryJUMP
,JUMPI
- read the destination bytePUSH*
- push*
bytes from current bytecode as a word to stackSTOP
- EVM returns a implicitSTOP
in the end if program counter is increased out of range.If the requested range is out of source bound, only
RETURNDATACOPY
triggers error, others right pad the result with all zeros.CALLDATALOAD
,CALLDATACOPY
Calldata source could be:
tx_table
- when rootrw_table
- when internalSince the calldata of tx_table could be up to
≈223 (7486750)
(all zeros calldata with 30 million gas limit(30000000-53000) / 4
), in the worst case we need 3 bytes range lookup to compare if the bytes copy is out of range.CODECOPY
Bytecode source could be:
tx_table
- when root creationbytecode_table
- when call and internal creationAgain one of the source is
tx_table
, in the worst case we still need 3 bytes range lookup.EXTCODECOPY
External bytecode source could only be
bytecode_table
since it's already deployed, so the range becomes3 * 213 (0x6000)
which can be done by 2 bytes range lookup.But considering
EXTCODECOPY
is really similar toCODECOPY
, we probably handled them together.RETURNDATACOPY
Since the source is always from memory of
rw_table
, we can verify the range by 5 bytes range lookup.JUMP
,JUMPI
For the success case we don't need to worry about the range, the lookup already did for us.
However, for the out-of-range jump case, we need to verify it's indeed out of range, and the source is same as
CODECOPY
.PUSH*
We can handle this in the same way as
CODECOPY
since they have the same source.We can also try to hack on the source described in the next section.
Implicit
STOP
in the endIf we can ask Bytecode circuit to pad 33
0
in the end of each bytecode, and ask Tx circuit to also do so in the end of calldata of each transaction, then we don't need to worry about the implicitSTOP
andPUSH*
out of range.