我有一个管理员的performUpKeep功能,这是关键的任务,只有管理员可以打电话,而不是一些随机的第三方,以激活合同更快。似乎链链管理员不断变化,所以我如何确保只有守门员才能调用合同?
发布于 2021-11-01 18:03:32
理想情况下,您只需要验证checkUpKeep是否返回true,并且对输入进行一些数据验证,以确保它只能执行您希望它做的事情。根据链式github:
如果你想忽视这件事..。(您不应该这么做),但是您可以向您的onlyKeepers函数中添加一个performUpkeep修饰符,这样只有Keepers注册中心才能调用您的合同。
address public keepersRegistry = xxxxxx;
modifier onlyKeepers() {
require(msg.sender == keepersRegistry, "Ownable: caller is not keepers registry");
_;
}然后用它包装你的函数。
function functionName() onlyKeepers {
....
}发布于 2021-11-01 18:43:23
添加到前面的答案,因为我不确定它是否正确。
chainlink KeeperCompatibleInterface实现为performUpkeep函数指定:
* @dev The input to this method should not be trusted, and the caller of the
* method should not even be restricted to any single registry. Anyone should
* be able call it, and the input should be validated, there is no guarantee
* that the data passed in is the performData returned from checkUpkeep. This
* could happen due to malicious keepers, racing keepers, or simply a state
* change while the performUpkeep transaction is waiting for confirmation.
* Always validate the data passed in.其中最重要的一点显然是:
* @dev The input to this method should not be trusted, and the caller of the
* method should not even be restricted to any single registry.考虑到您必须实现一个checkUpkeep函数,您只需在调用performUpkeep逻辑之前再次检查checkUpkeep的条件就可以保证自己的安全。当需要维修时,如果第三方要求你的合同,那就去做。如果没有,则恢复事务。
作为指定的这里。
https://ethereum.stackexchange.com/questions/112677
复制相似问题