Skip to main content

Logic and Manifest

Logic

A logic is an executable program that is deployed on the MOI network, which holds a set of rules similar to those of a smart contract on Ethereum. It has callable endpoints that can be called through interactions.

Logics can maintain storage for a global state; they are also built to be able to operate within an individual Participant Context - a foundational principle of MOI. This essentially means that logics are built to execute rules for a participant's data - their assets, account state, etc. - rather than holding all the data centrally within its state.

Manifest

Manifest is the schema that describes your logic. It encapsulates the execution rules (bytecode) and public interface (ABI). Once a logic is deployed on the blockchain, participants can invoke its endpoints.

Coco compiler produces manifests in YAML, JSON or POLO format: here's an example.

Show full flipper.yaml file
flipper.yaml
syntax: 1
engine:
kind: PISA
flags: []
version: 0.5.1
kind: logic
elements:
- ptr: 0
kind: typedef
data: map[identifier]bool
- ptr: 1
kind: state
data:
mode: logic
fields:
- slot: 0
label: values
type: map[identifier]bool
- ptr: 2
deps:
- 1
kind: callable
data:
name: Init
mode: dynamic
kind: deploy
accepts: []
returns: []
executes:
asm:
- LLOAD $0 &0
- PMAKE $1 &1
- NOT $1 $1
- ORIGIN $2
- SETKEY $0 $2 $1
- STORE $0
catches: []
- ptr: 3
deps:
- 1
kind: callable
data:
name: Flip
mode: dynamic
kind: invoke
accepts: []
returns: []
executes:
asm:
- LLOAD $0 &0
- ORIGIN $1
- GETKEY $1 $0 $1
- NOT $1 $1
- ORIGIN $2
- SETKEY $0 $2 $1
- STORE $0
catches: []
- ptr: 4
deps:
- 1
kind: callable
data:
name: Mode
mode: static
kind: invoke
accepts: []
returns:
- slot: 0
label: value
type: bool
executes:
asm:
- LLOAD $0 &0
- ORIGIN $1
- GETKEY $1 $0 $1
- YIELD $1 &0
- DUMP $0
catches: []
- ptr: 5
deps:
- 1
kind: callable
data:
name: Set
mode: dynamic
kind: invoke
accepts:
- slot: 0
label: value
type: bool
returns: []
executes:
asm:
- LLOAD $0 &0
- OBTAIN $1 &0
- ORIGIN $2
- SETKEY $0 $2 $1
- STORE $0
catches: []
- ptr: 6
kind: callable
data:
name: Invert
mode: pure
kind: invoke
accepts:
- slot: 0
label: value
type: bool
returns:
- slot: 0
label: out
type: bool
executes:
asm:
- OBTAIN $0 &0
- NOT $0 $0
- YIELD $0 &0
catches: []

Artifact

When the logic is deployed, it's stored on the network in an encoded format called artifact that's directly executable by PISA virtual machine (MOI's VM that executes logics). Similarly, when Coco runs logics through its test environment Cocolab, Coco programs are compiled to manifests and these manifests converted to artifacts that are executed in PISA.

Artifacts are largely invisible to developers, so we're not going into further details.

Coco Compiler & Cocolab

Coco Compiler is a compiler for Coco Programming Language that compiles .coco source code into manifests. It also contains Cocolab, a local test environment that enables executing logics locally without actual deployment on MOI network.