Centralize ZK constants and refactor withdrawal tests (ZK-002, ZK-003…#332
Merged
ANAVHEOBA merged 1 commit intoANAVHEOBA:mainfrom Apr 25, 2026
Merged
Conversation
…, ZK-034, ZK-037) - Create shared constants modules in SDK (zk_constants.ts) and Noir (lib/src/constants.nr) - Centralize tree depth, field widths, zero-address semantics, amount encoding - Extract withdrawal circuit tests from main.nr into dedicated tests.nr module - Add circuit-adjacent Merkle root validation (canonical + non-zero checks) - Build negative tamper matrix for proof boundary validation - Update all SDK and circuit files to use centralized constants - Add MERKLE_ROOT error code for root-specific validation Fixes ANAVHEOBA#246, ANAVHEOBA#247, ANAVHEOBA#278, ANAVHEOBA#281
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR centralizes ZK protocol constants across Noir circuits and TypeScript SDK, refactors withdrawal circuit tests into a dedicated module, adds circuit-adjacent Merkle root validation, and implements a negative tamper matrix for proof boundary validation.
Changes
ZK-002: Centralize ZK Constants
sdk/src/zk_constants.tswith centralized constants for:MERKLE_TREE_DEPTH(20)NOTE_SCALAR_BYTE_LENGTH(31)MERKLE_NODE_BYTE_LENGTH(32)ZERO_FIELD_HEX(64 zeros)STELLAR_ZERO_ACCOUNT(GAAAAAAAA...WHF)GROTH16_PROOF_BYTE_LENGTH(256)BN254_FIELD_MODULUSandBN254_FIELD_BYTE_LENGTHcircuits/lib/src/constants.nrwith shared Noir constantsZK-003: Refactor Withdrawal Circuit Tests
circuits/withdraw/src/main.nrinto dedicatedcircuits/withdraw/src/tests.nrmod testsdeclaration in main.nr to import the test moduleZK-034: Circuit-Adjacent Root Validation
sdk/src/merkle.ts:WitnessValidationErrorwithMERKLE_ROOTerror codesdk/test/merkle_root_validation.test.tsZK-037: Negative Tamper Matrix
sdk/test/verification_harness.test.tsTesting
All existing tests should remain green after migration. New test suites added:
sdk/test/merkle_root_validation.test.ts- root canonical and non-zero validationsdk/test/verification_harness.test.ts- negative tamper matrixFixes