Skip to content

LP-183 reference impl: Go port of ZAP envelope decode precompile (renumbered from LP-182) #75

@abhicris

Description

@abhicris

Renumber note (2026-06-01): This was filed as LP-182 in the title. LP-182 was consumed by Agent Payment Standard (luxfi/LPs#660, also abhicris) earlier today. This issue is renumbered to LP-183 going forward.

Problem

The ZAP wire transport (PR #21) ships a Rust reference codec for PaymentOffer / PaymentProof envelopes. A pure-Solidity decoder of the same format benchmarks at ~4.9M gas per 1 KiB frame — prohibitive for the per-payment, per-anchor, per-message decode that AgentEscrow + future bridge anchors need to do inline.

We need a native EVM precompile at address 0x0c (canonical short form) that decodes a ZAP frame into an ABI-encoded tuple (uint8 version, uint8 scheme, bytes32 headerDigest, bytes payload, uint8 nestedTag, bytes nestedPayload), with the same byte-for-byte semantics as the Rust codec.

This is the kcolbchain-side reference implementation for LP-183. The luxfi/LPs proposal will land separately; this issue tracks the Go port of the decode path so the precompile is callable from any Lux subnet (and from Create Protocol at genesis).

Proposed Approach

  1. Port the Rust ZAP envelope decoder (PR zap_transport: binary wire encoding for PaymentOffer / PaymentProof #21 codec) to Go, preserving:
    • TLV walk with bounds checks before sub-buffer allocation
    • CRC-32C (Castagnoli) verification as the final step
    • Single level of nested envelope surfacing (x402, Warp 2.0)
    • 16 KiB hard ceiling on frame size; revert with full gas consumption on oversize
  2. Gas pricing: gas = 50 + 8 * len(input), calibrated against RIPEMD-160 and IDENTITY curves.
  3. Shipped as a standalone Go module that any EVM precompile registry (luxfi/precompile, parsdao/precompile) can register at 0x0c.
  4. Test corpus: 30 vectors covering happy-path (12), x402-nested (8), Warp-2.0-nested (4), adversarial (6).

Acceptance Criteria

  • Go decoder matches Rust output on all 30 test vectors byte-for-byte
  • Fuzz harness: 1M random byte strings, no panics, every input either decodes or reverts cleanly
  • Bench harness shows <50us decode for 16 KiB frame on standard precompile bench
  • CRC verification is last; cheap structural checks revert with full-linear gas
  • Documented as the spec-authoritative reference for LP-183

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions