DeFiLayer 1Layer 2
14,723 OP
View results
Submission Details
Severity: high
Invalid

Critical Storage Slot Calculation Error Leads to Incorrect Price Updates in ScrvusdVerifierV1 Contract

Summary

The contract ScrvusdVerifierV1 contains an incorrect calculation of the storage slot for the balanceOf mapping in the PARAM_SLOTS array. The issue arises from the incorrect order of arguments in the keccak256(abi.encode(...)) function, which is used to compute the storage slot for a mapping entry. This results in the contract reading from or writing to an incorrect storage location, potentially leading to unintended behavior or vulnerabilities.

Affected code: ScrvusdVerifierV1::PARAM_SLOT

Vulnerability Details

Root Cause

In Solidity, the storage slot for a mapping entry is calculated as:

keccak256(abi.encode(key, slot))

Where:

  • key is the mapping key (e.g., an address).

  • slot is the storage slot where the mapping itself is stored.

In the contract, the following calculation is used:

uint256(keccak256(abi.encode(18, SCRVUSD)))

Here, 18 is treated as the key, and SCRVUSD is treated as the slot. This is incorrect because:

  1. The slot (where the mapping is stored) should be 18.

  2. The key (the address whose balance is being looked up) should be SCRVUSD.

The correct calculation should be:

uint256(keccak256(abi.encode(SCRVUSD, uint256(18))))

Location

The issue is located in the PARAM_SLOTS array initialization in the ScrvusdVerifierV1 contract:

uint256[PROOF_CNT] internal PARAM_SLOTS = [
uint256(0), // filler for account proof
uint256(21), // total_debt
uint256(22), // total_idle
uint256(20), // totalSupply
uint256(38), // full_profit_unlock_date
uint256(39), // profit_unlocking_rate
uint256(40), // last_profit_update
uint256(keccak256(abi.encode(18, SCRVUSD))) // Incorrect balanceOf(self) slot
];

Technical Impact

The incorrect storage slot calculation for balanceOf(self) in PARAM_SLOTS causes the _extractParametersFromProof function to read from an unintended storage location. This results in:

  1. Incorrect parameter Values Passed to _updatePrice:

  • params[6] (balance of scrvUSD) will contain a value from the wrong storage slot, leading to incorrect data being used in price calculations.

  1. Faulty Price Calculations in _updatePrice:

    • If the incorrect slot contains 0, the contract may assume a zero balance, skewing the price.

    • If the incorrect slot contains a large value, the price may be artificially inflated or deflated, causing financial discrepancies.

  2. Failure of State Proof Verification Mechanism:

    • Extracted slot values may not match the state proof, causing reverts or silent acceptance of incorrect data, undermining the system's reliability.


Impact

Severity

  • High: The issue affects the core functionality of the contract, as it involves reading and writing to storage, which is critical for the contract's operation. Incorrect storage access can lead to severe consequences, including financial losses or exploitation.

Likelihood

  • High: The issue is guaranteed to occur whenever the balanceOf mapping is accessed, as the storage slot calculation is hardcoded and incorrect.


Tools Used

  1. Manual Code Review

Recommendations

Update the PARAM_SLOTS array to use the correct storage slot calculation:

uint256[PROOF_CNT] internal PARAM_SLOTS = [
uint256(0), // filler for account proof
uint256(21), // total_debt
uint256(22), // total_idle
uint256(20), // totalSupply
uint256(38), // full_profit_unlock_date
uint256(39), // profit_unlocking_rate
uint256(40), // last_profit_update
uint256(keccak256(abi.encode(SCRVUSD, uint256(18)))) // Correct balanceOf(self) slot
];
Updates

Lead Judging Commences

0xnevi Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

[invalid] finding-ScrvusdVerifierV1-incorrect-storage-slot-balanceOf-compute

- Per sponsor comments, verified slot is vyper, solidity contract only verifies it. - Vyper computes storage slots different from solidity as seen [here](https://ethereum.stackexchange.com/questions/149311/storage-collision-in-vyper-hashmap)

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.