Writing Function Tasks

Function Tasks verify and provide a transcript for the execution of serverless function code.

During Public Beta, all Function Tasks activities are performed by Truebit.

In the current version of the Function Task services, auditing of the hub during Stage 2 verification is not yet implemented. See our product roadmap for the latest updates.

Function Tasks are dispatched and verified by the Truebit Verify Hub, and executed by Truebit Verify Nodes. Function Tasks are accessed via a built-in web services interface provided by the Truebit Verify Hub, and can be called by any application using HTTP. Each Function Task recorded is documented in a transcript.

Prerequisites

There are several important considerations when writing Function Task code:

  • Execution environment: The task must run the same on any computer architecture and operating system. Therefore, Function Tasks execute in an isolated WebAssembly sandbox using our deterministic WASI implementation. See the WebAssembly section for more information.

  • No Network Calls: To provide maximum security, the execution environment does not provide network access. If you need to access data from an external source, consider using an API Task.

  • Determinism: The execution environment guarantees determinism: all Function Tasks will produce the same outputs for given inputs when executed by any Truebit Verify node.

Building a Function Task

Check the Supported Languages page to see the specific task preparation steps required for your development language

1. Write your Function Task code

The task developer will create the code following the best practices described below:

Replace network operation with filesystem reads and writes

If your program would normally read and write to network endpoints, you'll need to replace this with filesystem operations.

Random numbers

If your program would normally use random numbers, in Truebit you will always get the same sequence. This is done to ensure a deterministic execution.

Dates and times

If your program would normally get date-time values, in Truebit you will always get the same value, which is "1970.1.1 0:1:40". This is done to ensure a deterministic execution.

Output value

The task must return a value. If the result is empty, the task will be marked as failed.

2. Test your Function Task

Once your code is ready to be tested, the task-developer will:

  • Generate a WASM File. Truebit employs WebAssembly to ensure the same execution regardless of the hardware and operation system that is executing the task.

  • Instrument the WASM File to make it deterministic.

3. Deploy the Function Task

Authorize the Task execution

The Task Authorization process is an optional step. This step allows the Task Developer to define who has permission to execute the deployed task.

Click Here to see more information about the Task Authorization process.

4. Execute the Function Task

Click Here to view the list of pre-developed Truebit Tasks created for you to start getting familiar with the task development

Last updated

Was this helpful?