Status DataClose notification

Zendex Disclosed Report

Audit Report

Missing Uniqueness Constraint on nullifierA/nullifierB in join Circuit Enables Double-Spend of a Single Deposit, Draining Shared Vault Funds

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Repo & commit: hackenproof-public/zendex-sc, HEAD b25f3c3a633056907690ed868deaae0b4ad33407

Summary

ZendexVaultManager::join merges two private note-commitments into one, consuming two nullifiers (jp.nullifierA, jp.nullifierB) in a single call. Neither the Solidity contract nor the Noir join circuit enforces that the two nullifiers (equivalently, the two underlying secrets rho_a/rho_b) are distinct. A user can supply the same real, previously-deposited commitment as both "input A" and "input B" of a join, producing a new commitment commitmentC whose declared value is amount_a + amount_b — double the value actually deposited — backed by only one real deposit. Withdrawing against that fabricated commitment pays out real tokens the attacker never deposited, drawn from the shared vault pool that holds every other depositor's funds.

Root cause chain Circuit level (circuits/join/src/main.nr): the only constraint tying the two inputs together is assert(amount_a + amount_b == amount_c). Each input is independently verified (verify_nullifier, verify_commitment), but nothing constrains rho_a != rho_b, hence nothing prevents nullifier_a == nullifier_b or commitment_a == commitment_b. Contract level (ZendexVaultManager.sol:155-176): both nullifiers are validated before either is consumed: solidity _validateNullifier(jp.nullifierA); // line 167 _validateNullifier(jp.nullifierB); // line 168 ... _consume(jp.nullifierA); // line 173 _consume(jp.nullifierB); // line 174 _insert(jp.commitmentC); // line 175

If nullifierA == nullifierB, both validations pass — nullifierUsed[nullifier] isn't set true until the first _consume call, which hasn't run yet at the time of the second validation. 3. TreeOperator::consume (TreeOperator.sol:156-158) has no internal guard against consuming an already-used nullifier within the same call sequence:

solidity function consume(uint256 nullifier) external onlyManager { nullifierUsed[nullifier] = true; }

The double-consumption is silently idempotent, not reverted. 4. Grep confirms zero nullifierA != nullifierB (or equivalent) check anywhere in ZendexVaultManager.sol.

split (single nullifier) is structurally immune — this class of collision requires two parallel nullifiers in one call, which only join has.

