📃RequestBuilder

The RequestBuilder library in Solidity is designed to help users create and manage complex request operations. It uses a structured approach to manage operations and their operands, which may be encrypted values or indices pointing to previously computed results. This guide provides a detailed explanation of the structure and usage of the RequestBuilder library.

Structure

The library contains two primary structures:

  1. Operation

  2. Request

Operation Structure

The Operation structure represents an individual operation with the following fields:

  • opcode: A uint8 representing the operation code, which defines the type of operation.

  • operands: A uint256[] array representing the indices of operands or an encrypted value.

  • value: A uint64 representing a direct value if applicable.

Request Structure

The Request structure aggregates multiple operations and manages their execution. It includes:

  • id: A unique identifier for the request, generated upon completion.

  • requester: The address of the entity making the request.

  • ops: An array of Operation structures.

  • opsCursor: A cursor to track the current position in the ops array.

  • callbackAddr: Address for the callback once the request is processed.

  • callbackFunc: Function signature for the callback.

  • payload: Additional data to be sent with the request.

Usage of Operands as Indices

In this library, operands are used as indices rather than direct values. This approach allows for flexible and efficient referencing of previously computed results within the same request. Each operation can reference the result of another operation by its index in the ops array. This method enhances modularity and composability in constructing complex operations.

Example

To add two encrypted uint64 values and store the result:

  1. Load the first encrypted value:

    op firstIndex = getEuint64(request, firstEncryptedValue);
  2. Load the second encrypted value:

    op secondIndex = getEuint64(request, secondEncryptedValue);
  3. Add the two values and store the result:

    op resultIndex = add(request, firstIndex, secondIndex);

Last updated