Skip to content
/ PaVM Public

The source code of PaVM, a smart contract virtual machine that supports inter- and inner-parallel execution.

Notifications You must be signed in to change notification settings

nkfyz/PaVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

PaVM

Hello there!

This repo is created for publishing the source code of PaVM, a smart contract virtual machine that supports inter- and inner-contract parallel execution.

Get started

# enable compile.sh executable
chmod +x compile.sh

# compile PaVM
./compile.sh

Introduction

Key instructions

The newly added instructions in PaVM is listed as follows:

Type Mnemonic Opcode Context
Thread control SUBSOL 0xA1
Thread control SLEEP 0xA2
Thread control REVERTT 0xA3
Data control AFTERW 0xA4
Data control AFTERR 0xA5
Data control AFTERA 0xA6
Runtime record RR 0xA7
Runtime record RPHASH 0xA8
Runtime record RDR 0xA9
Runtime record WTR 0xAA

The implementation of each instruction obeies the following code:

func op[insturction_name] (ret) {stack..}{
  // get the args from VM Stack
  // instruction specific logic
  // return value
}

New data area

PaVM provides several data areas to store the multithread-related data as follows:

  • Thread Data
  • Record Data
  • Thread State Table

The implementation of the above areas can be found in /core/vm/ folder.

Besides, PaVM also supports typical areas such as:

  • Stack
  • Persistent Storage

Enable parallel!

Key interfaces for developer

The features such as multithreading can be enabled by interfaces/keywords provided by PaVM:

image

Have a try with this demo contract:

contract WordCount {
  function count(string textSegment) {
    mapping string[int] ret;
    for(int i = 0; i < len(textSegment); i++) {
      string word = textSegment[i];
      ret[word] == NULL ? ret[word] = 0 : ret[word]++;
    }
    return ret;
}
11
12 /* Enable runtime record and hash computing in main function */
13 function rr rphash main(string text) {
14 int length = len(text);
15
16 mapping tempRet1 = subsol [1] count(text[0 : length/2]);
17 mapping tempRet2 = subsol [2] count(text[length/2 : length]);
18 sleep [1] 1000; // No.1 thread sleeps for 1000ms
19 revertt [2]; // Revert the operations made by No.2 thread
20
21 /* Join the two temporary values by embedded function */
22 return join(tempRet1, tempRet2);
23 }
24 }

About

The source code of PaVM, a smart contract virtual machine that supports inter- and inner-parallel execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages