The setTypeWeight function in the GaugeController contract allows a gauge admin to set the weight for a specified gauge type. It accepts two parameters—the gauge type and the new weight—and updates the typeWeights mapping accordingly after verifying that the weight does not exceed MAX_TYPE_WEIGHT. However, the function lacks a validation check to ensure that the provided gauge type is supported (i.e., either GaugeType.RWA or GaugeType.RAAC as enforced in the addGauge function). Without this check, an admin (or a malicious actor with admin privileges) can assign a weight to an invalid or unsupported gauge type, which can lead to inconsistent internal state, unwanted storage population, and potentially erroneous behavior in gauge-related calculations such as reward distribution or governance.
The setTypeWeight function is designed to update the weight associated with a gauge type. Its code is as follows:
Lack of GaugeType Validation:
Unlike the addGauge function—which validates the gauge type by ensuring it is either GaugeType.RWA or GaugeType.RAAC—the setTypeWeight function does not perform such a check. As a result, any arbitrary value passed as gaugeType will be accepted, even if it is not one of the supported types.
Consequences:
This oversight can lead to:
Inconsistent State: Unsupported gauge types may be recorded in the typeWeights mapping, causing mismatches with the rest of the system that expects only valid gauge types.
Unwanted Storage Population: Storing weights for gauge types that should not exist can lead to unpredictable behavior during gauge-related computations (e.g., reward allocations, governance weight calculations).
Potential Exploitation: Although only the gauge admin can call this function, a compromised admin key or an error by an admin can introduce invalid entries, disrupting the protocol's functionality.
Setup:
An admin calls setTypeWeight with an invalid gauge type value (for example, an enum value that is not RWA or RAAC).
Execution:
The function accepts the invalid gauge type and sets a weight in the typeWeights mapping without any validation. Consequently, the internal state is updated with an unsupported gauge type, which might then be referenced by other parts of the system, leading to inconsistencies.
Test Suite:
The following Foundry test suite demonstrates how an invalid gauge type can be recorded in the typeWeights mapping.
Step 1: Create a new Foundry project:
Step 2: Remove unnecessary files.
Step 3: Place your contract files (including GaugeController and its interface) in the src directory.
Step 4: Create a test directory adjacent to src and add the above test file (e.g., GaugeControllerTypeWeightTest.t.sol).
Step 5: Run the test using:
Expected Output:
This confirms that the function accepts and stores an invalid gauge type, resulting in inconsistent state.
Inconsistent Internal State:
Recording an invalid gauge type in the typeWeights mapping can lead to misalignment between expected gauge types and the stored configuration. Subsequent functions that rely on gauge type values may produce erroneous calculations or behaviors.
Reward Distribution and Governance Distortion:
If an invalid gauge type is referenced during reward distribution or governance calculations, it may result in incorrect reward allocations or improperly weighted votes.
Unwanted Storage Population:
The absence of gauge type validation allows for the injection of arbitrary keys into the typeWeights mapping, which could potentially be exploited to interfere with system operations.
System Integrity Risk:
Over time, if multiple invalid gauge types accumulate, the overall integrity of the gauge management system may be compromised, affecting both reward mechanics and governance stability.
Manual Review
Foundry
To mitigate this vulnerability, the setTypeWeight function should be updated to include a validation check for the gauge type. The valid gauge types should be restricted to those defined by the protocol (i.e., GaugeType.RWA and GaugeType.RAAC). If an invalid gauge type is provided, the function should revert with an InvalidGaugeType error.
GaugeController::setTypeWeightThe 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.