feat(payment): pay N merkle trees in one tx (payForMerkleTrees) - #15
feat(payment): pay N merkle trees in one tx (payForMerkleTrees)#15Nic-dorman wants to merge 1 commit into
Conversation
…010) Adds the batched entry point so external-signer uploads need one wallet confirmation per <=4 trees instead of one per tree (V2-989): - contract: payForMerkleTrees(MerkleTreePayment[]), all-or-nothing, per-tree MerklePaymentMade events in input order, MAX_TREES_PER_PAYMENT=16 constant getter as the client feature probe; winner-pool seed gains the tree index; repo contract aligned with the deployed production source (Ownable + setBatchLimit, solc 0.8.33) - rust: Wallet::pay_for_merkle_trees, external_signer:: pay_for_merkle_trees_calldata, handler decodes ALL MerklePaymentMade events of a tx in log order; MERKLE_TREES_PER_PAYMENT=4 calldata cap exported for consumers - retry: estimation-time reverts keep their revert data so contract errors (e.g. PaymentAlreadyExists) decode to typed errors instead of being retried and stringified - tests: Foundry adversarial suite (15) + Anvil integration tests for the batched path incl. external-signer raw-calldata e2e Linear: V2-989 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
ADR-0010 draft (for filing in ant-node ADR-0010: Batched Merkle Tree Payments (payForMerkleTrees)
ContextExternal-signer uploads (ant-ui via WalletConnect/MetaMask, mobile SDKs) pay Two facts shape the solution space:
Decision Drivers
Considered Options
DecisionWe will add an additive entry point to PaymentVaultV2 (option 1) and struct MerkleTreePayment {
uint8 depth;
uint64 merklePaymentTimestamp;
PoolCommitment[] poolCommitments;
}
function payForMerkleTrees(MerkleTreePayment[] calldata trees)
external returns (bytes32[] memory winnerPoolHashes, uint256 totalAmount);
evmlib grows the matching surface: ConsequencesPositive
Negative / Trade-offs
Neutral / Operational
Validation
Notes for AI-assisted workAI tools may help draft this ADR, but must not mark it Accepted without |
…ees) Filed from the draft posted on WithAutonomi/evmlib#15 (V2-989, parent V2-949). Status: Proposed. Numbered 0011: 0010 was taken on main by the beta upgrade channel ADR after this draft was numbered. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Linear issue
V2-989 — https://linear.app/withautonomi/issue/V2-989
Risk tier
Compatibility
getCompletedMerklePaymentstate getter — zero node changes)completedMerklePaymentsrecords)payForMerkleTrees(legacypayForMerkleTreebyte-for-byte untouched), new evmlib functions (Wallet::pay_for_merkle_trees,external_signer::pay_for_merkle_trees_calldata, handler batched methods) and constants (MAX_TREES_PER_PAYMENT,MERKLE_TREES_PER_PAYMENT). One behavioral fix: estimation-time reverts now surface as typedTransactionRevertedwith revert data (previously stringifiedTransactionFailedToSendretried 3×).Semver impact
Test evidence
forge test: 15/15 — new adversarial suitetest/PaymentVaultV2.t.sol: event ordering + attribution (log order == input order), revert atomicity (wrong pool count mid-batch, depth-too-large, depth-0 panic, allowance short by one — no partial state survives), duplicate winner within a batch + replay across entry points (PaymentAlreadyExists), seed decorrelation of identical trees via the tree index, empty/oversized-batch bounds, 16-tree max accepted, legacy entry-point regression,setBatchLimitonlyOwner.cargo test --release --features external-signer: 34/34 — incl. new Anvil integration tests: batched round trip via handler andWallet(3 trees, per-tree winner/amount/storage verified), duplicate rejection surfacing typedPaymentAlreadyExiststhrough the gas-estimation revert path, external-signer raw-calldata e2e (approve → submit calldata → exactly one stored payment per tree).cargo clippy --all-targets --all-featuresclean,cargo fmt --checkclean.New dependency
forge-stdv1.16.2 (git submodule +foundry.lock, test-only — standard Foundry test harness; the repo previously had no Solidity test infra). No Rust dependency changes.ADR
ADR-0011 (Proposed), filed in ant-node via WithAutonomi/ant-node#213 — permanent home:
docs/adr/ADR-0011-batched-merkle-tree-payments.md(branch link; resolves onmainonce #213 merges). Original draft (numbered ADR-0010, pre-renumber) also posted as a comment below.Mitigation / rollback
Nothing deploys from this PR; the new entry point reaches production only via V2-992 (fresh vault deployment + evmlib address bump, node-first rollout). Rollback = revert the PR / don't deploy.
payForMerkleTreeis unchanged, so released clients (ant-ui 0.9.7, mobile 0.0.7) are unaffected on both old and new vaults.🤖 Generated with Claude Code