Assessment reports>Polygon Staking>Discussion>Calling checkUpkeep on chain is against the automation documentation and may revert or waste gas

Calling checkUpkeep on chain is against the automation documentation and may revert or waste gas

In the Chainlink automation documentation, the checkUpkeep function is defined to contain gas-intensive logic that is explicitly indicated to be run off chain, in order to generate data that is then passed into the performUpkeep function. It recommends having this function use the cannotExecute modifier from their AutomationCompatible contract in order to ensure that this function is not executed on chain.

However, the PolygonFundFlowController contract does execute this on chain in the withdrawVaults function:

function withdrawVaults(uint256[] calldata _vaultIds) external {
    strategy.unstakeClaim(_vaultIds);

    (bool upkeepNeeded, ) = withdrawalPool.checkUpkeep("");

    if (upkeepNeeded) {
        withdrawalPool.performUpkeep("");
    }
}

If it is required that upkeep needs to be done after the unstakeClaim, then the current logic is the only way to guarantee that upkeep was attempted. However, if that is not a hard requirement, then we recommend omitting this check and call. If the withdrawalPool contract contains gas-intensive operations in its checkUpkeep function, or it takes the above linked recommendation and disallows checkUpkeep from running on chain at all, then withdrawVaults will start failing.

Zellic © 2025Back to top ↑