Skip to content

Commit d9acfc9

Browse files
authored
fix: ERC20 return data size (DEV-1147) (#237)
1 parent 60eceb8 commit d9acfc9

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/ForeignController.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
201201
);
202202

203203
require(
204-
returnData.length == 0 || abi.decode(returnData, (bool)),
204+
returnData.length == 0 || (returnData.length == 32 && abi.decode(returnData, (bool))),
205205
"FC/transfer-failed"
206206
);
207207
}
@@ -496,7 +496,10 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
496496
// decode it first
497497
approveCallReturnData = abi.decode(data, (bytes));
498498
// Approve was successful if 1) no return value or 2) true return value
499-
if (approveCallReturnData.length == 0 || abi.decode(approveCallReturnData, (bool))) {
499+
if (
500+
approveCallReturnData.length == 0 ||
501+
(approveCallReturnData.length == 32 && abi.decode(approveCallReturnData, (bool)))
502+
) {
500503
return;
501504
}
502505
}
@@ -508,7 +511,9 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
508511

509512
// Revert if approve returns false
510513
require(
511-
approveCallReturnData.length == 0 || abi.decode(approveCallReturnData, (bool)),
514+
approveCallReturnData.length == 0 ||
515+
(approveCallReturnData.length == 32 && abi.decode(approveCallReturnData, (bool))
516+
),
512517
"FC/approve-failed"
513518
);
514519
}

src/MainnetController.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
11581158
);
11591159

11601160
require(
1161-
returnData.length == 0 || abi.decode(returnData, (bool)),
1161+
returnData.length == 0 || (returnData.length == 32 && abi.decode(returnData, (bool))),
11621162
"MC/transfer-failed"
11631163
);
11641164
}
@@ -1175,7 +1175,7 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
11751175
);
11761176

11771177
require(
1178-
returnData.length == 0 || abi.decode(returnData, (bool)),
1178+
returnData.length == 0 || (returnData.length == 32 && abi.decode(returnData, (bool))),
11791179
"MC/transferFrom-failed"
11801180
);
11811181
}

src/libraries/ApproveLib.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ library ApproveLib {
2222
returnData = abi.decode(data, (bytes));
2323

2424
// Approve was successful if 1) no return value or 2) true return value.
25-
if (returnData.length == 0 || abi.decode(returnData, (bool))) return;
25+
if (
26+
returnData.length == 0 ||
27+
(returnData.length == 32 && abi.decode(returnData, (bool)))
28+
) return;
2629
}
2730

2831
// If call was unsuccessful, set to zero and try again.
@@ -31,7 +34,10 @@ library ApproveLib {
3134
returnData = IALMProxy(proxy).doCall(token, approveData);
3235

3336
// Revert if approve returns false.
34-
require(returnData.length == 0 || abi.decode(returnData, (bool)), "MC/approve-failed");
37+
require(
38+
returnData.length == 0 || (returnData.length == 32 && abi.decode(returnData, (bool))),
39+
"MC/approve-failed"
40+
);
3541
}
3642

3743
}

src/libraries/UniswapV4Lib.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ library UniswapV4Lib {
280280

281281
// Revert if approve returns anything, and that anything is not `true`.
282282
require(
283-
approveResult.length == 0 || abi.decode(approveResult, (bool)),
283+
approveResult.length == 0 ||
284+
(approveResult.length == 32 && abi.decode(approveResult, (bool))),
284285
"MC/permit2-approve-failed"
285286
);
286287
}

0 commit comments

Comments
 (0)