The Wrong Trail: How Systematic Enum Mapping Analysis Ruled Out the Obvious Suspect in a Filecoin Proving Bug

Introduction

In the world of cryptographic proving systems, few bugs are as frustrating as an intermittent failure that works flawlessly on one path but fails consistently on another. This article examines a concentrated debugging session within the Filecoin Curio project, where an AI assistant and a user collaborated to investigate a perplexing failure: PSProve PoRep (Proof-of-Replication) proofs were failing when processed through the CuZK GPU-accelerated proving engine, yet succeeding when routed through the traditional FFI (Foreign Function Interface) path. The investigation spanned multiple messages, multiple languages (Go, C, Rust), and multiple serialization boundaries, ultimately ruling out the most obvious suspect and redirecting attention to a far subtler issue in JSON serialization round-tripping.

The Bug: A Tale of Two Paths

The CuZK proving engine is a GPU-accelerated backend for Filecoin's proof generation pipeline. It communicates with the Go application layer via gRPC, using protobuf-defined messages. The PSProve (Proof Sharing) system allows proof computation to be distributed across multiple workers, with proof data serialized as JSON and transmitted over the network. When a PSProve worker receives proof data from a peer, it deserializes the JSON into Go structs, then re-serializes everything into a gRPC SubmitProofRequest for the CuZK server.

The bug manifested as a stark asymmetry: proofs that went through this PSProve → CuZK pipeline would fail verification, while the same proofs processed through the direct FFI path (which calls Rust natively via CGO bindings) would succeed. The user's initial hypothesis was straightforward and plausible: somewhere in the chain of RegisteredSealProof enum mappings—the numeric identifiers that tell the proving system which proof variant to use—a value was being misinterpreted across the Go-to-Rust boundary.

The Investigation Begins: Parallel Data Gathering

The assistant's first response ([msg 1]) was a model of efficient reconnaissance. Rather than reading files sequentially, it launched six parallel file reads targeting the complete enum mapping chain:

  1. proofs.go — The Go FFI bindings that call into the C shared library
  2. cgo/proofs.go — The CGO bindings providing low-level C API access
  3. porep_vproof_types.go — The Go-side proof type definitions, including StringRegisteredProofType and its ToABI() conversion method
  4. proving.pb.go — The protobuf-generated Go code defining the ProofKind enum
  5. cuzk_funcs.go — The normal PoRep C2 path that constructs SubmitProofRequest
  6. task_prove.go — The PSProve path that constructs the same request type This parallel read strategy is a hallmark of effective debugging in multi-file investigations. By fetching all six files simultaneously, the assistant minimized round-trips and established a comprehensive baseline before diving into specifics. As noted in the detailed analysis of this data-gathering phase [10], the assistant's approach mirrors how an experienced developer would open multiple editor tabs to scan a codebase.

Tracing the Enum Across Three Languages

Over the next several messages ([msg 2] through [msg 9]), the assistant methodically traced the RegisteredSealProof enum across every language boundary. The journey took it through:

The CGO bindings in cgo/const.go ([msg 2]), where Go constants like RegisteredSealProofStackedDrg2KiBV1 are mapped to C enum values via C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1. The assistant found 20 matches, suggesting a complete set of bindings [5].

The C header filcrypto.h ([msg 3], [msg 7], [msg 8]), which defines the canonical RegisteredSealProof enum using standard C auto-incrementing from 0. The declaration order—2KiB V1, 8MiB V1, 512MiB V1, 32GiB V1, 64GiB V1, followed by V1_1 variants and feature variants—matched the Go ABI ordering exactly [7].

The Go ABI constants in porep_vproof_types.go ([msg 4]), where the assistant discovered that the Go-side enum uses explicit integer assignments: RegisteredSealProof_StackedDrg2KiBV1 = RegisteredSealProof(0), RegisteredSealProof_StackedDrg8MiBV1 = RegisteredSealProof(1), and so on through value 19 [4].

The test file proofs_test.go ([msg 9]), which contains explicit assert.EqualValues assertions confirming that the CGO constants equal the ABI constants. This provided independent verification that the mapping was intentional and tested [2].

The Master Enum Mapping Table

