Skip to content

Add validation for beneficiary basis points sum in plan updates#965

Merged
ONEONUORA merged 9 commits into
Fracverse:masterfrom
anonfedora:feat/validate-beneficiary-bps-sum
Jul 18, 2026
Merged

Add validation for beneficiary basis points sum in plan updates#965
ONEONUORA merged 9 commits into
Fracverse:masterfrom
anonfedora:feat/validate-beneficiary-bps-sum

Conversation

@anonfedora

Copy link
Copy Markdown
Contributor

Title: Add validation for beneficiary basis points sum in plan updates

Description:
This PR addresses issue #960 by adding validation to ensure that the sum of beneficiary allocation basis points (allocation_bps) equals exactly 10000 (100.00%) in any plan updates.

Changes Made

Smart Contract (contracts/inheritance-contract/src/lib.rs)

  • Added update_plan function: New contract method to update existing plans
    • Validates that beneficiary allocation_bps sum equals exactly 10000
    • Returns Error::InvalidBasisPoints if validation fails
    • Also validates bridge metadata and maximum beneficiaries count
    • Allows updating beneficiaries, grace_period, earn_yield, and yield_rate_bps
    • Requires owner authentication

Backend API (backend/src/api.rs)

  • Added UpdatePlanRequest struct: Request body for plan updates
  • Added update_plan handler: New PUT endpoint handler
    • Validates each beneficiary address is not empty
    • Validates each allocation_bps does not exceed 10000
    • Validates total allocation_bps equals exactly 10000 - returns 400 error with descriptive message if not
    • Updates beneficiaries by deleting existing ones and inserting new ones in a transaction
    • Returns updated plan with beneficiaries on success
  • Added PUT route: /api/plans/{id} endpoint added to user routes (requires signature authentication)
  • Added put import: Updated routing imports to support PUT method

Validation Logic

Both the contract and backend enforce the same validation:

  • Individual beneficiary allocation_bps cannot exceed 10000
  • Sum of all beneficiary allocation_bps must equal exactly 10000 (100%)
  • If validation fails:
    • Contract: Returns Error::InvalidBasisPoints
    • Backend: Returns 400 Bad Request with error message: "Total allocation_bps must be exactly 10000 (100%), got {actual_sum}"

Testing

  • Contract compiles successfully
  • Backend compiles successfully
  • Both validation paths tested locally

Related Issues

Fixes #960

- Add update_plan function to contract with allocation_bps validation
- Add PUT /api/plans/{id} endpoint to backend with allocation_bps validation
- Enforce that beneficiary allocation_bps sum equals exactly 10000 (100%)
- Return Error::InvalidBasisPoints in contract if validation fails
- Return 400 error with descriptive message in backend if validation fails
- Both contract and backend now validate on plan updates

Fixes Fracverse#960
Fixes ethnum v1.5.2 transmute error with newer Rust toolchain
The contract CI failure is due to ethnum v1.5.2 incompatibility with CI's Rust toolchain.
This is a pre-existing infrastructure issue unrelated to the validation feature changes.
The contract compiles successfully locally with the original SDK version.
ethnum v1.5.2 has a transmute bug that fails with Rust 1.71+
Pinning to 1.70.0 resolves the CI build failure
Lock file version 4 is incompatible with Rust 1.70.0
Regenerated with correct Rust version to match CI toolchain

@ONEONUORA ONEONUORA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @anonfedora
Thank you for your contribution

@ONEONUORA
ONEONUORA merged commit 39ea84b into Fracverse:master Jul 18, 2026
4 of 5 checks passed
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.

[Contract] Issue #4: Add Validation for Beneficiary Basis Points Sum

2 participants