Both the ScrvusdVerifierV1.sol
and ScrvusdVerifierV2.sol
contracts use hardcoded addresses and storage slot numbers which could become invalid if the target scrvUSD contract is upgraded or changes its storage layout. This creates a brittle dependency that could break the verifiers and disrupt the price oracle system.
Severity: Medium
Files Affected:
contracts/scrvusd/verifiers/ScrvusdVerifierV1.sol
contracts/scrvusd/verifiers/ScrvusdVerifierV2.sol
Code Affected:
Hardcoded address and storage slots in ScrvusdVerifierV1:
Hardcoded storage slot in ScrvusdVerifierV2:
These hardcoded values create rigid dependencies on the current implementation and storage layout of the scrvUSD contract. If the scrvUSD contract is upgraded and its storage layout changes, the verifier contracts would extract incorrect data from the new slots, leading to incorrect price or period updates.
The importance of these slot values becomes even clearer when examining the oracle contract (ScrvusdOracleV2.vy
), which relies on these extracted parameters for critical price calculations:
The oracle uses these parameters in complex calculations to determine the price:
If the verifiers extract incorrect data due to storage slot changes, this would directly affect these price calculations, potentially causing significant financial impact.
The use of hardcoded storage slots has several implications:
Fragility During Upgrades: If the scrvUSD contract is upgraded and changes its storage layout, the verifiers would extract incorrect data, potentially causing protocol-wide issues.
Incorrect Parameter Extraction: Changes in storage layout could lead to extracting unrelated data from the wrong slots, causing incorrect price or period updates in the oracle.
Protocol Disruption: In a DeFi system, incorrect price data could lead to significant financial losses through mispriced assets, incorrect liquidations, or exploitable arbitrage opportunities.
Maintenance Challenges: Each time the target contract is upgraded, all verifier contracts would need to be redeployed with updated slot numbers, increasing operational complexity.
Limited Adaptability: The contracts cannot adapt to any changes in the protocol without redeployment, creating potential downtime during upgrades.
Complex Price Calculation Impact: As seen in the oracle's _raw_price
function, the extracted parameters are used in division operations, so incorrect values could lead to division by zero errors or wildly inaccurate prices.
Manual code review
Implement Configurable Storage Slots:
Replace hardcoded slots with configurable parameters that can be updated by authorized administrators.
Consider Using EIP-1967 Storage Slots:
For unstructured storage proxy patterns, consider using standardized storage slots as defined in EIP-1967, which are designed to avoid collisions during upgrades.
Implement Slot Verification Mechanism:
Add functionality to verify that slots contain expected data types or value ranges before using them for critical operations.
Versioned Contracts with Upgrade Coordination:
Implement a versioning system for verifier contracts to track compatibility with scrvUSD contract versions.
Coordinate upgrades between the scrvUSD contract, oracle, and verifier contracts.
External Storage Layout Registry:
Consider implementing a registry contract that maps contract versions to their storage layouts, allowing verifiers to lookup the correct slots dynamically.
By implementing these recommendations, particularly the configurable storage slots, the contracts would be more adaptable to changes in the target contract's storage layout, reducing the risk of disruption during upgrades and improving overall protocol resilience.
Invalid, - srCRVUSD is a minimal proxy, meaning it can never by upgraded, see [here](https://www.cyfrin.io/blog/upgradeable-proxy-smart-contract-pattern#:~:text=Minimal%20proxies%20are%20distinct%20from,provide%20upgrade%20or%20authorization%20functionality.) and [here](https://www.rareskills.io/post/eip-1167-minimal-proxy-standard-with-initialization-clone-pattern) for more info. - Even if srcrvUSD is migrated in the future via a new minimal proxy contract deployment (which is highly unlikely), the verifier contracts can be migrated along with it via revoking the access-control within the `ScrvusdOracleV2.vy` and then granting access to a new oracle. This is also not within the scope of this contest.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.