The culmination of this tracing effort was a comprehensive mapping table presented in [msg 10] [11]. The table documented all 20 variants of RegisteredSealProof, spanning sector sizes from 2 KiB to 64 GiB across three protocol versions (V1, V1_1 with Synthetic PoRep, V1_2 with Non-Interactive PoRep), with identical numeric values across all four representations:

| Value | Go ABI | C Header | Rust | String | |-------|--------|----------|------|--------| | 0 | StackedDrg2KiBV1 | STACKED_DRG2_KI_B_V1 | StackedDrg2KiBV1 | "StackedDrg2KiBV1" | | 1 | StackedDrg8MiBV1 | STACKED_DRG8_MI_B_V1 | StackedDrg8MiBV1 | "StackedDrg8MiBV1" | | ... | ... | ... | ... | ... | | 19 | StackedDrg64GiBV1_2_Feat_NiPoRep | ..V1_2__FEAT__NON_INTERACTIVE_PO_REP | StackedDrg64GiBV1_2_Feat_NonInteractivePoRep | "StackedDrg64GiBV1_2_Feat_NonInteractivePoRep" |

This table definitively established that the enum mappings were consistent across all layers. The Go ABI values 0–19, the C enum auto-increment values 0–19, the Rust enum values (which follow the same ordering), and the string representations all aligned perfectly.

The Proto Layer and the Two Code Paths

The assistant also examined the protobuf layer, where SubmitProofRequest carries two relevant fields: ProofKind (a discriminator: POREP_SEAL_COMMIT = 1, SNAP_DEALS_UPDATE = 2, etc.) and RegisteredProof (a uint64 carrying the numeric proof type value). Both the normal path and the PSProve path used ProofKind_POREP_SEAL_COMMIT, confirming the discriminator was correct.

The critical comparison came when the assistant examined how each path constructed its request ([msg 5], [msg 6]). In the normal path (cuzk_funcs.go), sn.ProofType comes directly from storiface.SectorRef—the actual abi.RegisteredSealProof used during sealing. The VanillaProof is the raw output of GeneratePoRepVanillaProof, which is the native Rust SealCommitPhase1Output JSON serialization.

In the PSProve path (task_prove.go), the RegisteredProof comes from request.RegisteredProof, a StringRegisteredProofType deserialized from JSON received over the wire. The string is converted via ToABI() to a numeric value—which the assistant verified produces the correct constants. But the VanillaProof is obtained by re-serializing the already-deserialized Commit1OutRaw struct back to JSON using Go's json.Marshal.

This is where the assistant's investigation pivoted. As described in the analysis of this mid-investigation pivot [8], the assistant recognized that the real difference between the two paths was not in which enum value was sent, but in how the proof payload was constructed.

The Critical Insight: JSON Round-Trip Asymmetry

The assistant's key finding was that the Go Commit1OutRaw struct (defined in porep_vproof_types.go) has different field structures compared to the native Rust SealCommitPhase1Output. When the Go struct is re-serialized via json.Marshal, the output may differ from the original Rust JSON in several ways:

  1. Field ordering: Go's json.Marshal serializes struct fields in definition order, while Rust's serde may use a different order.
  2. Map key serialization: The VanillaProofs field is map[StringRegisteredProofType][][]VanillaStackedProof, and Go's JSON encoder may format map keys differently than Rust.
  3. Base64 encoding of byte arrays: When Go's json.Marshal encounters a []byte field, it automatically base64-encodes it. The content being base64-encoded differs between the two paths. The Rust CuZK server deserializes the Phase1Out field expecting the exact format produced by rust-fil-proofs SealCommitPhase1Output serialization. If the Go-re-serialized version has structural differences—even subtle ones like field ordering or whitespace—the Rust deserialization could fail or produce incorrect results.

Ruling Out the fr32 Seed Masking Hypothesis

Alongside the enum mapping investigation, the assistant also explored a separate hypothesis raised by the user: that the intermittent failure might be caused by fr32 seed masking. The powsrv utility, used for PoW challenge generation, does not apply the standard seed[31] &= 0x3f truncation that the Filecoin protocol expects. However, the assistant's analysis of the Rust challenge derivation code showed that the seed is used as raw bytes for SHA256 hashing, not directly as an Fr (finite field) element. This ruled out the seed masking as the root cause of the intermittent failure—though it remains a correctness issue in powsrv that should be addressed separately.

