Staking Protocol Patterns

Detects vulnerabilities in Solidity staking and reward distribution contracts during security audits.

66|17|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/BitterSecurity/Vigilo --skill staking-protocol-patterns-bittersecurity
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Staking Protocol Patterns
Source: https://github.com/BitterSecurity/Vigilo/tree/main/packages/claude/skills/protocol-patterns/staking
Command: npx skills add https://github.com/BitterSecurity/Vigilo --skill staking-protocol-patterns-bittersecurity

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Auditing DeFi staking contracts requires deep knowledge of reward accumulator math, lock period logic, and reentrancy patterns, and missing subtle flaws like precision loss or first-staker advantage can lead to critical exploits. ## Core Features & Use Cases - Reward Distribution Analysis: Identifies precision loss, overflow, first staker advantage, and late staker dilution in Synthetix-style reward-per-token accumulators. - Lock & Unstake Review: Detects lockup bypass via token transfers, lock extension manipulation, and unstake reentrancy caused by state updates after external calls. - Multi-Reward & Boosted Staking Checks: Covers multi-reward token update desync and veToken/gauge boost manipulation patterns. - Use Case: When auditing a Solidity staking contract, apply the included checklist to verify high-precision accumulators, CEI pattern compliance, and correct handling of zero totalSupply edge cases. ## Quick Start Audit this staking contract for reward calculation, lock period, and reentrancy vulnerabilities using the staking patterns checklist.

Frequently Asked Questions about Staking Protocol Patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I audit a Solidity staking contract for vulnerabilities?▼

Review the reward-per-token accumulator for precision loss and overflow, verify the first staker cannot claim all pending rewards, check lock enforcement on transfers, and confirm state updates happen before external calls. The included checklist covers reward calculation, locks, reentrancy, and edge cases.

What is the first staker advantage vulnerability in staking contracts?▼

First staker advantage occurs when rewardPerTokenStored is not updated while totalSupply is zero, letting the first staker claim all rewards accumulated since lastUpdateTime. The fix resets lastUpdateTime when the first deposit occurs.

How to prevent reentrancy in unstake and claim functions?▼

Follow the checks-effects-interactions pattern by updating balances and reward state before transferring tokens, and apply a nonReentrant modifier to sensitive functions. Sending rewards before state updates allows attackers to re-enter and drain funds.

Why does reward calculation lose precision in staking contracts?▼

Precision loss happens when rewardRate multiplied by time delta is smaller than totalSupply, causing integer division to return zero. Multiplying by a high-precision factor like 1e18 before division preserves reward accuracy.

Can staking lock periods be bypassed by transferring tokens?▼

Yes, if the lock is only checked in the unstake function, users can transfer stake tokens to bypass it. Locks should be enforced in the token transfer hook or tracked per deposit.