0

ChainLink automation enables conditional execution of smart contracts functions. However, when calling function from the smart contract, it is the ChainLink registry contract that calls the function, and not the address that registered the UpKeep.

Therefore, it is likely that the call will fail if the function to call has a require that forces the caller (msg.sender) to be a given address (admin address for example).

Is it possible to automate such kind of functions (with msg.sender set to a needed address) with ChainLink Automation ?

As an example:

mapping() private _balance;
address public admin;

constructor {
    admin = msg.sender;
}

modifier onlyAdmin {
    require(msg.sender == admin, "Only admin");
    _;
}

function pay(address _account, uint256 _amount) public onlyAdmin {
    _balance[_account] += _amount; 
}

function getBalance(address _account) public view returns(uint256) {
    return _balance[_account];
}

update a balance through Chainlink automation. I expect the balance of _account to update to its previous value + _amount.

sam
  • 1
  • 2

2 Answers2

0
_balance[account] = _balance[account] + _amount;
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jan 30 '23 at 20:40
0

As you said transaction sent by Chainlink automation is signed with Chainlink Registry contract, and as far as I know it is impossible to replace the signature with consumer contract's owner's signature.

I think the better way to do this is to modify the modifier onlyAdmin to add address of registry contract.

Frank Kong
  • 1,010
  • 1
  • 20
  • 32
  • Thank you @frank Kong. The problem with setting the onlyAdmin to the address of the registry is that anyone could then register the same contract on ChainLink and execute it. If we imagine that the contract is used for payment, then this will lead to a serious issue, since anyone would be able to trigger the payment from the contract – sam Feb 03 '23 at 22:11
  • Hi @sam, please check this page https://docs.chain.link/chainlink-automation/compatible-contracts/#revalidate-performupkeep. By design, there are 2 functions: `checkUpkeep` and `performUpkeep`, and you are expected to put your validation logics in `checkUpkeep` and revalidate the same logics in `performUpkeep`. By this way, nothing will be broken even if the function could be called by a third-party. For example, if you want to do payment in `performUpkeep`, there has to be a validation logic to ensure the payment is legit. – Frank Kong Feb 04 '23 at 01:02
  • Hello @Frank Kong. I checked the page, and what I understood is that these two functions just allow to add validation logic as you said. The call is still done from the Chainlink Registry contract. Therefore, the msg.sender is still the registry contract. – sam Mar 23 '23 at 13:48
  • yes, what I mean is that you can set logics in `performUpkeep` can be executed by any address when you write the contract. Let's say, when the condition met, anyone can trigger `performUpkeep` so you don't need to consider the access control. – Frank Kong Mar 28 '23 at 02:54
  • Sure. But I need access control because I want the contract to be called only by an Admin address, that means I want to set msg.sender == AdminAddress. However, since the msg.sender is always the Chainlink Registry, this condition is likely to fail. That's my issue – sam Mar 29 '23 at 14:55