From 4f5897700790a0eaeb88a78c909fb3835527acfb Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Fri, 6 Jun 2025 17:24:07 +0100 Subject: [PATCH] fix(BalancerV3Executor): Do data.length check at the beginning of swap Took 16 minutes --- foundry/src/executors/BalancerV3Executor.sol | 7 +++---- foundry/test/executors/BalancerV3Executor.t.sol | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/foundry/src/executors/BalancerV3Executor.sol b/foundry/src/executors/BalancerV3Executor.sol index 19aa12f..82c44ef 100644 --- a/foundry/src/executors/BalancerV3Executor.sol +++ b/foundry/src/executors/BalancerV3Executor.sol @@ -31,6 +31,9 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback { payable returns (uint256 calculatedAmount) { + if (data.length != 81) { + revert BalancerV3Executor__InvalidDataLength(); + } bytes memory result = VAULT.unlock( abi.encodeCall( BalancerV3Executor.swapCallback, @@ -113,10 +116,6 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback { address receiver ) { - if (data.length != 113) { - revert BalancerV3Executor__InvalidDataLength(); - } - amountGiven = uint256(bytes32(data[0:32])); tokenIn = IERC20(address(bytes20(data[32:52]))); tokenOut = IERC20(address(bytes20(data[52:72]))); diff --git a/foundry/test/executors/BalancerV3Executor.t.sol b/foundry/test/executors/BalancerV3Executor.t.sol index c8ff878..3a1a182 100644 --- a/foundry/test/executors/BalancerV3Executor.t.sol +++ b/foundry/test/executors/BalancerV3Executor.t.sol @@ -68,7 +68,7 @@ contract BalancerV3ExecutorTest is Constants, TestUtils { assertEq(receiver, BOB); } - function testDecodeParamsInvalidDataLength() public { + function testSwapInvalidDataLength() public { bytes memory invalidParams = abi.encodePacked( osETH_ADDR, waEthWETH_ADDR, @@ -77,7 +77,7 @@ contract BalancerV3ExecutorTest is Constants, TestUtils { ); vm.expectRevert(BalancerV3Executor__InvalidDataLength.selector); - balancerV3Exposed.decodeParams(invalidParams); + balancerV3Exposed.swap(1 ether, invalidParams); } function testSwap() public {