Skip to content

feat: merkle batch payment external signer support#12

Open
Nic-dorman wants to merge 2 commits intomainfrom
feat-merkle-external-signer
Open

feat: merkle batch payment external signer support#12
Nic-dorman wants to merge 2 commits intomainfrom
feat-merkle-external-signer

Conversation

@Nic-dorman
Copy link
Copy Markdown
Contributor

Summary

Extends the external signer support (PR #10) to cover merkle batch payments — the gas-efficient path for uploads with 64+ chunks.

The problem: pay_for_merkle_batch requires a Wallet on the Rust side. Desktop apps using WalletConnect can't call wallet.pay_for_merkle_tree() directly.

The solution: Same prepare/finalize pattern as the wave-batch PR:

  1. client.prepare_merkle_batch_external(addresses, data_type, data_size) — builds tree, collects candidate pools → returns PreparedMerkleBatch with depth, pool_commitments, timestamp
  2. Frontend calls pay_for_merkle_tree(depth, pool_commitments, timestamp) via WalletConnect → gets back winner_pool_hash
  3. finalize_merkle_batch(prepared, winner_pool_hash) — finds winner pool, generates per-chunk proofs

Changes

  • PreparedMerkleBatch: New struct with public payment params + private tree/pool data
  • prepare_merkle_batch_external(): Phase 1 — no wallet needed
  • finalize_merkle_batch(): Phase 2 — no wallet needed
  • ExternalPaymentInfo enum: WaveBatch(PaymentIntent) | Merkle(PreparedMerkleBatch)file_prepare_upload auto-selects based on chunk count
  • finalize_upload_merkle(): Handles merkle variant
  • Refactored pay_for_merkle_single_batch: Now uses prepare + finalize internally

No breaking changes

Existing wallet-based flows (file_upload_with_mode, pay_for_merkle_batch) work identically — pay_for_merkle_single_batch was refactored to use the new functions internally.

Tests

  • 3 new unit tests for finalize_merkle_batch (valid winner, invalid winner, proof deserialization)
  • All 108 tests pass (105 existing + 3 new)
  • Clippy clean, fmt clean

Test plan

  • cargo check --all passes
  • cargo clippy -p ant-core -- -D warnings clean
  • cargo fmt --all -- --check clean
  • cargo test -p ant-core --lib — 108 tests pass
  • E2E: prepare_merkle_batch_external → external payment → finalize_merkle_batch on devnet

Usage from ant-gui

let prepared = client.file_prepare_upload(&path).await?;

match prepared.payment_info {
    ExternalPaymentInfo::WaveBatch(intent) => {
        // Frontend calls payForQuotes() with intent.payments
    }
    ExternalPaymentInfo::Merkle(ref merkle) => {
        // Frontend calls pay_for_merkle_tree(depth, pool_commitments, timestamp)
        // Returns winner_pool_hash
    }
}

🤖 Generated with Claude Code

Nic-dorman and others added 2 commits March 27, 2026 09:41
Adds prepare/finalize split for merkle batch payments, matching the
wave-batch external signer pattern from PR #10.

For uploads with 64+ chunks, merkle payments reduce gas costs by paying
for the entire batch in a single on-chain transaction. This change
allows external signers (WalletConnect) to submit that transaction.

Changes:
- PreparedMerkleBatch: holds tree, candidate pools, pool commitments
  for the frontend to call pay_for_merkle_tree()
- prepare_merkle_batch_external(): Phase 1 — build tree, collect
  candidates, return payment data. No wallet needed.
- finalize_merkle_batch(): Phase 2 — generate per-chunk proofs from
  the winner pool hash. No wallet needed.
- ExternalPaymentInfo enum: WaveBatch | Merkle — file_prepare_upload
  auto-selects based on chunk count (threshold: 64)
- finalize_upload_merkle(): handles merkle variant of finalize
- Refactored pay_for_merkle_single_batch to use the new functions
  internally, eliminating code duplication

No breaking changes — existing wallet-based flows are unchanged.
All 105 tests pass, clippy clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover:
- Valid winner pool hash → proofs generated for all chunks
- Invalid winner pool hash → error
- Generated proofs round-trip through deserialize_merkle_proof

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant