The Interfold 백서

The Interfold

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 45쪽 중 10쪽

nd CRISP deploys read the identity and the verifier artifact from prover.json , unless you set OPENVM_APP_EXE_COMMIT and OPENVM_APP_VM_COMMIT with either OPENVM_VERIFIER_ARTIFACT and OPENVM_VERIFIER_SHA256 or OPENVM_HALO2_VERIFIER and OPENVM_HALO2_RUNTIME_CODE_HASH . Start the program server Run interfold program start . The service picks its worker and runs the worker's check , which loads every key and both KZG parameter files and recomputes the receipt identity. Then it listens on 127.0.0.1:13151 . Check the server Run curl http://localhost:13151/health . The server returns {"status":"healthy","e3_id":"0"} . Deadlines and memory Variable Default Meaning OPENVM_CHECK_TIMEOUT_SECS 1800 Deadline for the startup check OPENVM_PROVE_TIMEOUT_SECS 86400 Deadline for one proof. The worker is stopped and the round fails. OPENVM_SEGMENT_MEMORY_BYTES 8 GiB Read by compile . The segment memory limit; 8 GiB fits a 16 GB GPU. The worker holds the guest's input stream in memory twice, about eight times the binary size of the round. Jobs are in memory: a restart of the service loses accepted jobs, and the operator must reconcile them. Next steps Verify the compute provider How the proof is checked on-chain, and how to check the receipt identity. Complete example See the dev runner and the webhook in one E3. Configuration reference Every key of interfold.config.yaml . Program Contract Verify the Compute Provider ## /build/e3-program/verify-compute-provider Build E3 Program Anatomy Verify the Compute Provider Verify the Compute Provider An OpenVM proof shows which guest ran and what it revealed. This page explains how the Interfold contract checks that proof, which values each check binds, and how to confirm the receipt identity of a deployment. It is for E3 program developers, auditors, and operators who did not build the deployment. At the end, you can tie a deployed verifier to a guest and its source. Two checks on one proof publishCiphertextOutput checks the compute proof two times, in this order ( InterfoldLifecycle.publishCiphertext and _isValidCiphertextHash ): The protocol ciphertext verifier of the encryption scheme. For BFV this is OpenVmBfvCiphertextVerifier ( contracts/verifiers/bfv/OpenVmBfvCiphertextVerifier.sol ). verify on the program contract of the E3. Before these checks, the Interfold contract calls verifyDataAvailability on the program contract. If a verifier returns false , the call reverts with InvalidOutput . After the program check, the Interfold contract reads the stage again and checks committee viability again. Then it stores the output hash and commitment and moves the E3 to CiphertextReady . Both verifiers rebuild the same journal and call the same OpenVmReceiptVerifier : openVmVerifier. verify (proof.seal , imageId , sha256 (journal)); OpenVmReceiptVerifier ( contracts/verifiers/OpenVmReceiptVerifier.sol ) checks that imageId is its own identity, decodes the seal, and calls the Halo2 verifier with the digest as the public values and its two application commitments. The Halo2 verifier reverts when the proof does not show that the guest with those commitments revealed that digest. What each check binds The journal has nine 32-byte words ( lib/OpenVmComputeProof.sol ). The table shows where each verifier gets each word. A call argument is a value from the caller of publishCiphertextOutput . Word OpenVmBfvCiphertextVerifier MyProgram.verify (template) Chain ID block.chainid block.chainid Interfold contract msg.sender (the Interfold proxy) address(interfold) E3 ID Call argument Call argument Encryption scheme ID e3.encryptionSchemeId e3.encryptionSchemeId Committee public key hash e3.committeePublicKey e3.committeePublicKey Output ciphertext hash Call argument Call argument Output SAFE commitment Call argument Call argument BFV parameter hash Request-time hash, compared with the proof Hash that validate stored, compared with the proof Input root Proof (not checked) Root of the on-chain input tree, compared with the proof The caller supplies the output hash and the commitment, and the Interfold contract stores them in the E3. The proof binds them to this chain, this Interfold contract, this E3, this committee key, and these parameters. The prover cannot change these other words. 🚫 The protocol verifier does not check the input root. The program contract must compare the input root in the proof with its own tree root. If it does not, a prover can publish an output that it computed over inputs that nobody submitted. MyProgram.verify and CRISPProgram.verify both make this comparison. The guest derives the input root from the ciphertexts it reads. Its input has no root field ( e3_openvm_types::GuestHeader ), and every ciphertext contributes a leaf whatever the policy selects. The root in the journal is therefore a function of the inputs that the output used. The receipt identity OpenVmReceiptVerifier binds three values, all immutable and public : verifier : the Halo2 verifier contract; appExeCommit : the commitment of the guest executable; appVmCommit : the commitment of the VM configuration ( guest/openvm.toml ). Its imageId is keccak256(abi.encode(keccak256("INTERFOLD_OPENVM_RECEIPT_V1"), verifier, appExeCommit, appVmCommit)) . The protocol verifier and the program contract must both name this imageId . The constructor refuses a verifier address with no code and a commitment that is zero or not a canonical BN254 scalar. These properties hold without any action from you: The verifier is fixed at request time. bindCryptoConfig copies the current ciphertext verifier of the scheme and the parameter hash into a per-E3 record. A later setCiphertextVerifier changes only future requests. The identity cannot change. OpenVmBfvCiphertextVerifier.imageId and openVmVerifier are immutable . A rebuilt guest needs new verifiers. One verifier for each scheme. The Interfold contract keeps one current ciphertext verifier for each encryption scheme. Every BFV E3 program on a deployment must use the identity that it names. An E3 program can keep its own identity and receipt verifier. The template sets them in the constructor and has no setter. CRISPProgram has setOpenVmVerifier , which only its owner can call and which takes the new verifier's identity with it. Every constructor here refuses an identity that its receipt verifier does not report. A change of verifier cannot replace an output that the Interfold contract already accepted. It can make an E3 in progress fail, because verify then checks the proof against a different identity. Check a deployment Use this procedure to compare a deployed verifier with a guest. You need Foundry ( cast ), an RPC URL, and the Interfold contract address from Contract Addresses . Read the verifier address cast call < INTERFOLD_ADDRES S > "getCiphertextVerifier(bytes32)(address)" \ $( cast keccak "fhe.rs:BFV") --rpc-url < RPC_UR L > The result is the ciphertext verifier for new BFV requests. Read the identity cast call < VERIFIER_ADDRES S > "imageId()(bytes32)" --rpc-url < RPC_UR L > cast call < VERIFIER_ADDRES S > "openVmVerifier()(address)" --rpc-url < RPC_UR L > cast call < RECEIPT_ADDRES S > "appExeCommit()(bytes32)" --rpc-url < RPC_UR L > cast call < RECEIPT_ADDRES S > "appVmCommit()(bytes32)" --rpc-url < RPC_UR L > cast call < RECEIPT_ADDRES S > "verifier()(address)" --rpc-url < RPC_UR L > Compare with the guest Build the guest from the source you trust with interfold program compile in its project. Compare app_exe_commit and app_vm_commit in .interfold/caches/openvm/prepared/identity.json with the two commitments from the chain. The values must be equal. Check the program contract Read imageId() on the program contract. Read verifier() on a template program or openVmVerifier() on CRISPProgram . Compare them with the values from the previous steps. Generate the provenance manifest From the repository root, run: pnpm provenance:manifest --project < PROJECT_DI R > --config < PROVER_JSO N > --prover < WORKE R > \ --rpc < RPC_UR L > --verifier < VERIFIER_ADDRES S > --out manifest.json --project is the project whose guest the worker configuration describes. It defaults to examples/CRISP . Make sure that the manifest shows "complete": true . The unresolved list names each field that the script did not resolve. The manifest ( scripts/generate-provenance-manifest.ts ) records these values: The source commit and the project's commit, whether both are clean, and the digests of the root and worker lockfiles, the project's lockfile, the guest lockfile, and the guest's openvm.toml The SHA-256 of the application key, the executable, the aggregation key, the Halo2 key, the verifier artifact, the Halo2 parameter files, and the worker The two application commitments, and whether the worker's check passed The chain ID, the three verifier addresses and the hashes of their code, and whether the deployed identity and Halo2 runtime match the configured guest and artifact The manifest is complete: false when a field is missing. An incomplete manifest records an unfinished check. It is not a passing result. Reproduce the identity from source The manifest checks artifacts and the chain against each other. It does not rebuild the guest. To check the commitments against the source, rebuild the guest from a clean checkout with the pinned toolchains: cargo-openvm v2.0.2, its guest toolchain, and the guest's Cargo.lock ( OPENVM_BUILD_LOCKED=1 ). Then run the worker's prepare and compare the new identity.json . The SHA-256 of the executable is not the executable commitment. SHA-256 checks that a file arrived intact. The OpenVM commitment comes from the program's memory image and the VM. The manifest records both values for these two different purposes. Limits of these checks Proxy upgrades. The Interfold contract is an upgradeable proxy. The per-E3 verifier record protects an E3 from setCiphertextVerifier . It does not protect against an upgrade of the proxy. That control belongs to governance . Program values. The protocol verifier and each program contract keep separate values. The procedure above reads both. Unproved mocks. With TEMPLATE_UNPROVED_TEST=1 on the local chain, the template deploys MockOpenVmReceiptVerifier . With CRISP_UNPROVED_TEST=1 , CRISP deploys it on the local chain, and on Sepolia when ALLOW_SEPOLIA_UNPROVED_COMPUTE=true is also set. This verifier accepts every seal, and the dev runner returns a placeholder seal. Such an E3 proves nothing about the computation. To detect the mock, call imageId() on the receipt verifier. The mock returns keccak256("INTERFOLD_LOCAL_UNPROVED_TEST") . A real OpenVmReceiptVerifier returns the identity of its guest. Audit. The compute path and the OpenVM verifier integration are not audited. Next steps Contract addresses The deployed Interfold contract and verifier addresses for each network. Compute provider How the guest makes the journal and the proof. Program contract The verify function that makes the input root comparison. Compute Provider Complete Example ## /build/e3-program/complete-example Build E3 Program Anatomy Complete Example Complete Example This page follows one E3 through the default template. The E3 adds two encrypted numbers. Each step names the file that does the work, the contract function it calls, and the event that marks the result. It is for developers who want to see how the parts of an E3 program connect before they change one. At the end, you know where to look when a step fails. Before you start Make a project with interfold init and complete its setup. See Quick Start . Template paths on this page are relative to the project root. Paths that start with crates/ or packages/ are in the Interfold repository. The local scripts run in dev mode ( E3_PROGRAM__DEV=true , unless TEMPLATE_REAL_PROOFS=1 ). The compute proof is a mock, and MockOpenVmReceiptVerifier accepts it. The rest of the flow is the same as in production. The E3 at a glance One E3 in the template 1 Deploy 2 Request 3 Committee key 4 Inputs 5 Compute 6 Publish output 7 Decrypt 01 dev_ciphernodes.sh E3ProgramRegistered Deploy deploy/default.ts deploys the verifiers and MyProgram , and registers the program. Start the stack Run pnpm dev:all in the project root. scripts/dev_all.sh calls scripts/dev_all_concurrently.sh , which starts six processes: Process Command What it does FRONTEND pnpm dev:frontend Serves the client at http://localhost:3000 EVM anvil Local chain on port 8545, chain ID 31337, one block each second CHAIN node ./scripts/anvil-automine.mjs Moves the chain time forward and fulfills local randomness requests CIPHER pnpm dev:ciphernodes Deploys the contracts and starts five ciphernodes SERVER TEST_MODE=1 pnpm dev:server Runs the coordination server, server/index.ts , on port 8080 PROGRAM pnpm dev:program Runs interfold program start , which starts the program server on port 13151 Follow one E3 Deploy the contracts scripts/dev_ciphernodes.sh runs scripts/deploy-local.ts . That script deploys the Interfold contracts with mocks, and then calls deployTemplate in deploy/default.ts . deployTemplate does these actions in order: Deploys MockOpenVmReceiptVerifier (with TEMPLATE_UNPROVED_TEST=1 on the local chain) or an OpenVmReceiptVerifier for the guest that interfold program compile built. Deploys OpenVmBfvCiphertextVerifier with that receipt verifier and its imageId . Calls setCiphertextVerifier for keccak256("fhe.rs:BFV") . Deploys MyProgram with the Interfold address, the receipt verifier, and the imageId . Calls registerE3Program . The Interfold contract probes supportsInterface and emits E3ProgramRegistered . deployTemplate writes the addresses to interfold.config.yaml . Then dev_ciphernodes.sh starts the ciphernodes with interfold nodes up . Request the E3 In the client, client/src/pages/steps/RequestComputation.tsx builds the request. It uses committee size 0 ( Minimum ), parameter set 0 , and an input window. The window opens 15 seconds after the current chain time and lasts 100 seconds. It calls getE3Quote , approveFeeToken , and requestE3 from the SDK. On-chain, Interfold.request stores the E3 and calls MyProgram.validate . validate stores keccak256(e3ProgramParams) , starts an input tree of depth 20, and returns keccak256("fhe.rs:BFV") . The Interfold contract takes the fee, asks the registry for a committee, and emits E3Requested . Publish the committee key The ciphernodes select a committee, run DKG, and publish the committee public key. The E3 moves to KeyPublished . The serialized key arrives in CommitteePublicKeyChunkPublished events. server/index.ts listens for these events in setupEventListeners . It assembles the key and checks it against the commitment with validatePublicKeyCommitment . Then scheduleE3 waits until the chain time reaches inputWindow[1] . Encrypt and submit the inputs client/src/pages/steps/EnterInputs.tsx encrypts each number with encryptNumber and computes its SAFE commitment with computeCiphertextCommitment . It calls publishInput in client/src/utils/input.ts for each input: client/src/utils/input.ts const data = encodeAbiParameters ( parseAbiParameters ( 'bytes, bytes32' ) , [ input , ciphertextCommitment , ]) MyProgram.publishInput inserts the commitment as a leaf and emits InputPublished(e3Id, ciphertext, index) . Run the secure process When the input window closes, runProgram in server/index.ts reads paramSetRegistry(e3.paramSet) from the Interfold contract. It reads all InputPublished events for the E3 from MyProgram . The server skips the E3 when it has fewer than two inputs. callFheRunner in server/runner.ts posts the job to http://127.0.0.1:13151/run_compute . The body has the E3 ID, the proof domain, the parameters, the inputs, and the callback URL http://127.0.0.1:8080 . The dev runner ( crates/support-scripts/dev/src/main.rs ) builds a ComputeManager with your fhe_processor from program/src/lib.rs . start(policy()) builds the input tree, runs the processor, and computes the output hash, commitment, parameter hash, and input root. The runner encodes a mock proof with the parameter hash and the input root. With real proofs, the OpenVM service runs the same secure process natively, proves it in guest/ , and returns the verified OpenVM envelope instead. Publish the output The program server posts the webhook to the server. handleWebhookRequest in server/index.ts stores the ciphertext under its Keccak-256 hash in .interfold/data-availability . Then it calls publishCiphertextOutput through the SDK. Interfold.publishCiphertextOutput does these checks in order: The E3 is in KeyPublished , the input window is closed, and the compute deadline has not passed. The output is not published yet, and the committee still meets its threshold. MyProgram.verifyDataAvailability checks that the Keccak-256 hash of the raw ciphertext equals the content hash. OpenVmBfvCiphertextVerifier.verify rebuilds the journal and calls the receipt verifier. MyProgram.verify compares the parameter hash and the input root, rebuilds the journal, and calls the receipt verifier. The E3 moves to CiphertextReady . The Interfold contract emits CiphertextOutputReferencePublished and E3StageChanged . Decrypt the result The ciphernodes fetch the output bytes from the server at /availability/objects/<contentHash> . This is the mock_http data-availability mode in interfold.config.yaml . The committee makes decryption shares. The aggregator combines T + 1 of them and calls publishPlaintextOutput . The E3 moves to Complete , and the Interfold contract emits PlaintextOutputPublished . client/src/pages/steps/EncryptSubmit.tsx listens for PlaintextOutputPublished . It decodes the output with decodePlaintextOutput and shows the sum. The Interfold contract emits CiphertextOutputReferencePublished when it accepts the output. The SDK event type CIPHERTEXT_OUTPUT_PUBLISHED listens for CiphertextOutputPublished , which Interfold.sol declares but does not emit. Where to change the example Change Files The computation program/src/lib.rs ( fhe_processor ) The input leaf or the selection program/src/lib.rs ( policy ) and contracts/MyProgram.sol ( publishInput ), together Input validation contracts/MyProgram.sol ( publishInput ) The request parameters client/src/pages/steps/RequestComputation.tsx How inputs reach the compute provider server/index.ts ( runProgram ) and server/runner.ts How the result is shown client/src/pages/steps/EncryptSubmit.tsx and client/src/pages/steps/Results.tsx Compare with CRISP CRISP uses the same parts with production choices: Step Template CRISP Input submission One publishInput call with ciphertext and commitment publishInput with a Noir proof, then finalizeInput with a DA receipt Input leaf The SAFE commitment sha256(keccak256(ciphertext) ‖ commitment ‖ slot ‖ parent) mod the BN254 field Input policy InputPolicy::default() policy::crisp() , one input for each slot Compute provider Dev runner with a mock proof CRISP's OpenVM service and guest, proved on the operator's GPU or CPU Data availability Local file store and a hash check AvailVectorXDataAvailabilityVerifier (a mock on a local chain) Output publisher server/index.ts examples/CRISP/server ( /state/add-result webhook) Get help Gnosis Guild (opens in a new tab) is the initial development team of the Interfold. Contact Gnosis Guild with questions about this example. Next steps Secure process Change fhe_processor and test it. Client and server The client and the coordination server in more detail. Run CRISP Run a full CRISP round on a local stack. Verify the Compute Provider The I
프로젝트로 돌아가기