bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 45쪽 중 6쪽
n
prints that
feature name.
In a project folder with a running ciphernode, the CLI sends
interfold rev
to that node. The
output is then the revision of the node, which can differ from the revision of your CLI.
Troubleshooting
Problem
Cause and fix
command not found: interfold
The install folder is not in your
PATH
. Add
~/.local/bin
(or
/usr/local/bin
for
--system
) to your
PATH
.
No compatible asset found for <os>-<arch>
interfoldup
found no archive for your platform in the release. Build the CLI from source.
No compatible binary found for platform: <platform>
The install script found no
interfoldup
archive for your platform. Build the CLI from source.
GitHub API request for release <tag> failed
The tag does not exist, or GitHub is not available. Check the tag on the releases page.
The source build stops with
solc must be installed
Install the Solidity compiler
solc
and run the build again.
Next steps
Quick Start
Make a project from the template and run one E3 on your computer.
Tutorial
Project Template
The folders, scripts, and configuration of the default template.
Reference
CLI reference
All
interfold
commands and flags.
Reference
Use Cases
Quick Start
## /build/quick-start
Build
Quick Start
Quick Start
This page takes you from an empty folder to one completed E3 on your computer. It is for developers
who have installed the Interfold CLI. At the end, you have the default template running locally, and
a committee of local ciphernodes has decrypted the sum of two encrypted numbers.
Before you begin
Install the CLI and the developer tools on the
Installation
page. Then make
sure that each tool is available:
interfold
--version
# interfold 0.18.0
node
--version
# v22
pnpm
--version
# 10.7.1
cargo
--version
anvil
--version
You also need a browser wallet, for example MetaMask.
Run the template
Create the project
interfold
init
my-first-e3
interfold init
downloads the template that matches your CLI version (tag
v0.18.0
for CLI
0.18.0). It copies the template to
my-first-e3
, runs
pnpm install
, and makes the first Git
commit. The command prints
You can now start building on Interfold
when it completes.
Go to the project folder
cd
my-first-e3
Start the local stack
pnpm
dev:all
The terminal shows log lines from six processes. Each line starts with the process name:
FRONTEND
,
EVM
,
CHAIN
,
CIPHER
,
SERVER
, or
PROGRAM
. The first start takes more time, because Cargo
compiles the program server. The client is ready when the
FRONTEND
process starts Vite. See
What runs
for the details of each process.
Add the local chain to your wallet
Add a custom network to your wallet with these values:
Field
Value
RPC URL
http://localhost:8545
Chain ID
31337
Import the development account
Import this private key into your wallet as a new account:
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
This key is the first account of the Anvil test mnemonic. The deploy script uses this account, so it
holds the local fee token that pays for the E3.
⚠️
This private key is public. Use it only on the local chain. Never send real funds to this account,
and never use it on a live network.
Connect the wallet
Open
http://localhost:3000
(opens in a new tab)
. Use the connect button in the top bar to
connect the development account on the local chain. The client starts the SDK and moves to
Step 2
· Request Computation
.
Request an E3
Select
Request E3 Computation
. Approve the two transactions in your wallet: first the fee token
approval, then the E3 request.
The page shows the E3 ID and the message
Waiting for committee to publish public key…
. When the
committee publishes its public key, the client moves to
Step 3 · Enter Your Numbers
.
The button label shows
0.001 ETH
. The client does not send ETH. It gets a fee quote from the
Interfold contract and pays that fee in the local fee token.
Enter two numbers
Enter a
First Number
and a
Second Number
. Keep the sum less than 100. Select
Proceed to
Encryption
, then approve the two input transactions in your wallet.
The template uses the
insecure-512
parameter set. Its plaintext modulus is 100, so the result is
the sum modulo 100. The page shows the time that remains in the input window. You must submit both
numbers before the window closes.
Get the result
The page shows the progress of the E3. The coordination server starts the computation when the input
window closes. Then the committee decrypts the output. The client moves to
Step 5 · Results
and
shows your two numbers and their sum.
To run another E3, select
Start New Computation
.
To stop the stack, press
Ctrl+C
in the terminal that runs
pnpm dev:all
. Each start deploys the
contracts again on a new local chain.
What runs
pnpm dev:all
runs
scripts/dev_all.sh
, which uses
concurrently
to start six processes. If one
process fails,
concurrently
stops the others.
Process
Command
What it does
Ports
FRONTEND
pnpm dev:frontend
Waits for the chain and the program server. Exports the contract addresses with
interfold print-env --vite --chain localhost
, then starts the Vite client.
3000
EVM
anvil --host 0.0.0.0 --chain-id 31337 --block-time 1 …
Runs the local chain. It uses the test mnemonic
test test test test test test test test test test test junk
.
8545
CHAIN
node ./scripts/anvil-automine.mjs
Mines a block every second. Fulfills the mock randomness requests that committee selection uses.
None
CIPHER
pnpm dev:ciphernodes
Sets the wallets of five ciphernodes (
cn1
to
cn5
) and runs
interfold noir setup
. Deploys the protocol contracts and
MyProgram
. Starts the nodes with
interfold nodes up
and registers each node with the
ciphernode:admin-add
task.
QUIC 9201 to 9205, control 50501 to 50505, dashboard 8004 (
cn1
)
SERVER
TEST_MODE=1 pnpm dev:server
Runs the coordination server. It waits for the committee key, starts the computation when the input window closes, and publishes the ciphertext output. It also serves the output bytes to the ciphernodes.
8080
PROGRAM
pnpm dev:program
Runs
interfold program start
, which starts the program server. The program server runs the FHE computation in
program/src/lib.rs
.
13151
The
SERVER
and
PROGRAM
processes wait until the
CIPHER
process has deployed the contracts and
started all five nodes. The
CIPHER
process signals this with the file
/tmp/interfold_ciphernodes_ready
.
To open each process in its own pane, run
pnpm dev:all --tmux
. This mode needs tmux, and it starts
the chain with
pnpm dev:evm
(a Hardhat node) instead of Anvil.
⚠️
The program server accepts callback URLs from any caller. It does not authenticate callers and
does not restrict callback destinations. It is a development service only. Do not expose it to a
production or untrusted network.
What
predev:all
does
pnpm runs the
predev:all
script before
dev:all
:
./scripts/compile_program.sh
The script loads
scripts/lib/dev_config.sh
and runs
interfold program compile
. The local
settings set
E3_PROGRAM__DEV=true
and
TEMPLATE_UNPROVED_TEST=1
unless
TEMPLATE_REAL_PROOFS=1
,
which selects what the command builds:
Mode
interfold program compile
runs
Dev mode (the local default)
.interfold/support/dev/compile
, which runs
cargo build --locked --bin e3-support-scripts-dev
. No guest is built.
TEMPLATE_REAL_PROOFS=1
.interfold/support/openvm/compile
: the OpenVM guest in
guest/
, its keys and receipt identity, and the proving service.
In dev mode, the program server runs the computation without a proof, and the template deploys
MockOpenVmReceiptVerifier
, which accepts every receipt on the local chain only. See
Compute provider
for proofs.
What just happened
The Interfold contract records each E3 in a sequence of stages. Your E3 went through five stages.
Your E3 on the local chain
1
Requested
2
CommitteeFinalized
3
KeyPublished
4
CiphertextReady
5
Complete
01
Requester
E3Requested
Requested
The client requested an E3 with the
minimum
committee size and parameter set
0
(
insecure-512
).
Stage
What happened in the template
Requested
The client got a fee quote, approved the fee token, and called the Interfold contract. The request used the
minimum
committee size, parameter set
0
(
insecure-512
), and an input window of 100 seconds that opens 15 seconds after the request. The contract emitted
E3Requested
.
CommitteeFinalized
Sortition selected three of the five ciphernodes. The
minimum
committee has N = 3 and threshold T = 1. The
CHAIN
process supplied the randomness that sortition needs on the local chain. The contract emitted
CommitteeFinalized
.
KeyPublished
The committee ran distributed key generation (DKG) and published one public key. The client assembled the key from
CommitteePublicKeyChunkPublished
events and checked it against the key commitment. Then it encrypted each number and called
MyProgram.publishInput
twice.
CiphertextReady
When the input window closed, the coordination server sent the two ciphertexts to the program server. The program server ran
fhe_processor
and returned the encrypted sum. The coordination server called
publishCiphertextOutput
, and the contract emitted
CiphertextOutputReferencePublished
.
Complete
The committee members fetched the encrypted sum and made decryption shares. T + 1 shares (two shares) are sufficient to decrypt. The plaintext was published with a proof, and the contract emitted
PlaintextOutputPublished
. The client decoded the result.
No single ciphernode could decrypt your numbers. The computation ran on ciphertexts only, and only
the final sum was decrypted. For the full stage model, including timeouts and the
Failed
stage,
see
E3 lifecycle
.
Troubleshooting
Problem
Cause and fix
interfold init
stops with
Directory '…' is not empty
The target folder must be empty or must not exist. Use a new folder name.
interfold init
stops with
Cannot run `interfold init` when a configuration exists.
The CLI found an
interfold.config.yaml
in the current folder, in a parent folder, or in the default configuration folder. Run
interfold init
from a folder outside other Interfold projects.
The client shows
Environment Configuration Required
The client started without the contract addresses. Start the client with
pnpm dev:all
or
pnpm dev:frontend
, which export the addresses.
ERROR: only N/5 ciphernodes stayed up
A ciphernode stopped during startup. Read the
CIPHER
log lines above the error for the cause.
The page shows
Input window closed.
The input window closed before you submitted both numbers. Select
Start New Computation
and try again.
The client shows an old E3 after a restart
The client keeps its state in the browser. Select
Start over
in the top bar.
Next steps
Hello World
Change the FHE computation in the template and run the E3 again.
Tutorial
Project Template
Every folder, script, and setting in the template.
Reference
E3 lifecycle
Each stage of an E3, its events, and its timeouts.
Concepts
Installation
Hello World
## /build/hello-world
Build
Hello World
Hello World
This tutorial changes the FHE computation in the default template and runs the E3 again. It is for
developers who have completed the
Quick Start
. At the end, your E3 returns 2 ×
(a + b) instead of a + b. You also know which files hold the computation, its test, and its labels
in the client.
Before you begin
You need the
my-first-e3
project from the
Quick Start
, with no changes. All
paths on this page are relative to the project folder.
How the template computes
The FHE computation is one Rust function,
fhe_processor
, in
program/src/lib.rs
. The other parts
of the template move ciphertexts to this function and move its result to the committee.
Encrypt
The client encrypts each number to the committee key.
Publish
MyProgram.publishInput records each ciphertext.
Compute
The program server runs fhe_processor on the ciphertexts.
Decrypt
The committee decrypts only the output.
The client encrypts each number with the committee public key and calls
MyProgram.publishInput
.
When the input window closes, the coordination server (
server/index.ts
) reads the published
inputs and sends them to the program server on port 13151.
The program server (
.interfold/support/dev/src/main.rs
) calls
fhe_processor
and sends the
encrypted result back to the coordination server.
The coordination server publishes the encrypted result. The committee decrypts it.
This is the default computation in
program/src/lib.rs
. The doc comment above
policy
is removed
here:
program/src/lib.rs
use
e3_compute_provider
::
{
FHEProcessorInput
,
InputPolicy
};
use
fhe
::
bfv
::
Ciphertext
;
use
fhe_traits
::
{
DeserializeParametrized
,
Serialize
};
pub
fn
policy
()
->
InputPolicy
{
InputPolicy
::
default
()
}
/// Implementation of the CiphertextProcessor function
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
()
}
FHEProcessorInput
has two fields.
ciphertexts
yields
(Vec<u8>, u64)
pairs one at a time: the
serialized ciphertext and its input index.
params
holds the BFV parameters of the E3.
Ciphertext::zero
makes the zero ciphertext, the start value. The
+=
operator adds each input
ciphertext to it. This addition is homomorphic: the function adds the hidden values, but it cannot
see them.
sum.to_bytes()
serializes the encrypted result.
policy()
returns the input policy. The default policy uses every published input.
The template requests E3s with the
insecure-512
parameter set. Its plaintext modulus is 100, so
every result is calculated modulo 100. For this tutorial, 2 × (a + b) must be less than 100.
Change the computation
Stop the stack
If
pnpm dev:all
runs, press
Ctrl+C
in its terminal.
Double the encrypted sum
In
program/src/lib.rs
, replace the
fhe_processor
function with this version:
program/src/lib.rs
/// Implementation of the CiphertextProcessor function
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;
}
// Add the encrypted sum to itself. The hidden value becomes 2 × (a + b).
let
doubled
=
&
sum
+
&
sum;
doubled
.
to_bytes
()
}
&sum + &sum
adds two ciphertexts and returns a new ciphertext. The function needs no new imports.
Update the unit test
The test at the end of
program/src/lib.rs
encrypts 3 and 2 and calls
fhe_processor
. Change the
expected value from 5 to 10:
program/src/lib.rs
let
tally
=
Vec
::
<
u64
>
::
try_decode
(
&
decrypted, Encoding
::
poly
())
?
;
assert_eq!
(tally[
0
],
10
);
Ok
(())
Run the unit test
cargo
test
-p
e3-user-program
Cargo prints
test tests::test ... ok
. If the test fails, compare your
fhe_processor
with the
code in the previous step.
Update the label on the input step
In
client/src/pages/steps/EnterInputs.tsx
, find this line:
client/src/pages/steps/EnterInputs.tsx
<
strong
className
=
'font-semibold'
>Ready to compute:</
strong
> {input1}
+
{input2}
=
?
Change it to:
client/src/pages/steps/EnterInputs.tsx
<
strong
className
=
'font-semibold'
>Ready to compute:</
strong
>
2
× ({input1}
+
{input2})
=
?
Update the label on the results step
In
client/src/pages/steps/Results.tsx
, find this line:
client/src/pages/steps/Results.tsx
{
submittedInputs
?
`
${
submittedInputs
.input1
}
+
${
submittedInputs
.input2
}
=
${
result
!==
null
?
result
:
'…'
}
`
:
'…'
}
Change it to:
client/src/pages/steps/Results.tsx
{
submittedInputs
?
`2 × (
${
submittedInputs
.input1
}
+
${
submittedInputs
.input2
}
) =
${
result
!==
null
?
result
:
'…'
}
`
:
'…'
}
Start the stack
pnpm
dev:all
The
PROGRAM
process runs
interfold program start
. In dev mode, this command runs
cargo run --bin e3-support-scripts-dev
, so Cargo compiles the program server again with your new
fhe_processor
.
Run an E3
Open
http://localhost:3000
(opens in a new tab)
. If the client shows the result of an earlier
E3, select
Start over
in the top bar. Request an E3, then enter 5 and 3.
The input step shows
Ready to compute: 2 × (5 + 3) = ?
. The results step shows
2 × (5 + 3) = 16
.
Why nothing else changes
The contract.
MyProgram.publishInput
stores a commitment for each input, and
MyProgram.verify
checks the compute proof. Neither function contains the computation.
The coordination server.
server/index.ts
sends every published input to the program server
and publishes the output that it gets back. It does not know what the computation does.
The deployment.
pnpm dev:all
deploys the contracts again on a new local chain at each start.
In dev mode, the program server runs
fhe_processor
without a proof, and the template deploys
MockOpenVmReceiptVerifier
, which accepts every receipt on the local chain. With real proofs,
MyProgram.verify
checks the OpenVM receipt against the
imageId
that
MyProgram
receives when
it is deployed. A change to the program changes that identity, so compile and deploy again. See
Compute provider
.
Update the integration test
The template has an end-to-end test in
tests/integration.spec.ts
. It encrypts 1 and 2 and expects
their sum. After your change, update the expected value:
tests/integration.spec.ts
expect
(
BigInt
(result))
.toBe
(
2
n
*
(num1
+
num2))
Run the test with
pnpm test:integration
. This test needs a CLI that is built with the
test-only-skip-proof-aggregation
Cargo feature. Release binaries do not include it. See
Installation
for a source build.
Operations on ciphertexts
The template uses the
fhe
crate from
gnosisguild/fhe.rs
at tag
v0.4.2
. For a
Ciphertext
,
that crate implements these operators:
Operation
Operator
Example
Add two ciphertexts
+
,
+=
&a + &b
Subtract two ciphertexts
-
,
-=
&a - &b
Negate a ciphertext
unary
-
-&a
Add or subtract a plaintext
+
,
+=
,
-
,
-=
&a + &plaintext
Multiply by a plaintext
*
,
*=
&a * &plaintext
A
Plaintext
must use the same parameters object as the ciphertext, that is
fhe_inputs.params
. If
the parameters objects are different, the operator panics.
All results wrap modulo the plaintext modulus. A negative result, for example from
&a - &b
with
a < b
, wraps to a large value. The crate also implements
*
for two ciphertexts. The default
template does not use it, and this page does not cover it.
Next steps
Secure process
Write the FHE computation for your own E3 program.
Build
Program contract
Validate inputs and verify proofs in your E3 program contract.
Build
Project Template
Find the file to edit for each part of the template.
Reference
Quick Start
Project Template
## /build/project-template
Build
Project Template
Project Template
interfold init
makes a project from the default template (
templates/default
in the Interfold
repository). This page is for developers who change that project. It describes what
interfold init
does, the folders and scripts of the project, its configuration, and the file to edit for each part.
To run the template first, see the
Quick Start
.
What interfold init does
interfold
init
[PATH] [--template
<
URL
>
] [--skip-install] [--skip-cleanup]
Argument or option
Effect
PATH
The project folder. The folder must be empty or must not exist. Without
PATH
, the command uses the current folder.
--template <URL>
The template source, in the form
git+https://github.com/theinterfold/interfold.git#main:templates/default
. The part after
#
is the branch or tag and the path.
--skip-install
Do not run
pnpm install
. Use this option for an o프로젝트로 돌아가기