feat: merkle batch payment external signer support#12
Open
Nic-dorman wants to merge 2 commits intomainfrom
Open
feat: merkle batch payment external signer support#12Nic-dorman wants to merge 2 commits intomainfrom
Nic-dorman wants to merge 2 commits intomainfrom
Conversation
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>
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
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_batchrequires aWalleton the Rust side. Desktop apps using WalletConnect can't callwallet.pay_for_merkle_tree()directly.The solution: Same prepare/finalize pattern as the wave-batch PR:
client.prepare_merkle_batch_external(addresses, data_type, data_size)— builds tree, collects candidate pools → returnsPreparedMerkleBatchwithdepth,pool_commitments,timestamppay_for_merkle_tree(depth, pool_commitments, timestamp)via WalletConnect → gets backwinner_pool_hashfinalize_merkle_batch(prepared, winner_pool_hash)— finds winner pool, generates per-chunk proofsChanges
PreparedMerkleBatch: New struct with public payment params + private tree/pool dataprepare_merkle_batch_external(): Phase 1 — no wallet neededfinalize_merkle_batch(): Phase 2 — no wallet neededExternalPaymentInfoenum:WaveBatch(PaymentIntent) | Merkle(PreparedMerkleBatch)—file_prepare_uploadauto-selects based on chunk countfinalize_upload_merkle(): Handles merkle variantpay_for_merkle_single_batch: Now uses prepare + finalize internallyNo breaking changes
Existing wallet-based flows (
file_upload_with_mode,pay_for_merkle_batch) work identically —pay_for_merkle_single_batchwas refactored to use the new functions internally.Tests
finalize_merkle_batch(valid winner, invalid winner, proof deserialization)Test plan
cargo check --allpassescargo clippy -p ant-core -- -D warningscleancargo fmt --all -- --checkcleancargo test -p ant-core --lib— 108 tests passprepare_merkle_batch_external→ external payment →finalize_merkle_batchon devnetUsage from ant-gui
🤖 Generated with Claude Code