Diagnostic Enhancements: Preparing for the Next Phase

Having ruled out the enum mapping hypothesis and the fr32 seed masking hypothesis, the assistant took concrete steps to enable further diagnosis. It extended the existing 2KiB roundtrip test to cover the full CuZK wrapper and FFI C2 verification path, ensuring that future investigations could compare the exact byte streams produced by both paths. It also added comprehensive diagnostic logging to computePoRep in task_prove.go, capturing the exact byte streams and verification inputs at the point of failure.

These enhancements are crucial for the next phase of investigation. With the enum mappings confirmed correct and the seed masking ruled out, the remaining hypothesis is that the JSON round-trip introduces a subtle structural difference. The diagnostic logging will allow the team to capture the actual serialized payloads from both paths and compare them byte-by-byte, identifying the exact discrepancy that causes the CuZK server to fail.

Methodology: Lessons in Structured Debugging

The investigation documented in this chunk exemplifies several principles of effective debugging in multi-language distributed systems:

Rule out the obvious first. The user's hypothesis about enum mismatches was the most obvious suspect. The assistant systematically traced every enum value across every language boundary, building a comprehensive mapping table that definitively ruled out this hypothesis. As the analysis in [11] notes, "the discipline to systematically rule out the obvious before diving into more complex hypotheses is what separates effective debugging from guesswork."

Verify against the source of truth. Rather than trusting secondary representations, the assistant read the canonical C header file filcrypto.h directly to confirm the enum values [7]. This verification step transformed the conclusion from "the mappings appear consistent" to "the mappings are confirmed consistent against the canonical definition."

Compare code paths side by side. The assistant didn't just describe each path in isolation; it presented them side by side, highlighting the specific differences in how RegisteredProof is sourced and how VanillaProof is constructed [11]. This comparative approach made the critical difference immediately apparent.

Distinguish confirmed from hypothetical findings. The assistant was careful to state what was confirmed (enum mappings are correct) versus what was hypothesized (the JSON round-trip is the likely cause). This clarity prevents future investigators from retracing the same ground.

The Broader Significance

This investigation has implications beyond the specific PSProve PoRep bug. It highlights a class of bugs that are notoriously difficult to diagnose: serialization asymmetry in polyglot systems. When data is serialized in language A (Rust), deserialized in language B (Go), and then re-serialized in language B, the output may differ from the original in subtle ways that cause failures at the next deserialization step. Each individual serialization/deserialization step works correctly—the Go JSON encoder produces valid JSON from the Go struct, and the Rust JSON decoder correctly parses that JSON. The problem is that the Go struct representation differs from the Rust struct representation in ways that affect the serialized form.

This is particularly insidious because it doesn't manifest as a crash or error during serialization—it manifests as a verification failure much later in the pipeline. The proof is generated, transmitted, and received successfully, but the verification step fails because the public inputs were derived from slightly different data.

The investigation also demonstrates the value of definitive negative results. Ruling out the enum mapping hypothesis with comprehensive evidence prevented wasted effort and narrowed the search space to the remaining possibilities. In many debugging cultures, negative results are undervalued—but as this session shows, a well-documented negative result can be as valuable as a positive finding.

Conclusion

The debugging session examined in this chunk represents a masterclass in structured, multi-language debugging. The assistant systematically traced RegisteredSealProof enum mappings across Go, C, and Rust, built a comprehensive 20-row mapping table, compared two code paths side by side, ruled out the user's initial hypothesis with definitive evidence, investigated a secondary hypothesis about fr32 seed masking, and redirected attention to the likely root cause: JSON serialization asymmetry in the PSProve round-trip.

The diagnostic enhancements—extended roundtrip tests and comprehensive logging—position the team for the next phase of investigation, where the exact byte-level discrepancy can be captured and analyzed. The enum mapping investigation is closed; the JSON serialization investigation has begun.

For anyone debugging cross-language distributed systems, this session offers a valuable template: gather all data before drawing conclusions, verify against canonical sources, compare paths side by side, and never underestimate the value of a definitive negative result. The most obvious suspect is often the wrong trail—but following it to its end with thorough evidence is the only way to know for sure.