Skip to content

test(sdk): ZK-062 add fuzz and property tests for note serialization, witness encoding, and Merkle paths - #468

Draft
s6pa1rta3n-lab wants to merge 1 commit into
ANAVHEOBA:mainfrom
s6pa1rta3n-lab:fix-issue-306
Draft

s6pa1rta3n-lab wants to merge 1 commit into
ANAVHEOBA:mainfrom
s6pa1rta3n-lab:fix-issue-306

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Wave Issue Key: ZK-062
Closes #306

Adds a comprehensive deterministic fuzz and property test suite for note serialization, witness and public input encoding, and Merkle path operations in the SDK (sdk/test/zk062_fuzz_property.test.ts).

Test Coverage Highlights

  • Note Serialization:
    • Seeded random round-trip invariance for importBackup(exportBackup()) preserving note secrets, scalars, and Poseidon2 commitments across 100 iterations.
    • Legacy format round-trip testing for deserialize(serialize()).
    • Single-bit and single-byte mutation fuzzing across note backup payloads.
    • Structural prefix and payload length fuzzing (INVALID_PREFIX, INVALID_LENGTH, CORRUPT_DATA).
    • Non-hex payload character injection fuzzing.
    • Fixed regressions: corrupted denomination checksum, unsupported version byte 0x02.
  • Witness & Public Input Encoding:
    • Round-trip serialization into canonical 256-byte layout and 8-field order (serializeWithdrawalPublicInputs).
    • Soroban contract verifier serialization equivalence (serializeContractVerifierInputs).
    • Circuit input packing equivalence (packWithdrawalPublicInputs).
    • Canonical field hex validation and rejection of non-canonical decimal strings (ZK-082).
    • Stellar address format validation and BN254 field encoding (encodeStellarAddress).
    • Domain-separated nullifier hash determinism (encodeNullifierHash).
    • Fixed regressions: decimal amount string "1000", 63-character hex length in field inputs.
  • Merkle Path Integrity:
    • Tree path proof generation and reconstruction against tree roots across multiple depths (3, 4, 6) using stableHash32.
    • Sibling mutation sensitivity (single-bit flips at any level break root reconstruction).
    • Equivalence between batch insertion (insertBatch) and sequential insertion (insert).
    • Empty tree root canonical zero ladder equivalence (computeMerkleZeroLadder).
    • Invariant validation for validateMerkleProof (zero root rejection, length bounds).
    • Fixed regressions: negative and out-of-bounds leaf indices, tree overflow past depth capacity.

Verification

  • Ran npx jest test/zk062_fuzz_property.test.ts in sdk:
    • 25 passed across 3 test suites, 0 failures.

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

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-062: Add fuzz and property tests for note serialization, witness encoding, and Merkle paths

1 participant