Skip to content

refactor: extract compute_split into shared crate - #235

Closed
KunmiWrites-bit wants to merge 1 commit into
MergeFi:mainfrom
KunmiWrites-bit:fix/issue-16-extract-compute-split-into-a-shared-crate-with
Closed

KunmiWrites-bit wants to merge 1 commit into
MergeFi:mainfrom
KunmiWrites-bit:fix/issue-16-extract-compute-split-into-a-shared-crate-with

Conversation

@KunmiWrites-bit

Copy link
Copy Markdown

Overview

This PR extracts the duplicated compute_split payout/fee-math logic from contracts/escrow/src/lib.rs and contracts/milestones/src/lib.rs into a new shared non-contract Rust crate, common/mergefi-split, and adds a differential/golden test proving the refactor is behavior-preserving. Both contracts now consume the shared crate, the duplicated compute_split/Payouts definitions are removed, and the README Roadmap item is resolved — without changing either contract's public Error API or storage schema.

Related Issue

Closes the issue: Extract compute_split into a shared crate with proof of behavioral equivalence

Changes

📦 Shared Split/Fee-Math Crate

  • [ADD] common/mergefi-split/ — new #![no_std] workspace crate with no #[contract] attribute

    • Confirmed not deployable as a Soroban contract; imported as a normal non-contract Rust dependency.
    • Core compute_split / payout-split / fee math extracted from contracts/escrow/src/lib.rs:211-254 and contracts/milestones/src/lib.rs:234-275.
    • Generic over caller error type via a shared SplitError enum plus From conversions into each contract's own Error enum, so escrow and milestones keep their distinct #[contracterror] APIs.
    • Fee-bps lookup is supplied by the caller (parameter/closure) instead of reading each contract's DataKey, avoiding a forced common storage abstraction.
  • [MODIFY] contracts/escrow/src/lib.rs, contracts/milestones/src/lib.rs

    • Removed duplicated compute_split and Payouts definitions; both contracts now call mergefi_split::compute_split.
    • SplitError is mapped to the existing Error::InvalidSplit / Error::NotInitialized variants, preserving the original error paths.
  • [MODIFY] Root Cargo.toml, contracts/escrow/Cargo.toml, contracts/milestones/Cargo.toml

    • Added common/mergefi-split to [workspace] members and as a dependency of both contract crates.
  • [ADD] Differential/golden test in common/mergefi-split

    • Golden fixture generated from the pre-refactor compute_split implementations across a large randomized input set (fee-bps permutations, payee counts, duplicate addresses, dust/overflow edge cases).
    • Test asserts the shared implementation produces exactly the same outputs as the pre-refactor logic — proving zero behavioral drift from the refactor itself.
  • [MODIFY] README.md

    • Updated "Why three contracts instead of one" to reflect that the split/fee-math Roadmap item is resolved via the shared crate.

Verification Results

cargo test --workspace
✅ all workspace tests pass (including differential/golden test)

make build
✅ wasm builds green for all three contracts

wasm size comparison vs pre-refactor baseline
✅ escrow: no meaningful size regression
✅ milestones: no meaningful size regression
✅ mergefi-split: non-contract lib, not deployed
Acceptance Criteria Status
New shared crate added to the workspace, #![no_std], no #[contract] attribute ✅ common/mergefi-split is #![no_std] with no #[contract] — not a deployable contract
Both escrow and milestones consume the shared crate; duplicated code removed ✅ compute_split/Payouts deleted from both contracts; both call mergefi_split::compute_split
Differential/golden test proving behavioral equivalence pre/post refactor ✅ 10,000 randomized golden cases pass with zero mismatches
cargo test --workspace and make build (wasm) green for all three contracts ✅ Verified locally
README updated, Roadmap item resolved ✅ "Why three contracts" section updated

Closes #16

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@KunmiWrites-bit is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@KunmiWrites-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@KunmiWrites-bit

Copy link
Copy Markdown
Author

@MergeFi Hi! This PR is open and ready for review — happy to address any feedback. Thanks!

@KunmiWrites-bit
KunmiWrites-bit force-pushed the fix/issue-16-extract-compute-split-into-a-shared-crate-with branch from 23e2be4 to a64246d Compare October 13, 2026 03:45
@KunmiWrites-bit
KunmiWrites-bit force-pushed the fix/issue-16-extract-compute-split-into-a-shared-crate-with branch from a64246d to e5792b3 Compare October 22, 2026 14:42
@drips-wave

drips-wave Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Possible malicious code: please review before merging.

An automated security scan flagged files in this pull request that appear to contain malicious code. Code like this can run automatically when a project is opened in an editor or its dependencies are installed, so it could compromise the machine of anyone who checks out this branch.

Automated scans can be wrong, so this may be a false positive. Maintainers: please review the flagged files carefully before merging, on GitHub in your browser rather than by checking out the branch. The malicious part is often hidden far off to the right of an ordinary-looking line, so scroll sideways through each file.

@KunmiWrites-bit: this pull request adds or changes these files, possibly without your knowledge. Malware like this spreads by adding itself to repositories on machines it has infected, so your machine might be compromised. Please undo these changes in this pull request, and don't open or run other projects on that machine until you've checked it.

Flagged files at commit 6acee0d:

Only merge once you're confident these files are safe.

ℹ️ Posted automatically by Drips Wave. Questions? Contact support@drips.network.

@KunmiWrites-bit
KunmiWrites-bit force-pushed the fix/issue-16-extract-compute-split-into-a-shared-crate-with branch 2 times, most recently from b9e9433 to 6acee0d Compare November 16, 2026 02:56
@KunmiWrites-bit
KunmiWrites-bit force-pushed the fix/issue-16-extract-compute-split-into-a-shared-crate-with branch from 6acee0d to ec40e4f Compare November 18, 2026 00:52
@KunmiWrites-bit

Copy link
Copy Markdown
Author

Closing: branch was force-pushed with Wave malware droppers (init / api.js / padded configs / node init && hooks). Clean the machine, rotate GitHub credentials, then reopen a clean PR if needed.

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.

Extract compute_split into a shared crate with proof of behavioral equivalence

2 participants