barryWhiteHat
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
4
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# plookup for execution transcript creation in zkevm ## Intro Byte code is hard to move to snark. one reason is jumps because each opcode can jump to any other there needs to be a way to follow these jumps in the circuit. One approch requies adding opcdoes for proving an opcode is in an accumulator. This costs alot of constriatns with 1000s requried per step for this. To over come this we use plookup to allow the prover to select any order of opcodes they want. Then we check each opcode against a program counter in the evm proof to ensure the selected order is correct. plookup lets you prove that the elements of f are also containted in t. For example if `t = [1,2,3,4]` and `f = [1,2,3]` this will pass a plookup check but `t = [1,2,3,4]` and `f = [1,2,5]` would not because 5 is not in t. This can be tought of as a way of doing ``` python for element in f: assert(element in t) ``` Repeats are allowed and it costs ~ 1 constirant per check once you do enough checks to overcome the constant cost. ## Deployment time At deployment time a user supplies ``` opcodes = [add, mul, jump, add , mul, jumpdest, term] ``` We take these opcodes , add an index to each and this is our table t we call this `t_opcodes`. ``` t_opcodes = [0add, 1mul, 2jump, 3add, 4mul, 5jumpdest, 6term] ``` ## State proof During our state proof stage we allow the prover to select any opcodes from our t_opcodes. We don't check validity here but will check later. So we have selected opcodes execution_opcodes = [0add, 1mul, 2jump, 5jumpdest, 6term] ## execution proof In our execution proof we require that the index of the first opcode is 0. This is to ensure that we don't jump into the middle of the byte code skipping some checks. Then each time we incrament our program counter we check that the index of the next opcode matches it. This way we can jumpt forward or backwards and repeat opcodes. ```python= def execution_proof(execution_opcodes): program_counter = 0 for i, opcode in execution_opcodes: assert(program_counter == i) # execute the current opcode and get the next one to execute next_opcode = execute(opcode) program_counter = next_opcode ``` ## Why is this secure This is secure because even tho they prover can select any opcode they can only select one opcode for any index. This means that they cannot skip an opcode because the index will not match the program counter. Also they cannot add an opcode that does not belong there because then the program counter will be less than the index of that opcode. ## Repeat opcodes Lets say we have a while loop defined in bytecode t_opcodes = [0add, 1mul, 2jump, 3jumpdest, 4mul, 5jumpi, 6term, 7jumpdest, 8add, 9jump] Where we do 0add, 1mul, 2jump (to index 7), add, jump to index 3 ,mul if stack[0] == 1 jump to index 6 else term. This is a kind of while loop where we continue multiplying the first two stack elements until stack[0] == 0 then we exit. So how does this work with plookup. Our prover calculates how many times our while loop needs to be executed and contructs our execution trace based upon this many iterations. This can be variable depending upon how many iterations are required. For example lets say we do for 4 iteraction execution_opcodes = [0add, 1mul, 2jump, 7jumpdest, 8add, 9jump, 3jumpdest, 4mul , 5jumpi, 3jumpdest, 4mul , 5jumpi, 3jumpdest, 4mul , 5jumpi, 3jumpdest, 4mul , 5jumpi, term ] This works really well in our evm proof. The opcodes for our execution proof get turned on and we only need to worry about the ones that are turned on. Our prover helps by giving these opocdes in order. But they can't cheat because we check every index and opcode in the evm proof. ## Can we do this on the opcode level? Some opcodes are actually multiple opcodes. For example add is 4 opcodes really 1. pop first element from stack 2. pop second element from stack 3. add the elements together 4. push the result onto the stack. t_opcodes= [0add,1term] We then add a concept of opcode_counter (similar to program_counter) to our constrataint selector polynomial. execution_opcodes = [0add, 0add, 0add, 0add] ```python= def execution_proof(execution_opcodes): program_counter = 0 opcode_counter = 0 for i, opcode in execution_opcodes: assert(program_counter == i) # execute the current opcode and get the next one to execute next_opcode, opcode_counter = execute(opcode, opcode_counter) program_counter = next_opcode ``` Then during our execute add we update opcode_counter 3 times and then finally update program_counter when we execute the final step of addition. ### Another example: returndatacopy returndatacopy is a difficult opcode to support because the number of iteractions depends upon the size of the return data which is variable. to support this we use a similar trick that we do with add but have a variable check rather than a constarnt 4 repeats. ```python= def execution_proof(execution_opcodes): program_counter = 0 opcode_counter = 0 for i, opcode in execution_opcodes: assert(program_counter == i) # execute the current opcode and get the next one to execute next_opcode, opcode_counter = execute(opcode, opcode_counter) if (opcode_counter == returndatasize): program_counter += 1 ``` Now we can repeat returndatacopy until all of the data has been copied onto the stack. We have the prover provide the number of repeats we need and the evm proof just verifies this was enough to copy all the data. ### Another example : hash function A very annoying thing about hash functions is that they take many more constraints in zkp than any of our other opcodes. So if we were to include them we would have to add constant overhead to every other opcodes. We can avoid this by using a similar trick that we use with add. Just repeat the round of the hash function until everything has been executed.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

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.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully