Giter VIP home page Giter VIP logo

plasma-research's Introduction

plasma-research Build Status Go Report Card

That repo contains docs and code snippets related to BANKEX Plasma implementation. At the moment we focused on implementation of plasma cashflow model improved by zk-S[NT]ARK exclusion proofs for history compression

History compression with zk-S[NT]ARK exclusion proofs

At the moment when plasma user is getting a transfer from another user, he wants to ensure that the history of that transfer is valid. To do that ask other parties to provide exclusion proof for the particular slice that was transferred on most of the published plasma blocks. The size of such exclusion proof based on Merkle proof grows excessively, during the plasma lifetime. That problem was described here.

In our implementation, we are going to use S[NT]ARK exclusion proofs to compress it. You can find more details here

Multiassets plasma

By Multi-asset we mean support of deposit, withdraw, transfer and exchange of a wide range of Ethereum tokens standards like ERC20, ERC721, ERC888, etc.. as well as Ethereum it self

To support that we are going to implement the more sophisticated parent smart contract that will be able to take ownership of different tokens types.

Plasma parent contract can't guarantee that actual token contract is implemented safely and fully correctly. It means that end user should check that token contract he was offered doesn't have a backdors or bugs in the implementation by himself.

Each token type that was deposit to plasma smart contract will get a unique id. That id will be used further in the transactions to describe transfer and exchange operations.

To implement an exchange operation, we need a single transaction signed by both parties. The protocol that will allow users to share transactions for signatures will be mainly implemented in the plasma client.

All the research we do, we going to document in the form of Yellow Paper. At the moment we have following separate docs that cover different parts of our application:

plasma-research's People

Contributors

artall64 avatar enorage avatar k06a avatar krboktv avatar patsak avatar poma avatar prazd avatar snjax avatar sokel avatar v57 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plasma-research's Issues

Solidity library OrderedLinkedList

  • Use library with struct and all internal methods
  • Allow to add ranges (check order and collisions)
  • Allow to remove ranges (check existence)

Develop block assembler

  • reliable timer
  • efficient tx gathering
  • upload to storage
  • upload to contract
  • make sure that service works reliably even if it fails at any point
  • write tests

CLI tools

Try CLI tools to choose a suitable package

Plasma Assets (Deposits + Withdrawals)

Depends from #41

Deposit method for ETH:

function deposit(
    OrderedLinkedListItem depositSlot
) external payable returns(bool);

Deposit method for ERC20+ERC721:

function depositToken(
    OrderedLinkedListItem depositSlot,
    address from,
    uint amountOrTokenId
) external returns(bool);

See exit game method signatures: https://hackmd.io/FaKQ5Jc1Qg6rQ3a8xcPj_Q#Exit-game

function withdrawalBegin(
    Input point,  
    RSAInclusionProof proof
) external payable returns (bool);

function withdrawalChallangeSpend(
    ExitState state, 
    Transaction tx,
    uint64 blockIndex,
    SumMerkleProof[] txProof, // serialized to bytes
    uint8 spendIndex,
    RSAInclusionProof spendInclusionProof
) external returns (bool);

function withdrawalChallangeExistance(
    ExitState state,
    SumMerkleProof txProof,
    MerkleProof inputProof, 
    uint64 maxBlockIndex,
    MerkleProof maxBlockIndexProof
) external returns (bool);
    
function withdrawalEnd(
    ExitState state
) external returns (bool);

webswift3 error

try CCCryptorFinal(cryptor, &outBytes + outLength, outBytes.count, &outLength).check()

Develop tx processor

  • Check that transaction is well formed using common go lib
  • Write tx to FDB
  • add http endpoints
  • write tests
  • protect from block overflow

Block Structure

Block Header

{
	blockNumber (uint32),
	previousBlockHash (uint256),
	merkleRoot (uint256),
	signature (65 bytes secp256k1),
	rootMerkleHash (uint256, based on keccak256)
	transactions: Array<Transaction>
}
  1. First qu
    merkleRoot (uint256) and rootMerkleHash (uint256, based on keccak256)

Solidity PLASMA assetId abstraction

For ERC20:

assetId == address

For ERC721:

assetId == keccak256(address,tokenId)
  • Maybe need to store recovery for ERC721 assetId => (address,tokenId)

Solidity PLASMA exit queue

Plasma exit queue is the queue of tuples (uint hash, uint SFT, address next) ordered by SFT.

We need to construct the queue with last element border (tail element's SFT is infinity) and first element border (first element's SFT is zero) and the following methods:

function _insert(address posBefore, uint hash, uint SFT) private returns (bool);
function _remove(address posBefore, address posCurrent) private returns (bool);

The contract must check that the queue is still sorted after element insertion complete.

Solidity PLASMA deposits

Depends on #30

  • No need to write in smart contract storage who and how many deposited, use events.
  • Maybe no need to store even total amounts of tokens

Example impl:

function deposit(address beneficiary) public payable {
    emit EtherDeposited(msg.sender, beneficiary, msg.value);
}

function depositERC20(IERC20 token, uint256 amount, address beneficiary) public payable {
    // ***
    emit ERC20Deposited(token, msg.sender, beneficiary, amount);
}

function depositERC721(IERC721 token, uint256 tokenId, address beneficiary) public payable {
    // ***
    emit ERC721Deposited(token, msg.sender, beneficiary, tokenId, assetId);
}

Basic ethereum interaction

In hardcode branch we've started work on infrastructure for plasma prime. We need to add:

  1. Add ethereum account private key as a parameter of the app
  2. Add gourutine that will periodically request ethereum balance and store it in the internal variable
  3. Add Http handler for the client that will return current Ethereum connection status - Should return be set to false and return error description if last get balance request was failed

Implement merke tree utils in Go

We need Merkle Tree utils that are compatible with our solidity implementation, the reference implementation is available in plasma-research\software\smartContract\test\helpers\merkletree.js

Setup new structure of the github repo

We will work on 4 projects in 4 branches:

  • Verifier
  • Operator
  • Commons
  • Smart contract

Common brach will we be included in other branches as the orphan branch.
All of them will be merged into the branch

Research custom options of LevelDB

Calculate the volume of one block and the number of blocks to write to leveldb and find the most effective property values ​​in leveldb.

Options:

  1. BlockCacheCapacity
  2. BlockRestartInterval
  3. BlockSize
  4. WriteBuffer

Solidity PLASMA withdrawals

Depends on #30

Block structure for solidity

Cut hashes up to 160 bits. It provides us 80bit reliability.

struct MerkleProof {
    uint160 from,
    bytes proof,
    uint index
}

Use following structure of transactions:

plasma block

Merkle proof index bit map

  1. 32 bits for block to tx merkle proof
  2. 1 bit for tx netto proof (must be zero for outputs, inputs, max_blockid and must be one for signatures)
  3. 5 bits for merkle proof for outputs, inputs and max_block_id
  4. 3 bits for merkle proof for signatures.

So, maximal outputNumber is limited by 31 (must checked on the contract for input structures).

Data types encoding

leaf = keccak256(concat(datatype_byte, abi.encode(data))

Simple exit challenges

Use following requests:


struct SimpleExit {
  Input point
}

struct ExitQueueItem {
  uint160 exitHash,
  uint SFT
}


function withdrawal(Input point, address queuePtr) external payable returns (bool);

function withdrawalChallangeSpend(SimpleExit exit, address queuePtr, 
    Input spend, MerkleProof txProof, MerkleProof spendProof, 
    uint32 maxBlockId, MerkleProof maxBlockIdProof,
    Signature sign, MerkleProof signProof) external returns (bool);

function withdrawalChallangeBlock(SimpleExit exit, address queuePtr, MerkleProof proof) external returns (bool);
  1. Somebody published exit and the bond. We check the validity of input on the contract and put it into the exit queue with finalization time ordered by SFT = max(now+REP+MFT, input.timestamp+MFT), where REP=MFT=1 week. Also withdrawal emit SFT in event.
  2. anybody can challenge the spend of the input.
  3. anybody can challenge the existence of input inside the blockchain.

Signer guarantees validity of the transaction (or he have a risk to burn his money). That's why it is enough to check the signature and maxBlockId to run withdrawalChallangeSpend.

2nd, 3rd, 4th merkle proof are short (linked to tx hash, not to block hash).
.

UX for simple withdraw

  1. Somebody published exit and the bond. We check the validity of input on the contract and put it into the exit queue with finalization time ordered by SFT = max(now+REP+MFT, input.timestamp+MFT), where REP=MFT=1 week
  2. anybody can challenge the spend of the input.
  3. anybody can challenge the existence of input inside the blockchain.

If the input is challenged, it must be removed from the exit queue.
After finalization time the exit must be withdrawable in the queue order.

We must not store all information for the exit inside the storage. (hash, SFT) is enough to store, where hash is the hash of Input.

ux schema

implement PrimeHash game for plasma prime

PrimeHash game for Plasma Prime

We need to use the mapping between integers and prime numbers for some cases in Plasma Prime:

  • calculating $H_{prime}$ for Wesolowski proof
  • calculating prime numbers for each coin

Also, it will be useful if we can use it without any precomputations in lazy mode.
I propose to use something like truebit protocol for deterministic mapping any uint256 number (excluding 0 and 1) to a prime number.

Let's determine
$ Prime(I) := \max(n: 1 < n \leq I; n \in P) $.

We do not use any better computable subsets in the set of prime numbers, because it brings us additional work in the contract, as you can see below. $Prime(I)$ is not complicated to compute offchain for any 256bit I (not only PC but also cell phones are OK).

We can enumerate all plasma dust coins as $Prime(I*offset)$ and use not only $2^{40}$, but also $2^{50}$ or more dust coins and do not need to store the data anywhere.

Also we can use $PrimeHash(x) := Prime(keccak256(x))$ for $H_{prime}$ calculation.

For onchain cases let's use the game:

prime game

The game is simply generalizable for calculation with multiple prime numbers (it is enough to challenge one value to reject the calculation).

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.