---
# System prepended metadata

title: Tagion Virtual Engine

---

#  Tagion Virtual Engine

The scripting engine’s language is called Funnel. It is based on a stack machine, a simple, functional language inspired by the programming language FORTH. The scripting engine executes at different run levels. The lowest level is the total Turing equivalent and can only make conditional forward jumps; it cannot run loops or functions. The scripting engine is limited by the number of instructions executed, call stack depth, data stack depth, and memory.

The limitation is set to prevent a script from running into infinite loops. The transaction script can use a library of standard functions stored in the DART, and the fingerprint of the script, held in the Bull’s eye blockchain, which is the current state of the script.



| Run level | Description                       | Limitation                                          |
| --------- | --------------------------------- | --------------------------------------------------- |
| 0         | Consensus script                  | No limits, full Turing equivalent                   |
| 1         | Debug script function (read-only) | Limited resources, read-only call function to level 0 |
| 2         | Transaction function              | Limited resources and call function to levels 0 and 1 |
| 3          | Transaction script                        |    Limited instruction and call function to level 2                                                 |

Table 7. Runlevels for the Scripting engine

In contrast to standard FORTH, Funnel is a strictly typed language that supports the types shown in table 8. 

Converting from one type to another must be explicitly instructed via a type casting function. If the casting fails, the scripting engine generates an error, stopping the script. The scripting engine stops on overflow/underflow/divide-by-zero errors and if an operator is operating on invalid types.



| name     | Description                 | D-Type   |
| -------- | --------------------------- | -------- |
| TEXT     | UTF-8 text                  | string   |
| INTEGER  | signend 64-bits number      | long     |
| CARDINAL | Unsignend 64-bits number    | ulong    |
| BIG      | Unsigend big integer number | BigUint  |
| HiBON    | HiBON Read/Write-only       | HiBON    |
| DOCUMENT | HiBON Read only             | Document |
| BIN      | Byte arrays, used to hold keys and hash value|ubyte[]|

Table 8. Scripting types supported

##  Funnel Sample code for a test contract

