RAILGUN Reloaded
    Preparing search index...

    Module @railgun-reloaded/prover

    Source: dev 05c9b95

    @railgun-reloaded/prover

    RAILGUN transaction and POI proving with Circom witnesses and Mopro Arkworks WASM. The prover accepts circuit artifacts as byte arrays in Node and browsers.

    import { createProver } from '@railgun-reloaded/prover/browser'
    // In Node, import createProver from '@railgun-reloaded/prover/node'.

    const prover = createProver({ loadArtifact })
    try {
    const { proof, publicSignals } = await prover.fullProve(inputs, wasmBytes, zkeyBytes)
    const valid = await prover.verify(expectedVkey, publicSignals, proof)
    const poiResult = await prover.prove(poiInputs)
    } finally {
    await prover.close()
    }

    Both entry points expose the same Prover and ProverOptions types. Each instance starts its worker and initializes Mopro on the first request. Witness generation, proving, and verification run outside the caller's JavaScript thread. The worker remains available for later requests.

    loadArtifact runs on the caller's thread. It receives POI_3x3 or POI_13x13 and returns authenticated ProverArtifacts: wasm and zkey byte arrays and the parsed expected vkey. The caller owns downloads, caching, and their cleanup. Transaction artifacts are supplied directly to fullProve. Arguments are copied into the worker; caller buffers remain usable.

    Pass the runtime as prover to RailgunClient.create(). Its prove method also satisfies the wallet SDK's POI prover contract. Separate instances provide independent execution for transaction proofs and background POI work.

    A download or proof-request error rejects only that request. Other pending requests continue, and the worker remains available. Initialization or worker transport failure rejects pending requests and discards the worker. The next request starts a fresh worker. The runtime does not replay failed requests. close() rejects pending operations and stops the worker. Further requests reject, and repeated close() calls wait for the same cleanup.

    Browsers need cross-origin isolation for shared WASM memory. Serve Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp. Bundle the package's worker and WASM assets. With Vite, exclude @railgun-reloaded/prover and @railgun-reloaded/mopro-wasm from dependency pre-bundling so worker asset URLs remain relative to their modules. Node requires version 22 or newer.

    import mopro from '@railgun-reloaded/mopro-wasm'
    import { createGroth16ForEngine } from '@railgun-reloaded/prover'

    await mopro.initialize()
    const prover = createGroth16ForEngine(mopro)
    const { proof, publicSignals } = await prover.fullProve(inputs, wasmBytes, zkeyBytes)
    const valid = await prover.verify(expectedVkey, publicSignals, proof)

    Mopro loads its packaged WASM and selects the worker count automatically. Use mopro.initialize({ threads: 2 }) to limit worker use, or supply bundled WASM bytes with mopro.initialize({ wasm: moproWasmBytes }).

    inputs is TransactionBigintInputs or POIBigintInputs. Transaction Merkle paths are flat at this boundary and must contain exactly 16 elements per input. Leaf indices are positions within a tree, from 0 to 65535.

    Pass the adapter as prover to RailgunClient.create(). The wallet SDK checks the transaction proof against its expected public inputs and verification key before it returns calldata.

    import { MoproTransactionProver, MoproPoiProver } from '@railgun-reloaded/prover'

    const transactionProver = new MoproTransactionProver({ wasm, zkey, vkey }, mopro)
    const { proof, publicInputs } = await transactionProver.prove(transactionInputs)
    await transactionProver.verify(publicInputs, proof)

    const poiProver = new MoproPoiProver({ wasm, zkey, vkey }, mopro)
    const poiResult = await poiProver.prove(poiInputs)
    await poiProver.verify(poiResult.publicSignals, poiResult.proof)

    transactionInputs uses TransactionCircuitInputs. poiInputs uses POIBigintInputs, padded to the selected POI circuit size. POI proofs use affine coordinates in the node's wire format. G2 coordinate pairs use [c0, c1] order. Contract calldata reverses each pair.

    The standalone provers verify generated proofs against the configured key. Use authenticated circuit artifacts. A proving key is public ceremony data, not a wallet key.

    These low-level adapters execute WASM synchronously inside the returned promise. Use them inside a caller-owned execution context, with initialized Mopro bindings. Use the worker runtimes above when the package owns execution.

    Input converters use toTransactionWitnessInputs, fromTransactionWitnessInputs, toPOIWitnessInputs, and fromPOIWitnessInputs. These describe the Circom witness format. The corresponding types are TransactionWitnessInputs and POIWitnessInputs.

    The integration tests use the published Mopro WASM package from the lockfile.

    npm ci
    npm run build
    npm run lint
    npm test

    Tests use Mopro for proof generation and verification. Fixed public-signal vectors come from the circuit witness calculators for the test inputs.

    MIT

    MoproPoiProver
    MoproTransactionProver
    createGroth16ForEngine
    toPOIWitnessInputs
    fromPOIWitnessInputs
    toTransactionWitnessInputs
    fromTransactionWitnessInputs
    Groth16Proof
    ProofResult
    MoproBindings
    Proof
    ProverArtifacts
    VKey
    Groth16Prover
    POIBigintInputs
    POIProof
    POICircuitInputs
    POIWitnessInputs
    TransactionBigintInputs
    TransactionCircuitInputs
    TransactionWitnessInputs
    TransactionPublicInputs