Reproduction — 6 steps, empirically confirmed, real ZK proofs and real on-chain verifiers (no mocks) A victim deposits 5000 ZEN (real deposit, real commitment in tree). An attacker separately deposits 1000 ZEN (real deposit, real commitment commitment_A). Vault balance: 6000. Attacker generates two inclusion proofs for the same real commitment commitment_A. Attacker constructs a join proof with rho_a = rho_b, amount_a = amount_b = 1000, commitment_a = commitment_b = commitment_A, amount_c = 2000, commitment_c = new. The Noir circuit accepts this input and generates a valid proof — confirmed by both local proof verification (joinBackend.verifyProof() → true) and successful witness execution. Attacker submits the proof on-chain to join(). The real, circuit-derived Barretenberg verifier (JoinVerifier.sol, not a mock) accepts the proof. leafCount increments, nullifierUsed[nullifier] = true is set once (silently absorbing the collision), and commitmentC (declared value: 2000 ZEN) is inserted into the tree — backed by only the original 1000 ZEN deposit. Attacker calls withdraw() against commitmentC. 2000 ZEN is paid out — confirmed by direct ERC20 balance diff, not inference. Vault accounting: 0 → +5000 (victim) → +1000 (attacker) = 6000 before the exploit; 6000 − 2000 (attacker's fabricated withdrawal) = 4000 after. The victim is still owed exactly 5000 ZEN, but the vault holds only 4000 — a 1000 ZEN shortfall, exactly the attacker's fabricated profit, with no other possible source than the victim's real deposit.

Raw output:

Vault balance after both real deposits (5000 victim + 1000 attacker): 6000 STEP 3: malicious join proof generated successfully. amount_c = 2000 (from a single 1000-unit deposit) STEP 4: join() accepted on-chain. leafCount 2 -> 3 | nullifierUsed = true STEP 5: withdraw() paid out 2000 ZEN (attacker only ever deposited 1000) Attacker net profit (fabricated, not backed by any deposit): 1000 ZEN Shortfall against victim's real claim: 1000 ZEN ✔ STEP 3-6: attacker doubles their own deposit and drains the shared vault pool (91604ms) Reachability

Fully permissionless — no privileged role, no operator cooperation, no capital beyond the attacker's own deposit, no unusual conditions. Repeatable: each iteration fabricates a fixed multiple of whatever the attacker chooses to deposit, at a gas cost (~7.2M gas per join() call in testing) that is negligible relative to the fabricated profit. Affects every asset held in the shared vault (WZEN, USDT, USDC, DAI) — the attacker chooses the target asset via their own deposit.

Validation steps

Environment

Standard repo toolchain (Hardhat + Noir/Barretenberg), no environment patches required — npm install + npx hardhat compile succeed cleanly from a fresh clone (81 Solidity files compiled, zero errors). This is notably simpler than typical: no dependency pins, no manifest fixes, no version conflicts needed.

The PoC harness is cloned directly from the repository's own existing ZendexVaultManager.join.test.ts — it uses the same real Noir circuit compilation and the same real, deployed Solidity verifier contracts the protocol's own legitimate-flow tests use. No mocked circuits, no mocked verifiers, no simplified stand-ins anywhere in the proof-generation or on-chain verification path.

Reproduction steps Clone hackenproof-public/zendex-sc at commit b25f3c3a633056907690ed868deaae0b4ad33407. npm install npx hardhat compile Copy JoinNullifierCollision.poc.test.ts (attached) into test/. npx hardhat test test/JoinNullifierCollision.poc.test.ts

Expected result:

✔ STEP 3-6: attacker doubles their own deposit and drains the shared vault pool (~91s) 1 passing (2m) Raw output (fresh-clone verified, byte-identical across two independent runs) Vault balance after both real deposits (5000 victim + 1000 attacker): 6000 STEP 3: malicious join proof generated successfully. amount_c = 2000 (from a single 1000-unit deposit) STEP 4: join() accepted on-chain. leafCount 2 -> 3 | nullifierUsed = true STEP 5: withdraw() paid out 2000 ZEN (attacker only ever deposited 1000) Attacker net profit (fabricated, not backed by any deposit): 1000 ZEN Victim is still owed exactly 5000 ZEN, but the vault now only holds: 4000 Shortfall against victim's real claim: 1000 ZEN ✔ STEP 3-6: attacker doubles their own deposit and drains the shared vault pool

Every value above is read directly from on-chain state after each step — real ERC20 balanceOf diffs for the vault-in/vault-out amounts, the real leafCount counter on the Merkle tree, and the real nullifierUsed mapping — not asserted blindly or inferred. The test fails loudly if any intermediate value doesn't match what's expected, so a passing run is a direct empirical confirmation of every step in the chain, not just a final-state check.

Independently re-verified end to end on a second, separate fresh clone of the same commit, untouched by the original working tree: npm install + npx hardhat compile clean, identical proof generation, identical on-chain acceptance, identical payout and vault-balance figures shown above.

Cost note

join() costs approximately 7.2M gas per call in this environment (average of the two calls in the test) — well under the local block gas limit and not a practical barrier: the fabricated profit (1000 ZEN in this run, or any multiple of whatever the attacker deposits) far exceeds gas cost at any realistic gas price, and the attack is freely repeatable.

Attachments: join_nullifier_collision_finding.zip containing JoinNullifierCollision.poc.test.ts, test_output.txt (raw fresh-clone verification output), README.md, and BUILD_NOTES.md.

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.