The vulnerable pattern
This callback tries to remove a pending mint and refund the user after the mint fails:Pseudocode: vulnerable flow
panic aborts the callback. The pending mint is restored because its removal is reverted, and the transfer line never runs.
How the issue happens
- The contract calls another contract to mint for a user, attaching NEAR tokens.
- The mint fails, so the attached NEAR tokens return to the calling contract.
mint_callbackstarts, removes the pending operation, then panics.- The entire callback receipt is reverted: the pending operation remains and no refund transfer is scheduled.
The safe pattern
Handle the failure and return normally:Pseudocode: safe flow
General rule
Usepanic for invalid input or a broken invariant before changing state. In a callback’s expected failure path, record the outcome, clean up, and refund or otherwise settle the operation without panicking.
See refund NEAR tokens for the refund pattern and private callbacks for callback access control.