```
1
2 b o ol run ( Document )
3 v a r i a b l e t r a n s o b j
4 v a r i a b l e t r a n s s c r i p o b j
5 v a r i a b l e s i g n a t u r e s
6 v a r i a b l e h a s h t r a n s s c r p o b j
7 v a r i a b l e p ayee s
8 v a r i a b l e p a y e r s
9 v a r i a b l e n o p a y e r s
10 v a r i a b l e n o s i g n a t u r e s
11 v a r i a b l e s c r i p e n g o b j
12 v a r i a b l e b i l l s
13 v a r i a b l e n o b i l l s
14
15 : l o a d t r a n s a c t i o n o b j e c t
16 t r a n s o b j !
17 t r a n s o b j @ ’ t r a n s a c t i o n s c r i p t i n g o b j e c t ’ doc@
18 t r a n s s c r i p o b j !
19 t r a n s o b j @ ’ s i g n a t u r e s ’ doc@
20 s i g n a t u r e s !
21 t r a n s s c r i p o b j @ hash256
22 h a s h t r a n s s c r p o b j !
23 t r a n s s c r i p o b j @ ’ p ayee s ’ doc@
24 p ayee s !
25 t r a n s s c r i p o b j @ ’ p a y e r s ’ doc@
26 p a y e r s !
27 p a y e r s @ length@ n o p a y e r s !
28 s i g n a t u r e s @ length@ n o s i g n a t u r e s !
29 ;
30
31 : l o a d s c r i p t i n g e n g i n e o b j e c t
32 s c r i p e n g o b j !
33 s c r i p e n g o b j @ ’ b i l l s ’ doc@
34 b i l l s !
35 b i l l s @ length@ n o b i l l s !
36 s c r i p e n g o b j @ ’ t r a n s a c t i o n o b j e c t ’ doc@
37 l o a d t r a n s a c t i o n o b j e c t
38 ;
39
40 : g e t p a y e e ow n e r k e y
41 l o c a l p a yee
42 l o c a l p a y e e s
43 l o c a l i n d e x
44 i n d e x !
45 p a y e e s !
46 p a y e e s @ i n d e x @ doc@ p a yee !
47 p a yee @9 v a r i a b l e n o p a y e r s
10 v a r i a b l e n o s i g n a t u r e s
11 v a r i a b l e s c r i p e n g o b j
12 v a r i a b l e b i l l s
13 v a r i a b l e n o b i l l s
14
15 : l o a d t r a n s a c t i o n o b j e c t
16 t r a n s o b j !
17 t r a n s o b j @ ’ t r a n s a c t i o n s c r i p t i n g o b j e c t ’ doc@
18 t r a n s s c r i p o b j !
19 t r a n s o b j @ ’ s i g n a t u r e s ’ doc@
20 s i g n a t u r e s !
21 t r a n s s c r i p o b j @ hash256
22 h a s h t r a n s s c r p o b j !
23 t r a n s s c r i p o b j @ ’ p ayee s ’ doc@
24 p ayee s !
25 t r a n s s c r i p o b j @ ’ p a y e r s ’ doc@
26 p a y e r s !
27 p a y e r s @ length@ n o p a y e r s !
28 s i g n a t u r e s @ length@ n o s i g n a t u r e s !
29 ;
30
31 : l o a d s c r i p t i n g e n g i n e o b j e c t
32 s c r i p e n g o b j !
33 s c r i p e n g o b j @ ’ b i l l s ’ doc@
34 b i l l s !
35 b i l l s @ length@ n o b i l l s !
36 s c r i p e n g o b j @ ’ t r a n s a c t i o n o b j e c t ’ doc@
37 l o a d t r a n s a c t i o n o b j e c t
38 ;
39
40 : g e t p a y e e ow n e r k e y
41 l o c a l p a yee
42 l o c a l p a y e e s
43 l o c a l i n d e x
44 i n d e x !
45 p a y e e s !
46 p a y e e s @ i n d e x @ doc@ p a yee !
47 p a yee @9 v a r i a b l e n o p a y e r s
10 v a r i a b l e n o s i g n a t u r e s
11 v a r i a b l e s c r i p e n g o b j
12 v a r i a b l e b i l l s
13 v a r i a b l e n o b i l l s
14
15 : l o a d t r a n s a c t i o n o b j e c t
16 t r a n s o b j !
17 t r a n s o b j @ ’ t r a n s a c t i o n s c r i p t i n g o b j e c t ’ doc@
18 t r a n s s c r i p o b j !
19 t r a n s o b j @ ’ s i g n a t u r e s ’ doc@
20 s i g n a t u r e s !
21 t r a n s s c r i p o b j @ hash256
22 h a s h t r a n s s c r p o b j !
23 t r a n s s c r i p o b j @ ’ p ayee s ’ doc@
24 p ayee s !
25 t r a n s s c r i p o b j @ ’ p a y e r s ’ doc@
26 p a y e r s !
27 p a y e r s @ length@ n o p a y e r s !
28 s i g n a t u r e s @ length@ n o s i g n a t u r e s !
29 ;
30
31 : l o a d s c r i p t i n g e n g i n e o b j e c t
32 s c r i p e n g o b j !
33 s c r i p e n g o b j @ ’ b i l l s ’ doc@
34 b i l l s !
35 b i l l s @ length@ n o b i l l s !
36 s c r i p e n g o b j @ ’ t r a n s a c t i o n o b j e c t ’ doc@
37 l o a d t r a n s a c t i o n o b j e c t
38 ;
39
40 : g e t p a y e e ow n e r k e y
41 l o c a l p a yee
42 l o c a l p a y e e s
43 l o c a l i n d e x
44 i n d e x !
45 p a y e e s !
46 p a y e e s @ i n d e x @ doc@ p a yee !
47 p a yee @’ ownerkey ’ doc@
48 ;

```