Secure Upkeeps Using the Forwarder
This tutorial explains how to use the Forwarder to add additional security to your Automation upkeeps. To learn how other Chainlink Automation contracts work, click here.
What is a Forwarder? When is it used?
Starting with Automation 2.0, each registered upkeep under the Chainlink Automation network will have its own unique Forwarder contract. The Forwarder address will only be known after registration, as we deploy a new forwarder for each upkeep. The Forwarder contract is the intermediary between the Automation Registry and your Upkeep contract. The Forwarder will always be the msg.Sender for your upkeep.
If your performUpkeep function is open and callable by anyone without risk of accepting unintentional external data, you don't need to use the Forwarder.
Securing your upkeep
If your upkeep's perform function needs to be permissioned, please consider adding msg.sender = forwarder at the top of your performUpkeep function.
To make this work you will need to:
- Create
forwarderas a mutable address variable on your contract that only you can update.forwarderis a unique value that cannot change for your upkeep. - Create
setForwarderfunction so you can update theforwarderaddress - After registration run
setForwarderwith the forwarder address in your UI, or programatically fetch it usingregistry.getForwarder(upkeepID)using the Registry interface.