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:
TAMARA LIPOWSKI
2025-01-24 17:15:12 -05:00
parent ad0748e9c3
commit 8ef061fd75
4 changed files with 79 additions and 38 deletions

View File

@@ -10,7 +10,6 @@ import "./CallbackVerificationDispatcher.sol";
error TychoRouter__WithdrawalFailed();
error TychoRouter__AddressZero();
error TychoRouter__NonContractVerifier();
contract TychoRouter is
AccessControl,
@@ -44,7 +43,6 @@ contract TychoRouter is
address indexed oldFeeReceiver, address indexed newFeeReceiver
);
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
event CallbackVerifierSet(address indexed callbackVerifier);
constructor(address _permit2) {
permit2 = IAllowanceTransfer(_permit2);
@@ -121,9 +119,7 @@ contract TychoRouter is
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
if (target.code.length == 0) revert TychoRouter__NonContractVerifier();
callbackVerifiers[target] = true;
emit CallbackVerifierSet(target);
_setCallbackVerifier(target);
}
/**
@@ -134,7 +130,7 @@ contract TychoRouter is
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
delete callbackVerifiers[target];
_removeCallbackVerifier(target);
}
/**