Skip to content

feat(contracts): inspector bond + slashing-module integration#1029

Merged
pope-h merged 1 commit into
Shelterflex:mainfrom
joannamach250-collab:feat/issue-925
May 30, 2026
Merged

feat(contracts): inspector bond + slashing-module integration#1029
pope-h merged 1 commit into
Shelterflex:mainfrom
joannamach250-collab:feat/issue-925

Conversation

@joannamach250-collab
Copy link
Copy Markdown
Contributor

Summary

Implements the per-inspector bond + cross-contract slashing flow from #925 alongside the existing collateralised-bond and validator-evidence-slashing models. The existing public methods are not touched — the new functionality is purely additive — so nothing else in the workspace breaks.

contracts/bond_collateral

  • set_slashing_module(admin, slashing_module) and set_operator(admin, operator) for one-time wiring.
  • deposit_bond(inspector, amount) / withdraw_bond(inspector, amount) / get_bond(inspector) / get_locks(inspector).
  • lock_bond(operator, inspector, inspection_id) — operator-gated; any active lock blocks withdraw_bond with BondLocked.
  • unlock_bond(operator, inspector, inspection_id).
  • execute_slash(admin, inspector, slash_amount, inspection_id, reason) — admin-gated; cross-contract call to slashing_module.slash to record the slash, then reduces the inspector's bond by exactly slash_amount. Fails fast with InsufficientBond when slash_amount > bond.
  • New error variants: BondLocked, InsufficientBond, LockAlreadyExists, LockNotFound, SlashingModuleNotSet.

contracts/slashing_module

  • set_bond_contract(admin, bond_contract) / bond_contract() — registers the single bond contract authorised to call slash.
  • slash(caller, inspector, amount, inspection_id, reason) -> i128 — appends an InspectorSlashRecord { inspection_id, amount, reason, slashed_at } to the inspector's history. Rejects callers that aren't the registered bond contract with NotAuthorized; rejects amount <= 0 with ArithmeticError.
  • get_slash_history(inspector) -> Vec<InspectorSlashRecord>.

Both crates now expose rlib in addition to cdylib so tests can cross-import the generated *Client types.

Acceptance criteria

  • withdraw_bond is blocked when the bond is locked for a pending inspection dispute (BondLocked).
  • execute_slash reduces the inspector's bond by exactly slash_amount.
  • A slash for more than the inspector's bond balance fails with InsufficientBond; bond untouched.
  • slashing_module.slash is only callable by the registered bond_collateral contract address.
  • cargo test -p bond_collateral and cargo test -p slashing_module pass.

Test plan

  • cargo test -p bond_collateral14 tests pass (2 existing + 12 new inspector-bond tests covering full lifecycle, lock/unlock, cross-contract slash, multi-slash accumulation, every auth error variant).
  • cargo test -p slashing_module12 tests pass (8 existing + 4 new for set_bond_contract, unregistered-caller rejection, non-positive-amount rejection, slash history recording).
  • cargo test --workspace — no regressions in any other contract.
  • cargo fmt --all -- --check clean.
  • cargo clippy --workspace --all-targets --all-features clean (matches CI flags).

Closes #925

Adds the per-inspector bond flow specified in Shelterflex#925 alongside the existing
collateralised-bond and evidence-slashing models, keeping the existing
APIs untouched so nothing else in the workspace breaks.

bond_collateral:
- set_slashing_module(admin, slashing_module) + set_operator(admin, operator)
- deposit_bond(inspector, amount) / withdraw_bond(inspector, amount) /
  get_bond(inspector) / get_locks(inspector)
- lock_bond(operator, inspector, inspection_id) — operator-gated; blocks
  withdraw_bond while any lock is active
- unlock_bond(operator, inspector, inspection_id)
- execute_slash(admin, inspector, slash_amount, inspection_id, reason) —
  admin-gated; cross-contract call to slashing_module.slash; reduces the
  inspector's bond by exactly slash_amount; fails with InsufficientBond
  if slash_amount > bond.
- New error variants: BondLocked, InsufficientBond, LockAlreadyExists,
  LockNotFound, SlashingModuleNotSet.

slashing_module:
- set_bond_contract(admin, bond_contract) / bond_contract() — registers the
  one bond contract authorised to call slash.
- slash(caller, inspector, amount, inspection_id, reason) — appends an
  InspectorSlashRecord to the inspector's history; rejects callers that are
  not the registered bond contract; rejects amount <= 0.
- get_slash_history(inspector) — read.

Both crates now expose rlib so tests can cross-import the generated clients.

Tests: bond_collateral adds 12 new tests covering the full lifecycle
(deposit, lock-blocks-withdraw, unlock, cross-contract slash reduces bond
and records history, slash > bond fails, slash requires admin, slashing
module rejects unregistered callers, multi-slash accumulation). slashing
module adds 4 tests for the new surface. cargo test --workspace stays green.

Closes Shelterflex#925
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@joannamach250-collab is attempting to deploy a commit to the pope-h's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@joannamach250-collab 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

@pope-h pope-h merged commit 119fd30 into Shelterflex:main May 30, 2026
3 of 4 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.

Contracts: Slashing Module Integration for bond_collateral

2 participants