Browse Source

Dero Stargate DVM Smart Contracts Documentation.

master
root 2 years ago
commit
4e005bb922
8 changed files with 196 additions and 0 deletions
  1. +60
    -0
      README.md
  2. +11
    -0
      dim.md
  3. +27
    -0
      function.md
  4. +6
    -0
      goto.md
  5. +8
    -0
      if.md
  6. +14
    -0
      let.md
  7. +8
    -0
      return.md
  8. +62
    -0
      support_functions

+ 60
- 0
README.md View File

@@ -0,0 +1,60 @@
# DERO Virtual Machine (DVM)

DERO Virtual Machine represents entire DERO Smart Contracts eco-system which runs on the DERO block chain.

Documentation

DVM is a decentralized platform that runs both public and private smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference.Public Smart contracts are open versions. However, the DVM is being designed to support Private Smart Contracts where everything is hidden, eg parties, and information involved. Smart Contracts are nothing but rules which apply on transacting parties.

Current version of DVM is an interpretor based system to avoid security vulneribilities, issues and compiler backdoors. This also allows easy audits of Smart Contracts for quality,bug-testing and security assurances. DVM supports a new language DVM-BASIC.

-----



DVM apps run on a from scratch custom built privacy supporting, encrypted blockchain, an enormously powerful shared global infrastructure that can move value around and represent the ownership of assets/property without leaking any information.No one knows who owns what and who transferred to whom.

* This enables developers to create puzzles, games, voting, markets, store registries of debts or promises, move funds in accordance with instructions given long in the past (like a will or a futures contract) and many other ideas/things that have not been invented yet, all without a middleman or counterparty risk.


* DVM-BASIC is a contract-oriented, high-level language for implementing smart contracts. It is influenced by GW-BASIC, Visual Basic and C and is designed to target the DERO Virtual Machine (DVM). It is very easy to program and very readable.

* DVM runs Smart Contracts which are a collection of functions written in DVM-BASIC.
These functions can be invoked over the blockchain to do something. SCs can act as libraries for other SCs.


* DVM supports number of comments formats such as ', // , /* */ as good documentation is necessary.

Example Factorial program

```
' This is a comment
// This comment is supported
/* this is multi-line comment */
Function Factorial(s Uint64) Uint64 // this is a commment
10 DIM result,scopy as Uint64 /* this is also comment */
15 LET scopy = s
20 LET result = 1
30 LET result = result * s
40 LET s = s - 1
50 IF s >= 2 THEN GOTO 30
60 PRINTF "FACTORIAL of %d = %d" scopy result
70 RETURN result
End Function
```

### DVM are written in a DVM-BASIC custom BASIC style language with line numbers.
#### DVM supports uint64 and string data-types.
#### DVM interprets the smart-contract and processes the SC line-line

* uint64 supports almost all operators namely +,-,*,/,%
* uint64 support following bitwise operators & ,|, ^, ! , >> , <<
* uint64 supports following logical operators >, >= , <, <=, == , !=

* string supports only + operator. string support concatenation with a uint64.
* string supports ==, != logical operators.

* All DVM variables are mandatory to define and are initialized to default values namely 0 and "".


A SC execution must return 0 to persist any changes made during execution. During execution, no panics should occur.

+ 11
- 0
dim.md View File

@@ -0,0 +1,11 @@
# DIM statement
DIM stands for data in memory and is used to define variable names within a function

syntax

10 DIM variable1 as type
20 DIM variable1,variable2 as type

type can be any type supported by DVM

Defining a varible initializes a variable to its ZERO value.

+ 27
- 0
function.md View File

@@ -0,0 +1,27 @@
# Function statement

Function statement is used to define a function. See eg, below for a function which adds 2 numbers

```
Function ADD(x uint64, y uint64) uint64
10 RETURN x + y
End Function

```

Function syntax is of 2 types

1. Function function_name( 0 or more arguments )
2. Function function_name( 0 or more arguments ) return type

The rules for functions are as follows
* All functions begin with Function keyword
* Function name should be alpha-numeric. If the first letter of the function is Upper case alphabet, it can be invoked by blockchain and other smart-contracts. Otherwise the function can only be called by other functions within the smart contract.
* Function may or may not have a return type
* All functions must use RETURN to return from function or to return a value. RETURN is mandatory.
* All functions must end with End Function. End Function is mandatory
* A function can have a implicit parameter value of type uint64, which contains amount of DERO value sent with the transaction.

Any error caused during processing will immediately stop execution and discard all changes that occur during SC execution.

Any Entrypoint which returns uint64 value 0 is termed as success and will make transaction to commit all state changes.

+ 6
- 0
goto.md View File

@@ -0,0 +1,6 @@
# GOTO statement
It is used to jump to any point within the function. It cannot cross function-boundary

syntax
GOTO line-number


+ 8
- 0
if.md View File

@@ -0,0 +1,8 @@
# IF
If statement is used to evaluate expression and make decisions.It has following forms
1. IF expr1 condition expr2 THEN GOTO line number
2. IF expr1 condition expr2 THEN GOTO line number ELSE GOTO line number


This is used to change execution flow based on conditions.
Conditions can be as complex expressions

+ 14
- 0
let.md View File

@@ -0,0 +1,14 @@
# LET statement
LET is used to assign a value to a variable.
value can be as complex as possible and can contain complex expression

syntax
```
line number LET variable_name = expression
```

expression can invoke other functions,eg

10 LET x = 2 + 3 + ADD(2,3)

ANY assignments within DVM can only be done using LET

+ 8
- 0
return.md View File

@@ -0,0 +1,8 @@
# RETURN statement
it is used to return from a function and can be used anywhere within a function

syntax
1. RETURN ( return nil )
2. RETURN expression ( evaluates expression and returns value )

any return value must match with the type defined while declaring function

+ 62
- 0
support_functions View File

@@ -0,0 +1,62 @@
Support Functions are inbuilt functions which provide some functionality or expose internals for speed and technical reasons.


LOAD(variable)
==============

LOAD loads a variable which was previously stored in the blockchain using STORE function. Return type will be Uint64/String depending on what is stored.
It will panic if the value does NOT exists

Uint64 EXISTS(variable)
=======================
EXISTS return 1 if the variable is store in DB and 0 otherwise

STORE(key variable, value variable)
===================================
STORE stores key and value in the DB. All storage state of the SC is accessible only from the SC which created it.

Uint64 RANDOM()
Uint64 RANDOM(limit Uin64)
============================
RANDOM returns a random using a PRNG seeded on BLID,SCID,TXID. First form gives a uint64, second form returns
random number in the range 0 - (limit), 0 is inclusive, limit is exclusive

String SCID()
==============
Returns SMART CONTRACT ID which is currently running

String BLID()
==============
Returns current BLOCK ID which contains current execution-in-progress TXID

String TXID()
=============
Returns current TXID which is execution-in-progress.

Uint64 BLOCK_HEIGHT()
=====================
Returns current chain height of BLID()

Uint64 BLOCK_TOPOHEIGHT()
===========================
Returns current topoheight of BLID()

String SIGNER()
=================
Returns address of who signed this transaction

Uint64 IS_ADDRESS_VALID(p String)
=================================
Returns 1 is address is valid, 0 otherwise


String ADDRESS_RAW(p String)
============================
Returns address in RAW form as 64 byte keys, stripping away textual/presentation form. 2 address should always be compared in RAW form

SEND_DERO_TO_ADDRESS(a String, amount Uint64)
==============================================
Sends amount DERO from SC DERO balance to a address. address must in string form DERO/DETO form
If the SC does not have enough balance, it will panic



Loading…
Cancel
Save