refactor: Move contract code-checking logic to SwapExecutionDispatcher

I was inspired to do this because, when disabling the slither check for the delegatecall when calling the swap executor, I realized it's not clear from the same contract that we have already checked for contract code existence when setting the executor. 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 delegatecall 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 checks contract validity before setting the executor in the SwapExecutionDispatcher
This commit is contained in:
TAMARA LIPOWSKI
2025-01-23 15:40:24 -05:00
parent b616e11354
commit fb9f340cb7
6 changed files with 86 additions and 59 deletions

View File

@@ -20,33 +20,13 @@ contract TychoRouterTest is TychoRouterTestSetup {
address indexed token, uint256 amount, address indexed receiver
);
function testSetValidExecutor() public {
function testSetExecutorValidRole() public {
vm.startPrank(executorSetter);
vm.expectEmit();
// Define the event we expect to be emitted at the next step
emit ExecutorSet(DUMMY);
tychoRouter.setSwapExecutor(DUMMY);
vm.stopPrank();
assert(tychoRouter.swapExecutors(DUMMY) == true);
}
function testRemoveExecutor() public {
vm.startPrank(executorSetter);
tychoRouter.setSwapExecutor(DUMMY);
tychoRouter.removeSwapExecutor(DUMMY);
vm.stopPrank();
assert(tychoRouter.swapExecutors(DUMMY) == false);
}
function testRemoveUnSetExecutor() public {
vm.startPrank(executorSetter);
tychoRouter.removeSwapExecutor(BOB);
vm.stopPrank();
assert(tychoRouter.swapExecutors(BOB) == false);
}
function testRemoveExecutorMissingSetterRole() public {
vm.expectRevert();
tychoRouter.removeSwapExecutor(BOB);
@@ -57,15 +37,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
tychoRouter.setSwapExecutor(DUMMY);
}
function testSetExecutorNonContract() public {
vm.startPrank(executorSetter);
vm.expectRevert(
abi.encodeWithSelector(TychoRouter__NonContractExecutor.selector)
);
tychoRouter.setSwapExecutor(BOB);
vm.stopPrank();
}
function testSetValidVerifier() public {
vm.startPrank(executorSetter);
vm.expectEmit();