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.
| Part | What it does | Default template | CRISP example |
|---|---|---|---|
| Secure process | The FHE computation. It combines encrypted inputs into one encrypted output. | program/src/lib.rs (fhe_processor, policy) | program/src/lib.rs |
| E3 program contract | Implements IE3Program. It accepts inputs, keeps the input tree, and verifies the output proof. | contracts/MyProgram.sol | packages/crisp-contracts/contracts/CRISPProgram.sol |
| Compute provider | Runs the secure process off-chain and proves the run. | runner/ (program-runner, dev mode and OpenVM service) and guest/ (OpenVM) | runner/ and guest/ |
| Verifiers | Check the compute proof on-chain before the Interfold contract accepts the output. | OpenVmBfvCiphertextVerifier and the check in MyProgram.verify | OpenVmBfvCiphertextVerifier and CRISPProgram.verify |
| Client and server | The client encrypts and submits inputs. The server starts the compute and publishes the output. | client/src/, server/index.ts | client/, 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
- RequestThe requester calls request. The Interfold contract calls validate on the program contract.
- InputsThe client encrypts to the committee key and calls publishInput on the program contract.
- ComputeAfter the input window closes, the server sends the inputs to the compute provider.
- VerifyThe server calls publishCiphertextOutput. Two verifiers check the proof.
- DecryptT + 1 ciphernodes decrypt the output and publish the plaintext.
- Request. A requester calls
requeston the Interfold contract. The Interfold contract callsvalidateon your program contract. Your contract records the parameter hash, starts an empty input tree, and returns the encryption scheme ID. - Inputs. The committee publishes its public key. The client encrypts each input to that key
and calls
publishInputon your program contract. The Interfold contract does not see this call. Your contract inserts one leaf per input in its input tree. - 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.
- Verify. The server calls
publishCiphertextOutputon the Interfold contract. The protocol verifier checks the proof first. Then the Interfold contract callsverifyon your program contract. The E3 moves toCiphertextReadyonly when both checks pass. - 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 thePlaintextOutputPublishedevent.
Calls between the parts
| Caller | Called contract or service | Function or endpoint | When |
|---|---|---|---|
| Requester | Interfold contract | request | Once, to start the E3 |
| Interfold contract | Program contract | validate | Inside request |
| Client (data provider) | Program contract | publishInput | During the input window |
| Server | Compute provider | POST /run_compute | After the input window closes |
| Compute provider | Server | Webhook callback (callback_url) | When the proof is ready |
| Server | Interfold contract | publishCiphertextOutput | Before the compute deadline |
| Interfold contract | Program contract | verifyDataAvailability | Inside publishCiphertextOutput, first |
| Interfold contract | OpenVmBfvCiphertextVerifier | verify | Inside publishCiphertextOutput, second |
| Interfold contract | Program contract | verify | Inside 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
The FHE function, the BFV parameters it receives, and the input policy.
Rust2. Program contractEach IE3Program function, when the Interfold contract calls it, and what it must check.
How the program server runs the secure process and returns an OpenVM proof.
Off-chain4. Verify the compute providerHow the proof is checked on-chain, and how to check the image ID of a deployment.
Audit5. Complete exampleOne E3 in the template, from request to decrypted result, with the file for each step.
Walkthrough