Writing Function Tasks
Function Tasks verify and provide a transcript for the execution of serverless function code.
Last updated
Was this helpful?
Function Tasks verify and provide a transcript for the execution of serverless function code.
Last updated
Was this helpful?
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.
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 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 .
Determinism: The execution environment guarantees : all Function Tasks will produce the same outputs for given inputs when executed by any Truebit Verify node.
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.
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.
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.
Once your code is ready to be tested, the task-developer will:
Repeat this process every time your source code has been changed.
The Task Authorization process is an optional step. This step allows the Task Developer to define who has permission to execute the deployed task.
For example, instead of making an HTTP request to example.com
, read from the input.txt file. Click to see an example.
You can write results to the filesystem into an output file. Click to see an example.
Run the command through the to:
Generate a . Truebit employs WebAssembly to ensure the same execution regardless of the hardware and operation system that is executing the task.
the WASM File to make it deterministic.
Run the command through the to run and test the compiled code.
Once the task is ready for being used by others, the will deploy it to make it available for being called by the .
Click Here to see more information about the process.
The executes the task using the from the Truebit API.
Click to view the list of pre-developed Truebit Tasks created for you to start getting familiar with the task development