Writing Function Tasks
Function Tasks verify and provide a transcript for the execution of serverless function code.
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.
Building a Function Task
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.
Repeat this process every time your source code has been changed.
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.
4. Execute the Function Task
Last updated
Was this helpful?