Skip to content

feat: ZK-071 – split withdrawal circuit schema from contract verifier payload explicitly - #464

Open
rushikeshgarad2024-dev wants to merge 1 commit into
ANAVHEOBA:mainfrom
rushikeshgarad2024-dev:feat/zk-071-split-circuit-verifier-schemas
Open

rushikeshgarad2024-dev wants to merge 1 commit into
ANAVHEOBA:mainfrom
rushikeshgarad2024-dev:feat/zk-071-split-circuit-verifier-schemas

Conversation

@rushikeshgarad2024-dev

Copy link
Copy Markdown

Summary

Resolves #347 (Wave Issue Key: ZK-071).

Context & Implementation

This PR explicitly separates the full withdrawal circuit schema from the reduced contract verifier payload to eliminate schema confusion and prevent runtime layout mismatch between off-chain witness generation and on-chain verification.

  1. Explicit Schema & Type Separation in SDK (sdk/src/public_inputs.ts, sdk/src/proof.ts):

    • CIRCUIT_PUBLIC_INPUT_SCHEMA / WITHDRAWAL_PUBLIC_INPUT_SCHEMA: Defined with all 8 fields: [pool_id, root, nullifier_hash, recipient, amount, relayer, fee, denomination], frozen against runtime mutation.
    • CONTRACT_VERIFIER_INPUT_SCHEMA: Defined with the exact 6 reduced fields: [root, nullifier_hash, recipient, amount, relayer, fee], frozen.
    • Distinct TypeScript interfaces: WithdrawalCircuitPublicInputs, FullWithdrawalCircuitPublicInputs, ContractVerifierPublicInputs.
    • Deterministic projection: deriveContractVerifierInputs(full: WithdrawalCircuitPublicInputs): ContractVerifierPublicInputs with full input validation (rejects missing fields, no silent drops).
    • Serialization: serializeContractVerifierInputs emits 6 canonical field hexes (192 bytes).
    • Formatting helper: ProofGenerator.formatContractVerifierPayload.
  2. Soroban Contract Verifier Support (contracts/privacy_pool/src/types/state.rs, contracts/privacy_pool/src/crypto/verifier.rs):

    • CircuitPublicInputs (8 fields) and ContractVerifierPublicInputs (6 fields) with explicit projection CircuitPublicInputs::to_contract_verifier_inputs(&self).
    • compute_vk_x accepts 6 contract verifier inputs; compute_vk_x_circuit accepts 8 circuit inputs.
    • Verifier dynamically checks IC length (EXPECTED_IC_VECTOR_LENGTH = 7 for 6 inputs, or 9 for 8 inputs) and validates structural field boundaries.
  3. Validation & Test Suite:

    • test/schema_parity.test.ts updated to enforce distinct schemas, 6-input contract verifier schema, explicit exclusion of pool_id and denomination from contract verifier, and deterministic derivation.
    • Unit test test_circuit_public_inputs_to_contract_verifier_inputs_projection added to state_test.rs.
    • SDK builds cleanly (npm run build) and schema parity tests pass 100%.

Stellar Payout Address

Stellar Address: GC5U46IS25KYFKNHDXEHR3KTQB3DVIBM4NW5BH4MVUE2G77STCJP4IHF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZK-071: Split the withdrawal circuit schema from the contract verifier payload explicitly

1 participant