Summary
The capture
function does not check for zero address or verify if the provided well address is a whitelisted
LP token before calling initializeOracle
. This can lead to reverts in the initializeOracle
function when well is not a valid or whitelisted address.
Vulnerability Details
The capture
function does not validate if the well address is non-zero before proceeding to call initializeOracle
.
If a zero address or not a White listed Well Lp Tokens passed, it can cause the transaction to revert.
function capture(
address well
) external returns (int256 deltaB) {
bytes memory lastSnapshot = LibAppStorage
.diamondStorage()
.wellOracleSnapshots[well];
if (lastSnapshot.length > 0) {
deltaB = updateOracle(well, lastSnapshot);
} else {
initializeOracle(well);
}
deltaB = LibMinting.checkForMaxDeltaB(deltaB);
}
The initializeOracle
function attempts to read cumulative reserves from the well address without ensuring it is valid. If well is a zero address or not part of the whitelisted tokens, IWell(well).pumps()
will revert.
function initializeOracle(address well) internal {
AppStorage storage s = LibAppStorage.diamondStorage();
@>> Call[] memory pumps = IWell(well).pumps();
try ICumulativePump(pumps[0].target).readCumulativeReserves(
well,
pumps[0].data
) returns (bytes memory lastSnapshot) {
s.wellOracleSnapshots[well] = lastSnapshot;
emit WellOracle(s.season.current, well, 0, lastSnapshot);
} catch {
emit WellOracle(s.season.current, well, 0, new bytes(0));
}
}
Impact
// Need to handle failure gracefully, so Sunrise does not revert.
As Sunrise must not revert in any case but this is not handled, and the sunrise revert is happening before try/catch
.
Tools Used
Manual Review
Recommendations
function capture(
address well
) external returns (int256 deltaB) {
bytes memory lastSnapshot = LibAppStorage.diamondStorage().wellOracleSnapshots[well];
+ address[] memory tokens = LibWhitelistedTokens.getWhitelistedWellLpTokens();
+ for (uint256 i = 0; i < tokens.length; i++) {
+ if (well == token[i]){
+ address _well = token[i]; }
+ }
if (lastSnapshot.length > 0) {
- deltaB = updateOracle(well, lastSnapshot);
+ deltaB = updateOracle(_well, lastSnapshot);
} else {
- initializeOracle(well);
+ initializeOracle(_well);
}
deltaB = LibMinting.checkForMaxDeltaB(deltaB);
}