fix(BalancerV3Executor): Do data.length check at the beginning of swap

Took 16 minutes
This commit is contained in:
Diana Carvalho
2025-06-06 17:24:07 +01:00
parent 941879d5d6
commit 4f58977007
2 changed files with 5 additions and 6 deletions

View File

@@ -31,6 +31,9 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
payable payable
returns (uint256 calculatedAmount) returns (uint256 calculatedAmount)
{ {
if (data.length != 81) {
revert BalancerV3Executor__InvalidDataLength();
}
bytes memory result = VAULT.unlock( bytes memory result = VAULT.unlock(
abi.encodeCall( abi.encodeCall(
BalancerV3Executor.swapCallback, BalancerV3Executor.swapCallback,
@@ -113,10 +116,6 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
address receiver address receiver
) )
{ {
if (data.length != 113) {
revert BalancerV3Executor__InvalidDataLength();
}
amountGiven = uint256(bytes32(data[0:32])); amountGiven = uint256(bytes32(data[0:32]));
tokenIn = IERC20(address(bytes20(data[32:52]))); tokenIn = IERC20(address(bytes20(data[32:52])));
tokenOut = IERC20(address(bytes20(data[52:72]))); tokenOut = IERC20(address(bytes20(data[52:72])));

View File

@@ -68,7 +68,7 @@ contract BalancerV3ExecutorTest is Constants, TestUtils {
assertEq(receiver, BOB); assertEq(receiver, BOB);
} }
function testDecodeParamsInvalidDataLength() public { function testSwapInvalidDataLength() public {
bytes memory invalidParams = abi.encodePacked( bytes memory invalidParams = abi.encodePacked(
osETH_ADDR, osETH_ADDR,
waEthWETH_ADDR, waEthWETH_ADDR,
@@ -77,7 +77,7 @@ contract BalancerV3ExecutorTest is Constants, TestUtils {
); );
vm.expectRevert(BalancerV3Executor__InvalidDataLength.selector); vm.expectRevert(BalancerV3Executor__InvalidDataLength.selector);
balancerV3Exposed.decodeParams(invalidParams); balancerV3Exposed.swap(1 ether, invalidParams);
} }
function testSwap() public { function testSwap() public {