Code Monkey home page Code Monkey logo

godwoken-polyjuice's Introduction

Godwoken polyjuice

An Ethereum compatible backend for Godwoken rollup framework. It include generator and validator implementations.

Features

  • All op codes
  • Value transfer
  • pre-compiled contracts
    • ecrecover
    • sha256hash
    • ripemd160hash
    • dataCopy
    • bigModExp
    • bn256AddIstanbul
    • bn256ScalarMulIstanbul
    • bn256PairingIstanbul (performance issue)
    • blake2F

Data Structures

Polyjuice arguments

header     : [u8; 8]  (header[0]    = 0xff, 
                       header[1]    = 0xff, 
                       header[2]    = 0xff, 
                       header[3..7] = "POLY"
                       header[7]    = call_kind { 0: CALL, 3: CREATE })
gas_limit  : u64      (little endian)
gas_price  : u128     (little endian)
value      : u128     (little endian)
input_size : u32      (little endian)
input_data : [u8; input_size]   (input data)

Every polyjuice argument fields must been serialized one by one and put into godwoken RawL2Transaction.args for polyjuice to read. If the input_data have 56 bytes, then the serialized data size is 8 + 8 + 16 + 16 + 4 + 56 = 108 bytes.

Creator account script

code_hash: polyjuice_validator_type_script_hash
hash_type: type
args:
    rollup_type_hash : [u8; 32]
    sudt_id          : u32          (little endian, the token id)

Polyjuice creator account is a godwoken account for creating polyjuice contract account. This account can only been created by meta contract, and the account id is used as the chain id in polyjuice. The sudt_id field in script args is the sudt token current polyjuice instance bind to.

Contract account script

code_hash: polyjuice_validator_type_script_hash
hash_type: type
args:
    rollup_type_hash   : [u8; 32]
    creator_account_id : u32        (little endian, also chain id, and for reading 'sudt_id' from creator account script)
    info_data_hash     : [u8; 20]   (The information to be hashed is depend on how the account been created: [normal, create2], 
                                      the 20 bytes value is keccak256(info_data)[12..])

Normal contract account script

info_content:
    sender_address  : [u8; 20]   (the msg.sender: blake128(sender_script) + account id)
    sender_nonce    : u32 
    
info_data: rlp_encode(sender_address, sender_nonce)

The polyjuice contract account created in polyjuice by CREATE call kind or op code.

Create2 contract account script

info_data:
    special_byte    : u8         (value is '0xff', refer to ethereum)
    sender_address  : [u8; 20]   (the msg.sender: blake128(sender_script) + account id)
    create2_salt    : [u8; 32]   (create2 salt)
    init_code_hash  : [u8; 32]   (keccak256(init_code))

The polyjuice contract account created in polyjuice by CREATE2 op code.

Address used in polyjuice

The address used in polyjuice are all godwoken short address, which is:

short_address = blake2b(script.as_slice())[0..20]

More docs

godwoken-polyjuice's People

Contributors

thewawar avatar floustar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.