On this weblog, now we have outlined the idea of liquidity staking protocols and auditing pointers for staking protocols. The rules cowl a variety of susceptible spots reminiscent of withdrawal mechanisms, rounding errors, exterior calls, price logic, loops, structs, staking length, and so forth. This weblog put up can be a helpful reference for auditing staking protocols and may also help you establish potential bugs.
What’s Liquidity Staking?
Liquidity staking permits customers to stake their cryptocurrency holdings and earn rewards with out sacrificing liquidity. As a substitute of locking up their cash for a set interval, customers can obtain a liquid token that represents their staked property. This token may be traded or used like every other cryptocurrency, permitting customers to make use of their property as they please whereas nonetheless incomes staking rewards.
For instance, you have got 100 ETH you wish to stake on the Ethereum community. As a substitute of locking up your ETH for a set interval, you should utilize a liquidity staking service like Lido to stake your ETH and obtain a liquid token known as stETH in return. With stETH, you’ll be able to nonetheless commerce or use your staked ETH whereas incomes staking rewards.
Let’s get began with auditing staking contracts:
Study all the audit specs accessible earlier than starting with the contract code. It might be within the type of a white paper, README recordsdata, or one thing else. These will provide you with an concept of what the contract code will comprise.
When trying on the audit specification doc for the staking contract, search for these factors:
Sorts of Charges primarily based and their calculations.
Rewards mechanism for staked tokens
Powers of the proprietor
Will the contract maintain ETH?
What tokens the contract will maintain?
Unique contract from which it’s forked
Examine that the specs match the code. Start with charges and tokenomics, adopted by validation of the proprietor’s authority. Examine that each one rewards and price values are in accordance with the documentation.
Weak spots to search for?
1. Reward Withdraw Mechanism:
Examine that the staked token rewards mechanism is appropriately carried out and that rewards are distributed pretty and proportionally to all stakers. Tasks can distribute rewards in two methods: both routinely, on a periodic foundation, or upon request by the customers themselves. A withdrawal perform may be carried out and customised based on the protocol’s enterprise logic.Beneath are a couple of checkpoints:
Examine if any person is ready to withdraw greater than its reward + staked quantity.
Examine for Overflow/underflow within the quantity calculation
Examine if sure parameters can have a detrimental affect on rewards throughout calculation.
If block.timestamp or block.quantity is used on this perform. Examine if it may be exploited in any means.
2. Price Logic:
If the deposit and withdrawal are topic to some price, then confirm that no single person can bypass the price. Moreover, be vigilant for any potential overflow or underflow points. Solely the administrator or proprietor needs to be approved to change price settings. Additionally confirm {that a} threshold for max charges has been established, stopping the administrator from setting it at an excessively excessive quantity.
3. LP Token’s Minting/Burning Mechanism:
Confirm if the minting and burning mechanisms have been appropriately carried out. A burn perform ought to reverse all state adjustments made by a mint perform. Moreover, it’s essential to confirm that customers obtain the suitable quantity of tokens through the first stake, when the pool is empty.
The logic of minting and burning features may be mathematically verified to uncover any hidden vulnerability. Additionally, the overall provide of LP tokens minted mustn’t exceed the staked property.
4. Rounding Errors:
Regardless that sure minor rounding errors are usually unavoidable and never a priority, they’ll develop considerably when it’s potential to multiply them. Search for edge circumstances the place one can revenue from rounding errors by repeatedly staking and unstaking.
To find out whether or not rounding errors can accrue to a considerable quantity over an prolonged time period, we are able to mathematically calculate the vary of potential rounding errors.
5. Staking Period:
Make sure that the staking length calculations within the contract align with the required enterprise logic. Confirm that customers can’t redeem rewards earlier than the staking length has ended by bypassing the length checks. Additionally, Examine if the length of staking may be exploited by an attacker to get extra rewards.
6. Exterior Calls and Token Dealing with:
A lot of the exterior calls can be to the token contracts. So, we should decide what varieties of tokens the staking contract will deal with. It’s important to test exterior requires any errors and reentrancy assaults. Deflationary tokens or tokens with switch charges, reminiscent of Safemoon, can pose an issue if their logic is just not appropriately carried out.
7. Value Manipulations Checks:
Value Manipulation through a flash mortgage is Probably the most frequent hacks on DeFi tasks. There could also be conditions the place malicious actors can use flash loans to control costs throughout staking or unstaking great amount of tokens. Fastidiously overview staking and unstaking features to keep away from edge-case situations that would lead to flash loan-based worth manipulation assaults and lack of different customers’ funds.
8. Some Further Checks:
Loops: If the contract logic entails looping over arrays, it’s necessary to make sure that the block fuel restrict is just not exceeded. This may happen when the array dimension could be very massive, so it’s best to examine what features might improve the scale of the array and whether or not any person might exploit it to trigger a DoS assault. Try this report.
Structs: Staking contracts use the struct kind to retailer person or pool knowledge. When declaring or accessing a struct inside a perform, it’s necessary to specify whether or not to make use of “reminiscence” or “storage.” It would assist us avoid wasting fuel. For extra data, please seek advice from this text.
Entrance-Operating: Search for any situations the place malicious actors might front-run any transaction to their benefit.
Operate Visibility/ Entry Management Checks: Any perform that’s declared as exterior or public may be accessed by anybody. Subsequently, it is very important be certain that no public perform can carry out any delicate actions. It’s essential to confirm that the staking protocol has carried out applicable controls to stop unauthorized entry to each the staked cash and the system’s infrastructure.
Centralization Dangers: It will be important to not give the proprietor extreme powers. If the admin handle is compromised, it might trigger important harm to the protocol. Confirm that the proprietor or admin privileges are applicable and be certain that the protocol has a plan in place for dealing with conditions the place an admin’s non-public keys are leaked.
ETH / WETH dealing with: Contracts usually embody particular logic for dealing with ETH. For instance, when msg.worth > 0, a contract might convert ETH to WETH whereas nonetheless permitting WETH to be obtained instantly. When a person specifies WETH because the foreign money however sends ETH with the decision, this may break sure invariants and result in incorrect conduct.
To date, now we have mentioned liquidity staking protocols and the auditing pointers for such protocols. In a nutshell, Liquidity staking permits customers to earn staking rewards with out sacrificing liquidity. Now we have outlined the susceptible spots in staking contracts that auditors should take note of, reminiscent of withdrawal mechanisms, price logic, LP token minting/burning mechanism, rounding errors, staking length, exterior calls, and worth manipulation checks.
We suggest auditors to look at audit specs paperwork, match specs with code, and test charges and tokenomics validation. We additionally suggest extra checks reminiscent of looping over arrays, specifying reminiscence or storage for struct kind knowledge, and front-running situations. These pointers can be helpful for auditing staking protocols and assist establish potential bugs.
78 Views