# Staking that never goes rigid: clamp before revert

> Canonical: https://blazephoenix.xyz/learn/staking-that-never-goes-rigid/
> License: CC BY-NC-ND 4.0 (attribution + link) · © 2026 BlazePhoenix
> Updated: 2026-11-16

The V4 staking contract avoids rigidity in two ways: where a quantity could overshoot a bound it clamps to the bound with a minimum instead of reverting, and the doors that only make the book safer, such as repay and absorbBadDebt, stay open longer than the doors that add risk. The engine is pre-launch, so this describes the code as written, not a deployment.

Short answer: the contract does two things, and neither is a promise that every function works in every state. First, where a quantity could overshoot a bound, it is clamped to the bound with a minimum, so an edge case does not turn into an overflow or an overpayment. Second, the doors that only make the book safer stay open longer than the doors that add risk. Which doors those are is written in a table, and the table is what this article reads.

The staking engine is pre-launch, so this describes the behaviour of the code as written in the repository, not a deployment.

## The doors and the three states

The whitepaper (section 25.2) gives each entry point and its state in three conditions: a guardian pause, an emergency, and a hard breach, which is the state in which the BZPX the contract holds plus dust is below what it owes. The rows that matter for recovery are these.

## The principle behind the table

The paper states it in one sentence: closing debt only makes the book safer. That is why `repay` stays open under a pause and under a hard breach, and why `withdraw` stays open under a pause: a pause halts new risk without trapping anyone. In a hard breach the contract refuses doors that would pay out at par from a pot that may be short, which is why `withdraw` is closed there, while `repay`, `liquidate` and `absorbBadDebt` stay open because each of them reduces what is owed or brings value in.

The table also shows what is not open. In an emergency, `repay` and `liquidate` are closed, and `emergencyWithdraw` is the only exit: it pays net equity, scaled pro rata if the contract holds less than the positions are owed. A pause closes `liquidate`. The hard-breach column describes the book before anyone trips the breaker: a trip enters emergency mode, and from then on the emergency column applies. Reading that as 'recovery always works' would be wrong: recovery works through the doors the table lists, in the states it lists.

## Where it clamps instead of reverting

The numbers below are the minimum-style bounds that the equations of section 25 apply.

## Reading the clamps together

A clamp turns a boundary case into a smaller number, not an exception. A liquidation whose debt exceeds the stake seizes the whole stake and sends the remainder to the loss waterfall, first the protocol reserve and then recorded bad debt, and does not revert. An emergency exit on a short pot pays a fraction of the claim instead of failing. A window in which the reward reserve is lower than the schedule pays what the reserve holds.

A revert remains the right answer for a door that should be closed in that state. The difference is that the closed doors are the ones that add risk or pay at par, and the clamped paths are the ones that settle losses and unwind positions.

## What the breaker test pins

A permissionless trip is safe only if it cannot fire on a healthy book. The stateful test `invariant_INV20_breakerCannotTripWhileSound`, in InvariantsFullSurface.t.sol of the staking suite, checks that property. The reasoning behind it: nobody can lower the contract's balance except through flows that lower what it owes by the same amount, and donations only raise the balance, so the trip condition can fire only on a real shortfall. The worst a spurious trip could do is a temporary pause that the admin can undo.

## What this does not claim

It does not say that every function is callable in every state, and it does not say that a clamp removes a loss: the haircut is the contract's rule for dividing a loss, not a promise to avoid one. It describes the code as written for a launch that has not happened.

**Verify it yourself:** In the staking repository at commit c0366cf, run the stateful test invariant_INV20_breakerCannotTripWhileSound (InvariantsFullSurface.t.sol), then read the entry points repay, liquidate, withdraw and absorbBadDebt and their pause, emergency and breach gates against the table above. Reading: sections 25.2 and 25.11 of the 2.4 whitepaper.

Related: https://blazephoenix.xyz/learn/permissionless-circuit-breaker/ · https://blazephoenix.xyz/learn/oracle-free-lending/ · https://blazephoenix.xyz/learn/monotonicity-against-the-caller/
