Sapien - 2

QuantstampFiles named in the report

Quantstamp reviewed Sapien (Sapien - 2) on 2 Jul 2025: 9 findings, 0 critical; all marked fixed.

No open critical findings
Open the reportOpen Sapien’s security record

Report hosted on certificate.quantstamp.com.

Trustblock does not review code.

Findings10

Statuses are the security firm’s own, from its report.

SeverityOpenAcknowledgedFixed
Critical000
High004
Medium002
Low003
High`processQAPenalty()` Function Incorrectly Double Counts Tokens in CooldownFixed

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.

HighCooldown Period Can Be Bypassed Allowing Instant UnstakingFixed

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.

HighLockup Period for Unstaking Can Be Decreased by Staking Again with Shorter Lockup PeriodFixed

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.

HighQA Penalty Can Be Avoided by Unstaking Before Penalty ProcessingFixed

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.

MediumInconsistent Lockup Period Calculation Allows Users to Game the SystemFixed

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.

MediumMissing Expiration Check when Adding to Existing Stake Allows Timelock BypassFixed

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.

LowAuthorized `emergencyWithdraw()` Function Is Vulnerable to Reentrancy AttackFixed

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.

LowContracts Could End up without an Admin if Deployer Is Also the AdminFixed

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.

LowEIP-712 `QA_DECISION_TYPEHASH` Declares `string` but Encodes `bytes32`Fixed

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.

Contracts in scope

No deployed address is recorded for this audit.

The report names a repository or files. Open the report to see its scope.

Repository and files the report names (13)

  • src/SapienToken.sol
  • src/SapienVault.sol
  • src/utils/Constants.sol
  • src/interfaces/ISapienQA.sol
  • src/utils/SafeCast.sol
  • src/interfaces/ISapienToken.sol
  • src/interfaces/ISapienRewards.sol
  • src/interfaces/IMultiplier.sol
  • src/utils/Common.sol
  • src/Multiplier.sol
  • src/SapienRewards.sol
  • src/interfaces/ISapienVault.sol
  • src/SapienQA.sol

Part of Sapien’s security record

Sapien
Audits2 audits by 1 firmLast audit Jul 2025, by Quantstamp.
Critical findingsNo open critical findingsAcross 2 reports.
Open Sapien’s security record

Security firm

Quantstamp

240 projects reviewed · 338 reports · latest Nov 2026

See Quantstamp’s audits

Something 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