Quantstamp reviewed Sapien (Sapien - 2) on 2 Jul 2025: 9 findings, 0 critical; all marked fixed.
Report hosted on certificate.quantstamp.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 0 |
| High | 0 | 0 | 4 |
| Medium | 0 | 0 | 2 |
| Low | 0 | 0 | 3 |
The `_calculateApplicablePenalty()` function incorrectly calculates available tokens for penalties by adding `userStake.amount + userStake.cooldownAmount`. However, `cooldownAmount` represents tokens that are already included in `amount` but are queued for unstaking. This double counting allows penalties to exceed the user's actual stake balance, potentially leading to accounting errors or failed penalty applications when the contract attempts to transfer more tokens than available.
The `initiateUnstake()` function in the `SapienVault` contract sets the cooldown start timestamp only if the user is not already in a cooldown state, as controlled by the condition `if (uint256(userStake.cooldownStart) == 0)`. This design creates an opportunity to bypass the intended cooldown period for the majority of a user's stake. Specifically, a user may initiate unstaking for a small portion of their stake, wait for the cooldown to complete, and then unstake the remaining amount without waiting again, effectively circumventing the cooldown for most of their tokens.
The `SapienVault` contract recalculates the effective lockup period when a user adds to an existing stake using the `stake()` function. The recalculation uses a **weighted average** between the current effective lockup period and the newly provided lockup period. This mechanism allows users to **reduce** their overall lockup duration by staking additional tokens with a shorter lockup period. As a result, users can strategically lower their lockup commitment after the initial stake, undermining the intended locking mechanism.
Typical unstaking within the protocol requires a two day cooldown period to pass before unstaking can be completed. The intention of this is to allow a sufficient window for any QA penalties to be applied before the user can unstake their tokens. However, in the case of the `earlyUnstake()` function, users are able to instantly withdraw their funds by paying a 20 percent penalty. In cases where a user is expecting to be slashed a value greater than 20 percent they can call the `earlyUnstake()` function to immediately withdraw their tokens and avoid the impending larger QA penalty.
The `SapienVault` contract exhibits an inconsistency in the `effectiveLockupPeriod` calculation methodology. When users stake multiple times, the contract calculates a new weighted start time and a new weighted effective lockup period. Also when users increase their stake amount, the contract calculates a new weighted start time. However, the `increaseLockup()` function bypasses this weighted calculation for a new lockup period, and instead uses a direct addition of the remaining lockup time and the additional lockup period. This inconsistency allows users to game the system by strategically choosing whether to add new stakes or increase lockup on existing stakes to get the shortest lockup period, as the mathematical approach differs between these operations.
The `stake()` and `increaseAmount()` functions allow users to add tokens to stakes without validation that the initial stake's lockup period has not ended. This can allow for some stakes where the new `weightedStartTime + effectiveLockUpPeriod < block.timestamp` meaning the stake is immediately unlocked. This allows users to benefit from an increased multiplier while being able to unlock their tokens at any time.
The `emergencyWithdraw()` function performs ether transfer via a `.call()` without reentrancy protection. While this function is access-controlled to admin only, reentrancy vulnerabilities in emergency functions can be particularly dangerous as they may be called during compromised states. An attacker who gains admin access could potentially exploit reentrancy to drain funds beyond intended amounts.
In both `SapienVault` and `SapienRewards`, the `initialize()` function grants the `DEFAULT_ADMIN_ROLE` to the specified `admin` address and then unconditionally revokes the same role from `msg.sender`. If the deployer and the admin are the **same address**, this logic leads to a scenario where **no account holds the `DEFAULT_ADMIN_ROLE`**, effectively rendering the contract **administratively locked** and unmanageable.
The `QA_DECISION_TYPEHASH` in `SapienQA` is defined as: ```solidity keccak256("QADecision(address userAddress,uint8 actionType,uint256 penaltyAmount,bytes32 decisionId,string reason)") ``` However, when encoding the struct for signature verification, the `reason` field is encoded as `keccak256(bytes(reason))`, which is a `bytes32`, not a `string`. This means the actual encoded struct does not match the declared type hash, potentially breaking EIP-712 signature compatibility and causing signature verification to fail or be non-standard.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (13)
240 projects reviewed · 338 reports · latest Nov 2026
See Quantstamp’s auditsSomething wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.
Tell us