refactor: Move code check to CallbackVerificationDispatcher
[copied from exact same reasoning with execution code-checking] I was inspired to do this because, when disabling the slither check for the staticcall when calling the callback verifier, I realized it's not clear from the same contract that we have already checked for contract code existence when setting the verifier. This made me feel uneasy, as this contract can then not stand alone and must rely on the higher level contract to safely check for code existence, otherwise the staticcall is unsafe. Keeping this logic in a separate contract seems error-prone to me, as we may remove the check for code existence without immediately realizing the implications of doing so. For this reason I have organized it as follows: - Logic/tests relating to proper roles/access control in the main TychoRouter. - Lower-level logic/tests that check contract validity before setting the callback verifier in the CallbackVerificationDispatcher
This commit is contained in:
@@ -18,6 +18,31 @@ error CallbackVerificationDispatcher__NonContractVerifier();
|
||||
contract CallbackVerificationDispatcher {
|
||||
mapping(address => bool) public callbackVerifiers;
|
||||
|
||||
event CallbackVerifierSet(address indexed callbackVerifier);
|
||||
event CallbackVerifierRemoved(address indexed callbackVerifier);
|
||||
|
||||
/**
|
||||
* @dev Adds or replaces an approved callback verifier contract address if it is a
|
||||
* contract.
|
||||
* @param target address of the callback verifier contract
|
||||
*/
|
||||
function _setCallbackVerifier(address target) internal {
|
||||
if (target.code.length == 0) {
|
||||
revert CallbackVerificationDispatcher__NonContractVerifier();
|
||||
}
|
||||
callbackVerifiers[target] = true;
|
||||
emit CallbackVerifierSet(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Removes an approved callback verifier contract address
|
||||
* @param target address of the callback verifier contract
|
||||
*/
|
||||
function _removeCallbackVerifier(address target) internal {
|
||||
delete callbackVerifiers[target];
|
||||
emit CallbackVerifierRemoved(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Calls a callback verifier. This should revert if the callback verification fails.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user