Enclave is now The Interfold. Documentation is being updated.
Writing the E3 Program Contract

Writing an E3 Contract

The E3 contract defines your program on-chain. It verifies parameters during the creation of new E3 instances, validates inputs for your Secure Process, and records the computation output.

Smart Contract Components

Each E3 Program implements the IE3Program interface, which defines three functions:

  1. validate — validates parameters when a new E3 is created
  2. verify — verifies the computation output
  3. publishInput — validates and processes encrypted input data

E3 Program

The E3 program contract forms the core of each E3, implementing two functions: one to validate input parameters when a new E3 instance is created and another to verify the output of the computation.

validate

function validate(
  uint256 e3Id,
  uint256 seed,
  bytes calldata e3ProgramParams,
  bytes calldata computeProviderParams,
  bytes calldata customParams
) external returns (bytes32 encryptionSchemeId);

When a new instance of your E3 Program is requested, the validate function is called to validate and initialize the new E3. Some useful validations include:

  • Random seed initialization: Use the seed parameter to instantiate the E3 with a specific random seed
  • Custom parameters: Utilize e3ProgramParams to pass in any additional arbitrary parameters, most commonly the address of your Input Validator contract.
  • Compute Provider setup: Use computeProviderParams to validate the configuration of the Compute Provider chosen for your E3 Program.
  • Custom Params: Use customParams for any requester-defined data (e.g., application-specific settings).

For an example, see this mockup (opens in a new tab) or check out the demo implementation for the CRISP protocol (opens in a new tab).

verify

function verify(
  uint256 e3Id,
  bytes32 ciphertextOutputHash,
  bytes memory proof
) external returns (bool success);

The verify function receives the hash of the ciphertext output and the accompanying proof generated by your chosen Compute Provider to assess the validity of the proof.

Input Validation via publishInput

Data Providers submit encrypted data by calling the publishInput function on your E3 Program contract. This function should validate the encrypted data before accepting it.

function publishInput(uint256 e3Id, bytes memory data) external;

Responsibilities:

  • Data decoding: Decode encrypted input data to its intended format.
  • ZKP Verification: Verify any associated ZKPs to ensure input correctness.
  • Input validation: Validate the input data and revert if invalid.

Example:

pragma solidity >=0.8.27;
 
function publishInput(uint256 e3Id, bytes memory data) external {
  // Decode the input data
  // Verify associated ZKPs
  // Store or process the validated input
}