Skip to content

Commit 5e3aa82

Browse files
authored
🐞 Fix safeMoveETH (#1479)
1 parent d07f92e commit 5e3aa82

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

β€Žsrc/utils/SafeTransferLib.solβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ library SafeTransferLib {
214214
let balanceBefore := balance(to) // Check via delta, in case `SELFDESTRUCT` is bricked.
215215
mstore(0x00, to)
216216
pop(call(gas(), mover, amount, 0x00, 0x20, codesize(), 0x00))
217-
if iszero(lt(add(amount, balance(to)), balanceBefore)) { break }
218-
if lt(selfBalanceBefore, selfbalance()) { invalid() } // Just in case.
217+
// If `address(to).balance >= amount + balanceBefore`, skip vault workflow.
218+
if iszero(lt(balance(to), add(amount, balanceBefore))) { break }
219+
// Just in case `SELFDESTRUCT` is changed to not revert and do nothing.
220+
if lt(selfBalanceBefore, selfbalance()) { invalid() }
219221
}
220222
let m := mload(0x40)
221223
// If the mover is missing or bricked, deploy a minimal vault

β€Žtest/SafeTransferLib.t.solβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,10 @@ contract SafeTransferLibTest is SoladyTest {
12181218
assertEq(to.balance, amount0);
12191219
assertEq(address(this).balance, selfBalanceBefore - amount0);
12201220

1221+
if (_randomChance(2)) {
1222+
vm.etch(SafeTransferLib.ETH_MOVER, "");
1223+
}
1224+
12211225
if (SafeTransferLib.ETH_MOVER.code.length == 0) {
12221226
address vault = this.safeMoveETH(to, amount1);
12231227
assertEq(vault.balance, amount1);

0 commit comments

Comments
Β (0)