-
Notifications
You must be signed in to change notification settings - Fork 29
fix(docs): correct stale API references in support and building guides #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Toby1009
wants to merge
13
commits into
theinterfold:main
Choose a base branch
from
Toby1009:docs/correct-stale-api-references
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−135
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e0e438e
fix(docs): correct stale API references in support and building guides
Toby1009 3feabce
fix(docs): make the payload.json warning self-contained
Toby1009 b505541
fix(docs): use committee_public_key_hash in the run_compute example
Toby1009 8f23444
fix(docs): make the Boundless defaults note readable
Toby1009 b513e07
fix(docs): trim clauses that accumulated across review rounds
Toby1009 28c8b42
fix(docs): point the batch_size note at its tracking issue
Toby1009 315092e
fix(docs): keep defect notes to what a reader can act on
Toby1009 9ca556f
fix(docs): drop a forward reference the next heading already makes
Toby1009 3a30af8
fix(docs): scope the Boundless steps in the processing flow
Toby1009 f4b05bb
fix(docs): correct the result-publication actor and make the provider…
Toby1009 61b4c48
Merge branch 'main' into docs/correct-stale-api-references
Toby1009 c1fd8f8
Merge remote-tracking branch 'origin/main' into docs/correct-stale-ap…
Toby1009 b09acc7
fix(docs): rewrite the compute-provider example for the policy API
Toby1009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,88 +1,110 @@ | ||
| # FHE Compute Manager | ||
|
|
||
| This project provides a flexible and efficient framework for managing Secure Programs (SP) of the | ||
| [Interfold Protocol](https://theinterfold.com). It supports both sequential and parallel processing, | ||
| with the ability to integrate various compute providers. | ||
| This project provides a framework for managing Secure Programs (SP) of the | ||
| [Interfold Protocol](https://theinterfold.com), with the ability to integrate various compute | ||
| providers. | ||
|
|
||
| ## Features | ||
|
|
||
| - Support for both sequential and parallel FHE computations | ||
| - Flexible integration of different compute providers | ||
| - Merkle tree generation for input verification | ||
| - Ciphertext hashing for output verification | ||
| - Per-program input policies that decide the leaf layout and which inputs the computation sees | ||
|
|
||
| ## Installation | ||
|
|
||
| To use this library, add it to your `Cargo.toml`: | ||
|
|
||
| ```toml | ||
| [dependencies] | ||
| e3-compute-provider = { git = "https://github.com/gnosisguild/interfold.git", path = "crates/compute-provider"} | ||
| e3-compute-provider = { git = "https://github.com/theinterfold/interfold.git" } | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| To use the library, follow these steps: | ||
|
|
||
| 1. Create an instance of the `ComputeManager` with your desired configuration. | ||
| 2. Call the `start` method to begin the computation process. | ||
| 3. The method will return the computed ciphertext and the corresponding proof. | ||
| 1. Create an instance of the `ComputeManager` with your compute provider and inputs. | ||
| 2. Call the `start` method with your E3 program's `InputPolicy`. | ||
| 3. The method returns the provider output together with the computed ciphertext bytes. | ||
|
|
||
| ```rust | ||
| use anyhow::Result; | ||
| use e3_compute_provider::{ComputeInput, ComputeManager, ComputeProvider, ComputeResult, FHEInputs}; | ||
| use voting_core::fhe_processor; | ||
|
|
||
| // Define your Risc0Provider struct and implement the ComputeProvider trait | ||
| pub fn run_compute(params: FHEInputs) -> Result<(Risc0Output, Vec<u8>)> { | ||
| let risc0_provider = Risc0Provider; | ||
| let mut provider = ComputeManager::new(risc0_provider, params, fhe_processor, false, None); | ||
| let output = provider.start(); | ||
| Ok(output) | ||
| use e3_compute_provider::{ComputeError, ComputeManager, ComputeProvider, FHEInputs, InputPolicy}; | ||
| use my_program::fhe_processor; | ||
|
|
||
| pub fn run_compute<P>(params: FHEInputs, provider: P) -> Result<(P::Output, Vec<u8>), ComputeError> | ||
| where | ||
| P: ComputeProvider + Send + Sync, | ||
| { | ||
| let mut manager = ComputeManager::new(provider, params, fhe_processor); | ||
| manager.start(InputPolicy::default()) | ||
| } | ||
| ``` | ||
|
|
||
| ## Risc0 Example | ||
| `fhe_processor` is your own function. It must match the exported `FHEProcessor` alias, | ||
| `fn(&FHEInputs) -> Vec<u8>`. | ||
|
|
||
| Here's a more detailed example of how to use the Compute Manager with Risc0: | ||
| ## Input policies | ||
|
|
||
| `InputPolicy` carries the two answers that differ between E3 programs: | ||
|
|
||
| - `leaf` builds a tree leaf. It must equal what the E3 program builds on chain for the same input. | ||
| - `select` chooses which inputs the computation runs over, by index. | ||
|
|
||
| `InputPolicy::default()` is the behaviour every E3 program had before policies existed. The leaf is | ||
| the ciphertext's own SAFE commitment, and every input is computed over. A program whose contract | ||
| inserts something else, or that treats a second input from one participant as a replacement, | ||
| supplies its own. | ||
|
|
||
| A policy cannot supply a root or drop an input from the tree. Leaves are derived from the | ||
| ciphertexts the Secure Process consumed, and every published input contributes one. | ||
|
|
||
| When your E3 program publishes a commitment or other data alongside each ciphertext, build the | ||
| manager with `with_published` so the policy can read it: | ||
|
|
||
| ```rust | ||
| let mut manager = ComputeManager::with_published(provider, params, published, fhe_processor); | ||
| ``` | ||
|
|
||
| ## Implementing a provider | ||
|
|
||
| `ComputeProvider` has one method and one associated type. Everything else is yours to choose: | ||
|
|
||
| ```rust | ||
| use e3_compute_provider::{ComputeInput, ComputeManager, ComputeProvider, ComputeResult, FHEInputs}; | ||
| use methods::VOTING_ELF; | ||
| use risc0_ethereum_contracts::groth16; | ||
| use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, VerifierContext}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| pub struct Risc0Provider; | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct Risc0Output { | ||
| pub result: ComputeResult, | ||
| pub seal: Vec<u8>, | ||
| use e3_compute_provider::{ComputeInput, ComputeProvider, InputPolicy}; | ||
|
|
||
| pub struct MyProvider; | ||
|
|
||
| pub struct MyOutput { | ||
| pub proof: Vec<u8>, | ||
| } | ||
|
|
||
| impl ComputeProvider for Risc0Provider { | ||
| type Output = Risc0Output; | ||
| fn prove(&self, input: &ComputeInput) -> Self::Output { | ||
| // Implementation details | ||
| impl ComputeProvider for MyProvider { | ||
| type Output = MyOutput; | ||
|
|
||
| fn prove(&self, input: &ComputeInput, policy: InputPolicy) -> Self::Output { | ||
| // Prove that `input` produced its committed result under `policy`, however your | ||
| // backend does that, and return whatever the caller needs. | ||
| MyOutput { proof: Vec::new() } | ||
| } | ||
| } | ||
| pub fn run_compute(params: FHEInputs) -> Result<(Risc0Output, Vec<u8>)> { | ||
| let risc0_provider = Risc0Provider; | ||
| let mut provider = ComputeManager::new(risc0_provider, params, fhe_processor, false, None); | ||
| let output: (Risc0Output, Vec<u8>) = provider.start(); | ||
| Ok(output) | ||
| } | ||
| ``` | ||
|
|
||
| This example demonstrates how to create a Risc0Provider, use it with the ComputeManager, and measure | ||
| the execution time of the computation. | ||
| `prove` receives the policy rather than choosing one. A prover that picked its own would select a | ||
| different input set from the one `start` returned the ciphertext for. | ||
|
|
||
| The repository's RISC Zero and Boundless providers live in `e3-support-host`. That crate is in a | ||
| separate workspace, so the dependency above does not pull it in. Inside an Interfold checkout, its | ||
| `run_risc0_compute` and `run_compute` entry points wrap the two backends, and | ||
| `crates/support/host/src/lib.rs` is the reference implementation to read. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The `ComputeManager::new()` function takes several parameters: | ||
| `ComputeManager::new()` takes three parameters: | ||
|
|
||
| - `provider`: An instance of your compute provider (e.g., `Risc0Provider`) | ||
| - `provider`: An instance of your compute provider (e.g., `MyProvider`) | ||
| - `fhe_inputs`: The FHE inputs for the computation | ||
| - `fhe_processor`: A function to process the FHE inputs | ||
| - `use_parallel`: A boolean indicating whether to use parallel processing | ||
| - `batch_size`: An optional batch size for parallel processing, must be a power of 2 | ||
|
|
||
| `ComputeManager::with_published()` takes the same three, plus `published`: one `PublishedData` entry | ||
| per ciphertext, in the same order as `fhe_inputs.ciphertexts`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.