bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 45쪽 중 9쪽
uint256
(ciphertextCommitment));
emit
InputPublished
(e3Id
,
ciphertext
,
index);
}
⚠️
The template does not prove that the ciphertext matches its commitment, and it does not check the
encryption. An invalid input can then stop the E3 before it completes. A production program must
verify this binding before it inserts the leaf. CRISP shows one way to do this.
verify
interfaces/IE3Program.sol
function
verify
(
uint256
e3Id
,
bytes32
ciphertextOutputHash
,
bytes32
ciphertextCommitment
,
bytes
memory
proof
)
external
returns
(
bool
success);
The Interfold contract calls
verify
inside
publishCiphertextOutput
. The call comes after the
protocol ciphertext verifier accepts the same proof, and before the output is stored. The program
must check the arguments of the call. It must not read the pending output from Interfold storage.
Argument
Content
ciphertextOutputHash
Keccak-256 of the serialized output ciphertext
ciphertextCommitment
The SAFE commitment of the output ciphertext
proof
abi.encode(bytes seal, bytes32 paramsHash, bytes32 inputRoot)
verify
must do these checks:
Compare
paramsHash
in the proof with the hash that
validate
stored.
Compare
inputRoot
in the proof with the root of the on-chain input tree.
Rebuild the nine-word journal with
OpenVmComputeProof.journal
.
Call the OpenVM receipt verifier with the seal, the receipt identity, and
sha256(journal)
.
contracts/MyProgram.sol
function
verify
(
uint256
e3Id
,
bytes32
ciphertextOutputHash
,
bytes32
ciphertextCommitment
,
bytes
memory
proof
)
external
view
override
returns
(
bool
) {
require
(paramsHashes[e3Id]
!=
bytes32
(
0
)
,
E3DoesNotExist
());
E3
memory
e3
=
interfold.
getE3
(e3Id);
bytes32
paramsHash
=
paramsHashes[e3Id];
bytes32
inputRoot
=
bytes32
(inputs[e3Id].
_root
());
OpenVmComputeProof.Proof
memory
computeProof
=
OpenVmComputeProof.
decode
(proof);
if
(computeProof.paramsHash
!=
paramsHash
||
computeProof.inputRoot
!=
inputRoot)
revert
InvalidComputeContext
();
bytes
memory
journal
=
OpenVmComputeProof.
journal
(
bytes32
(block.chainid)
,
bytes32
(
uint256
(
uint160
(
address
(interfold))))
,
bytes32
(e3Id)
,
e3.encryptionSchemeId
,
e3.committeePublicKey
,
ciphertextOutputHash
,
ciphertextCommitment
,
paramsHash
,
inputRoot
);
verifier.
verify
(computeProof.seal
,
imageId
,
sha256
(journal));
return
true
;
}
🚫
The input root comparison is required. The protocol verifier takes the input root from the proof
and does not check it against any on-chain value. Without step 2, a prover can publish an output
that it computed over inputs that nobody submitted.
verify
can change state. After it returns, the Interfold contract reads the stage again and checks
committee viability again.
CRISPProgram.verify
also refuses the output while an input waits for
its availability receipt (
InputAvailabilityPending
).
verifyDataAvailability
interfaces/IDataAvailabilityVerifier.sol
function
verifyDataAvailability
(
bytes32
expectedContentHash
,
bytes
calldata
proof
)
external
view
returns
(
IDataAvailabilityVerifier
.
DataReference
memory
receipt);
The Interfold contract calls this function on every
publishCiphertextOutput
. It proves that the
output bytes are available outside Ethereum. The returned
receipt.contentHash
must equal
expectedContentHash
, or the output is refused. The Interfold contract emits the content hash and
the receipt coordinates in
CiphertextOutputReferencePublished
. The ciphernodes use them to fetch
the output bytes before they decrypt.
The template version is for the local stack only. It accepts the raw ciphertext as the proof and
checks its Keccak-256 hash:
contracts/MyProgram.sol
function
verifyDataAvailability
(
bytes32
expectedContentHash
,
bytes
calldata
proof
)
external
pure
override
returns
(
IDataAvailabilityVerifier
.
DataReference
memory
receipt) {
bytes32
actual
=
keccak256
(proof);
if
(actual
!=
expectedContentHash)
revert
DataAvailabilityHashMismatch
(expectedContentHash
,
actual);
return
IDataAvailabilityVerifier.
DataReference
(expectedContentHash
,
0
,
0
);
}
CRISPProgram
sends the call to an immutable
dataAvailabilityVerifier
. It uses the same verifier
for inputs and for the output.
Input validation with ZK proofs (CRISP)
CRISPProgram.sol
(
examples/CRISP/packages/crisp-contracts/contracts/
) validates each input with
a Noir proof. It uses two transactions for each input.
publishInput
decodes the Noir proof, the slot address, the ciphertext commitment, the
ciphertext content hash, the parent index, and a signed availability attestation. It verifies the
Noir proof with nine public inputs, which include the commitment and the committee public key. It
checks the attestation signature and expiry. Then it appends the leaf and emits
InputCommitted
.
finalizeInput
can be called by any account. It verifies the data-availability receipt for
the exact content hash, and then emits
InputPublished
.
The leaf binds the content hash, the commitment, the slot, and the parent:
CRISPProgram.sol
function
inputLeaf
(
bytes32
encryptedVoteHash
,
bytes32
commitment
,
address
slotAddress
,
uint40
parentIndexPlusOne
)
public
pure
returns
(
uint256
) {
return
uint256
(
sha256
(abi.
encodePacked
(encryptedVoteHash
,
commitment
,
slotAddress
,
parentIndexPlusOne))
) % SNARK_SCALAR_FIELD;
}
The CRISP secure process builds the same leaf. See
Secure Process
. For the circuits, see
Noir Circuits
.
Next steps
Compute provider
How the proof that
verify
checks is made.
Verify the compute provider
The journal fields, the image ID, and how to check a deployment.
Request an E3
The request parameters that reach
validate
.
Secure Process
Compute Provider
## /build/e3-program/compute-provider
Build
E3 Program Anatomy
Compute Provider
Compute Provider
The compute provider (CP) runs the secure process off-chain and proves that it ran correctly. Each
Interfold project proves its own E3 program: an OpenVM guest and a proving service, both built from
the project's
program/
crate, run on the operator's machine. There is no proving market, program
upload, or payment account. This page explains what the Interfold contract expects from a CP, how
the Rust crates fit together, and how to run a CP. It is for E3 program developers and for the
person who runs the CP.
What the Interfold contract expects
The Interfold contract has no registry of compute providers. It checks the result, not the party
that made it.
Any account can call
publishCiphertextOutput
. The function has no caller restriction.
The call must come after the input window closes and before the compute deadline. The E3 must be
in the
KeyPublished
stage, and the output can be published only one time.
The committee of the E3 must still meet its threshold.
The proof must pass the protocol ciphertext verifier of the encryption scheme and then
verify
on
the program contract.
The request field
computeProviderParams
goes to
IE3Program.validate
unchanged. The Interfold
contract does not read it.
interfaces/IComputeProvider.sol
defines
validate(e3Id, seed, params)
, which returns a
decryption verifier.
Interfold.sol
does not call this interface. Only the test contract
MockComputeProvider
implements it. The decryption verifier comes from
setDecryptionVerifier
for the encryption scheme.
Components
Component
Location
Role
e3-compute-provider
crates/compute-provider
SecureProcess
,
ComputeProvider
,
ComputeManager
,
InputPolicy
, input tree
e3-program-server
crates/program-server
HTTP server with
POST /run_compute
and
GET /health
. It calls a runner function.
e3-openvm-host
crates/openvm-host
The OpenVM runner: native run, guest input, worker selection, proof envelope
interfold-openvm-prover
crates/openvm-prover
The worker that proves the guest. A CPU build and a CUDA build.
Guest
guest/
in your project
The OpenVM guest. It links your
program/
crate.
Proving service and scripts
.interfold/support/openvm
in project
The service binary and the
compile
and
start
scripts that
interfold program
runs
Development runner
.interfold/support/dev
in project
An unproved runner with a mock proof, for local work
Coordination server
server/index.ts
(template)
Sends the job, receives the webhook, and calls
publishCiphertextOutput
interfold init
copies both support folders into the project and pins the guest's Interfold crates
to the template's commit.
The secure process
SecureProcess
(
crates/compute-provider/src/secure_process.rs
) is the computation that every CP
reproduces. It reads a round in two passes, one ciphertext at a time:
Every ciphertext, in index order. For each one it recomputes the SAFE commitment, hashes the
bytes with Keccak-256, and builds the input's leaf with your policy. Then it drops the bytes.
The policy's
select
runs over the records that remain: index, hash, stored commitment,
metadata, and recomputed commitment.
The selected ciphertexts, read again in index order. Each one is refused unless it hashes to the
value from the first pass. Your processor receives them one at a time.
Only one ciphertext is held at a time, so the guest's 512 MiB of memory does not limit the number of
inputs.
ComputeInput::run
runs the same code over a round that is already in memory. The OpenVM
host uses that to predict the journal the guest must reveal. The guest build swaps in OpenVM's
accelerated hashing, so the prediction holds only while that code matches the host's. Check it by
running the guest without proving: the worker's
execute
compares the digest it reveals with the
host's journal.
The processor takes the selected ciphertexts as an iterator:
program/src/lib.rs
pub
fn
fhe_processor
(fhe_inputs
:
FHEProcessorInput
<'
_
>)
->
Vec
<
u8
> {
let
mut
sum
=
Ciphertext
::
zero
(fhe_inputs
.
params);
for
(bytes, _)
in
fhe_inputs
.
ciphertexts {
let
ciphertext
=
Ciphertext
::
from_bytes
(
&
bytes, fhe_inputs
.
params)
.
unwrap
();
sum
+=
&
ciphertext;
}
sum
.
to_bytes
()
}
The processor must read every item. Keep the state that it carries between items small.
The ComputeProvider trait
A CP that uses
ComputeManager
implements one method
(
crates/compute-provider/src/ciphertext_output.rs
):
crates/compute-provider/src/ciphertext_output.rs
pub
trait
ComputeProvider
{
type
Output
:
Send
+
Sync
;
fn
prove
(
&
self, input
:
&
ComputeInput
, policy
:
InputPolicy
)
->
Self
::
Output
;
}
ComputeManager
connects the provider, the inputs, and the processor.
start(policy)
runs the
secure process and then calls
prove
with the same policy. It returns the provider output and the
output ciphertext from the same input selection. Use
with_published
when the policy reads the
commitment or metadata of each input.
The dev runner (
crates/support-scripts/dev/src/main.rs
) is the smallest complete CP. It runs your
processor, builds a mock proof, and serves it over HTTP:
crates/support-scripts/dev/src/main.rs
#[tokio
::
main]
async
fn
main
()
->
Result
<()> {
let
server
=
E3ProgramServer
::
builder
(
|
job
|
async
move
{
let
mut
manager
=
ComputeManager
::
with_published
(
MockProofProvider
,
job
.
inputs,
job
.
published,
fhe_processor,
);
let
(result, ciphertext)
=
manager
.
start
(e3_user_program
::
policy
())
?
;
let
proof
=
encode_mock_compute_proof
(
&
[
3
,
1
,
4
,
1
,
5
,
9
,
2
,
6
,
5
,
3
,
5
],
&
result)
?
;
Ok
((proof, ciphertext))
})
.
build
()
?
;
server
.
run
()
.await?
;
Ok
(())
}
The OpenVM service (
crates/support-scripts/openvm/service/src/main.rs
) has the same shape. Its
runner is
e3_openvm_host::Prover::prove
, which runs the secure process natively, writes the
guest's input stream, runs the worker, and returns the verified proof envelope.
The program server
The program server does not send transactions. It computes, then posts the result to the
callback_url
of the request. The coordination server receives that webhook and calls
publishCiphertextOutput
.
Setting
Development runner
OpenVM service
Bind address
0.0.0.0:13151
127.0.0.1:13151
; set
OPENVM_BIND_ADDR
to change it
Endpoints
POST /run_compute
,
GET /health
The same
Body limit
10 MiB
128 MiB; set
OPENVM_MAX_REQUEST_BYTES
to change it
Body deadline
120 s
120 s; set
OPENVM_BODY_TIMEOUT_SECS
to change it
Parallel jobs
1
1; set
MAX_CONCURRENT_COMPUTATIONS
to change it
Webhook
Up to five attempts
Up to five attempts
Response
{"status":"processing","e3_id":"<id>"}
at once
A request is admitted before its body is read. A request over the job limit gets HTTP 429, a body
over the limit gets HTTP 413, and a body that does not arrive by the deadline gets HTTP 408. The
webhook is retried with backoff after a network error or HTTP 5xx, 408, or 429.
Request fields
POST /run_compute
takes a JSON body (
crates/program-server/src/types.rs
,
ComputeRequest
):
Field
Type
Content
e3_id
string
The E3 ID. Required.
chain_id
number
Chain ID for the proof domain
interfold_address
hex string
Interfold contract address for the proof domain
encryption_scheme_id
hex string
e3.encryptionSchemeId
committee_public_key_hash
hex string
e3.committeePublicKey
(a hash of the committee key)
params
hex string
paramSetRegistry[e3.paramSet]
from the Interfold contract
ciphertext_inputs
array of
[hex, number]
Each input ciphertext and its on-chain index, sorted by index
input_commitments
array of hex strings
Optional. The commitment that the program stored for each input.
input_slots
array of hex strings
Optional. The 20-byte slot of each input. Send it with
input_commitments
.
input_parents
array of numbers
Optional. The parent index plus one of each input, at most
uint40
.
callback_url
string
The URL for the webhook. Required.
The template server sends only the first seven fields and
callback_url
(
server/runner.ts
). The
default policy needs no per-input data. CRISP also sends the three optional fields.
Webhook payload
The webhook body is a tagged JSON object. On success:
{
"status"
:
"completed"
,
"e3_id"
:
"1"
,
"ciphertext"
:
"0x..."
,
"ciphertext_commitment"
:
"0x..."
,
"proof"
:
"0x..."
}
On failure:
{"status":"failed","e3_id":"1","error":"..."}
. The template server takes the success
body and calls
publishCiphertextOutput
with a
CiphertextOutputReference
:
server/index.ts
await
sdk
.publishCiphertextOutput
(
BigInt
(e3_id)
,
{
contentHash
,
ciphertextCommitment
:
ciphertext_commitment
,
computeProof
:
proof
,
// The local program verifies raw bytes as a deterministic mock receipt.
availabilityProof
:
ciphertext
,
})
The program server rejects a callback URL that points at a private or link-local address. Loopback
is allowed. Set
ALLOW_PRIVATE_CALLBACKS=1
to allow private addresses for local development.
Proof modes
The
program
section of
interfold.config.yaml
selects the mode
(
crates/config/src/program_config.rs
).
Setting
What
interfold program start
runs
Proof
program.dev: true
.interfold/support/dev/start
: the dev runner, built from your
program/
crate
Mock proof. Only
MockOpenVmReceiptVerifier
accepts it.
program.dev: false
,
program.openvm
.interfold/support/openvm/start
: the OpenVM service for your
program/
crate
OpenVM Halo2 EVM proof, verified before it is returned
--dev true
on
interfold program start
or
interfold program compile
overrides the file, as does
E3_PROGRAM__DEV=true
. The template's local scripts set it unless
TEMPLATE_REAL_PROOFS=1
, and
CRISP's unless
CRISP_REAL_PROOFS=1
. A configuration with the removed
program.risc0
section still
loads, but
interfold program
refuses it.
Proof format
The guest reveals SHA-256 of nine 32-byte ABI words, 288 bytes (
lib/OpenVmComputeProof.sol
):
Chain ID
Interfold contract address
E3 ID
Encryption scheme ID
Committee public key hash
Output ciphertext hash
Output SAFE commitment
BFV parameter hash
Input root
The CP returns the proof as
abi.encode(bytes seal, bytes32 paramsHash, bytes32 inputRoot)
. The
seal is
abi.encode(uint8(1), bytes(halo2ProofData))
, 1,856 bytes. It does not repeat the journal:
the Halo2 proof's only public value is the journal digest.
OpenVmComputeProof.decode
reads the
envelope on-chain. The verifiers rebuild the other seven fields from on-chain state. See
Verify the Compute Provider
.
The guest must match your E3 program
The guest and the service link your
program/
crate, so they run your processor and your policy.
The contract, the host, and the guest must derive the same leaves, the same selection, the same
parameter hash, and the same journal.
A changed program, policy, or
guest/openvm.toml
gives a new receipt identity: a new executable
commitment and VM commitment. The protocol verifier and your program contract must both name it,
so a changed guest needs new verifiers.
The Interfold contract keeps one ciphertext verifier for each encryption scheme. On one
deployment, every BFV E3 program must use the receipt identity that this verifier names. The
template deploys its own verifiers for its chain (
deploy/default.ts
).
If your program hashes data inside the guest, add the hash to the
openvm-hashes
feature of your
program/
crate and to
guest/openvm.toml
, as CRISP does for SHA-256.
Run a compute provider
This procedure builds and starts the OpenVM CP. Run it in an Interfold project that
interfold init
made.
⚠️
The program server does not authenticate callers. Any caller that can reach the port can start a
computation that your machine proves. Keep it on loopback or behind authenticated admission
control.
Install the tools
Install the Interfold CLI (see
Installation
) and
cargo-openvm
:
cargo
install
--locked
--git
https://github.com/openvm-org/openvm.git
--tag
v2.0.2
cargo-openvm
cargo
openvm
setup
--evm
cargo openvm setup --evm
writes the Halo2 proving key, the KZG parameters, and the EVM verifier to
~/.openvm
. Without
--evm
it writes only the recursion keys, and the compile step stops.
Generating the Halo2 key needs a large amount of memory;
--download
fetches OpenVM's prebuilt key
and verifier instead. Check their provenance before you use them.
Build the workers
Build the worker from the Interfold repository at the same revision as your project:
cargo
build
--locked
--release
--manifest-path
crates/openvm-prover/Cargo.toml
On a machine with an NVIDIA GPU, also build the CUDA worker into its own directory. It needs the
CUDA toolkit:
CARGO_TARGET_DIR
=
target/cuda
cargo
build
--locked
--release
--features
cuda
\
--manifest-path
crates/openvm-prover/Cargo.toml
Configure the program section
interfold.config.yaml
program
:
dev
:
false
openvm
:
prover_bin
:
/opt/openvm/interfold-openvm-prover
prover_bin_cuda
:
/opt/openvm/interfold-openvm-prover-cuda
backend
:
auto
Key
Default
Meaning
prover_bin
None
The CPU worker
prover_bin_cuda
None
The CUDA worker
backend
auto
auto
,
cpu
, or
cuda
setup_dir
~/.openvm
The directory that
cargo openvm setup --evm
wrote
Set at least one worker. Every path is absolute. With
backend: auto
the service uses the CUDA
worker when it is set and can open a GPU, and the CPU worker otherwise.
cuda
refuses to start
without a working GPU, and
cpu
never tries one.
Compile
Run
interfold program compile
. It builds
guest/
, generates the application proving key, runs the
worker's
prepare
for the aggregation key and the receipt identity, writes the worker configuration
to
.interfold/caches/openvm/prover.json
(or to
OPENVM_PROVER_CONFIG
when it is set;
start
and
the deploys read the same path), and builds the service. The keys are regenerated only when the
guest executable or
guest/openvm.toml
changes. The identity is in
.interfold/caches/openvm/prepared/identity.json
.
Deploy the verifiers
Deploy the contracts. The template a프로젝트로 돌아가기