[][src]Crate ovmi

ovmi

This library allows Predicate to be loaded in binary format and their functions invoked.

Introduction

Predicate is a DSL for resolving Layer 2 dispute logic, and the Optimistic Virtual Machine gives simulated environment by Predicate.

There are several types of Predicate, each of which has an interface that looks like this.

Atomic Predicate

  • decideTrue
  • decide

CompiledPredicate

  • payoutContractAddress
  • isValidChallenge
  • getChild
  • decide
  • decideTrue
  • decideWithWitness

DecidablePredicate

  • decideWithWitness

LogicalConnective

  • isValidChallenge

Each of these definitions can be imported and exported.

OVM does not manage the state, but it can be called externally.

Loading and Validation

Before execution, a module must be validated. This process checks that the module is well-formed and makes only allowed operations.

You can get the binary of predicate from json. The json format is refer to: https://github.com/cryptoeconomicslab/wakkanay/blob/master/packages/ovm-transpiler/src/CompiledPredicate.ts

This example is not tested
use ovmi::prepare;
let compiled_predicate = prepare::compile_from_json("<compiled_predicate_json>").unwrap();
let binary_predicate = compiled_predicate::encode();

if let Err(err) = prepare::validate(binary_predicate) {
    panic!(err);
}

Set external environments and.

Example) Compiled Predicate Execute

This example is not tested
use ovmi::prepare;

type AccountId = u64;

// Setting External environment.
struct MockExternalCall{..};
impl ExternalCall for MockExternalCall {
    ...
}

fn call_execute(inputs: Vec<Vec<u8>>, inputs: PredicateCallInputs<AccountId>) -> ExecResult<AccountId> {
    let compiled_predicate = prepare::compile_from_json("<compiled_predicate_json>").unwrap();
    let (payout, address_input, bytes_inputs) = prepare::parse_inputs(inputs);
    let ext = MockExternalCall{..};
    let executable = prepare::executable_from_compiled(
        &mut ext,
        code: compiled_predicate,
        payout,
        address_inputs,
        bytes_inputs,
    );
    // execute and return value.
    CompiledExecutor::execute(&executable, inputs)
}

Example) Logical Connective Predicate Execute

This example is not tested
use ovmi::prepare;

type AccountId = u64;

// Setting External environment.
struct MockExternalCall{..};
impl ExternalCall for MockExternalCall {
    ...
}

fn call_execute(address: AccountId, inputs: PredicateCallInputs<AccountId>) -> ExecResult<AccountId> {
    let ext = MockExternalCall{..};
    let executable = prepare::logical_connective_executable_from_address(
        &mut ext,
        address,
    );
    // execute and return value.
    LogicalConnectiveExecutor::execute(&executable, inputs)
}

Re-exports

pub extern crate alloc;
pub use compiled_predicates::CompiledPredicate;
pub use prepare::compile_from_json;

Modules

compiled_predicates
executor
predicates

Executable Predicates.

prepare

Macros

require
require_with_message

Structs

AccountId

An opaque 32-byte cryptographic identifier.

Range

An opaque Range(u128, u128).