Enclave is now The Interfold.
Build
E3 Program Anatomy
Overview

E3 Program Anatomy

An E3 program is the application code that runs on the Interfold. This page names each part of an E3 program, the file that holds it in the default template, and how the parts connect. It is for developers who have run the Quick Start and want to change the computation. At the end, you know which file to edit for each change and which page explains it.

The parts

An E3 program has five parts. You write the secure process, the program contract, and the client and server. The compute provider and the protocol verifiers come from the Interfold repository.

PartWhat it doesDefault templateCRISP example
Secure processThe FHE computation. It combines encrypted inputs into one encrypted output.program/src/lib.rs (fhe_processor, policy)program/src/lib.rs
E3 program contractImplements IE3Program. It accepts inputs, keeps the input tree, and verifies the output proof.contracts/MyProgram.solpackages/crisp-contracts/contracts/CRISPProgram.sol
Compute providerRuns the secure process off-chain and proves the run.runner/ (program-runner, dev mode and OpenVM service) and guest/ (OpenVM)runner/ and guest/
VerifiersCheck the compute proof on-chain before the Interfold contract accepts the output.OpenVmBfvCiphertextVerifier and the check in MyProgram.verifyOpenVmBfvCiphertextVerifier and CRISPProgram.verify
Client and serverThe client encrypts and submits inputs. The server starts the compute and publishes the output.client/src/, server/index.tsclient/, server/

Template paths are relative to the project root. CRISP paths are relative to the root of the CRISP repository (opens in a new tab). crates/ paths are relative to the root of the Interfold repository.

The Interfold contract (Interfold.sol) and the ciphernodes are not part of your E3 program. The Interfold contract records each E3 and calls your program contract. The ciphernodes generate the committee key and decrypt the output. See The Interfold Contract.

How the parts connect

  1. RequestThe requester calls request. The Interfold contract calls validate on the program contract.
  2. InputsThe client encrypts to the committee key and calls publishInput on the program contract.
  3. ComputeAfter the input window closes, the server sends the inputs to the compute provider.
  4. VerifyThe server calls publishCiphertextOutput. Two verifiers check the proof.
  5. DecryptT + 1 ciphernodes decrypt the output and publish the plaintext.
  1. Request. A requester calls request on the Interfold contract. The Interfold contract calls validate on your program contract. Your contract records the parameter hash, starts an empty input tree, and returns the encryption scheme ID.
  2. Inputs. The committee publishes its public key. The client encrypts each input to that key and calls publishInput on your program contract. The Interfold contract does not see this call. Your contract inserts one leaf per input in its input tree.
  3. Compute. After the input window closes, the server reads the inputs from the program contract events. It sends them to the compute provider. The compute provider runs the secure process and returns the output ciphertext and a proof.
  4. Verify. The server calls publishCiphertextOutput on the Interfold contract. The protocol verifier checks the proof first. Then the Interfold contract calls verify on your program contract. The E3 moves to CiphertextReady only when both checks pass.
  5. Decrypt. The ciphernodes decrypt the output. The Interfold contract needs T + 1 decryption shares. The E3 moves to Complete, and the client reads the plaintext from the PlaintextOutputPublished event.

Calls between the parts

CallerCalled contract or serviceFunction or endpointWhen
RequesterInterfold contractrequestOnce, to start the E3
Interfold contractProgram contractvalidateInside request
Client (data provider)Program contractpublishInputDuring the input window
ServerCompute providerPOST /run_computeAfter the input window closes
Compute providerServerWebhook callback (callback_url)When the proof is ready
ServerInterfold contractpublishCiphertextOutputBefore the compute deadline
Interfold contractProgram contractverifyDataAvailabilityInside publishCiphertextOutput, first
Interfold contractOpenVmBfvCiphertextVerifierverifyInside publishCiphertextOutput, second
Interfold contractProgram contractverifyInside publishCiphertextOutput, third

Two values connect the secure process to the program contract. The first is the input root: the compute provider and the program contract must build the same input tree from the same inputs. The second is the image ID: the program contract and the protocol verifier accept only proofs from the guest program that the image ID names.

Read the pages in order

Next steps