Skip to content

Commit a01f507

Browse files
authored
fix: check return value from transfer funds (#1351)
1 parent d4e8ce4 commit a01f507

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

contracts/contracts/gateway/GatewayManagerFacet.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {
103103
// Release fund flows from Gateway -> SubnetActor -> ReleaseQueue (Locking) -> Validator.
104104
// Because msg.sender is actually the subnet actor, this method sends the fund back to
105105
// the subnet actor caller.
106-
SubnetActorGetterFacet(msg.sender).collateralSource().transferFunds(payable(msg.sender), amount);
106+
SubnetActorGetterFacet(msg.sender).collateralSource().safeTransferFunds(payable(msg.sender), amount);
107107
}
108108

109109
/// @notice kill an existing subnet.
@@ -126,7 +126,7 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {
126126
delete s.subnets[id];
127127

128128
s.subnetKeys.remove(id);
129-
SubnetActorGetterFacet(msg.sender).collateralSource().transferFunds(payable(msg.sender), stake);
129+
SubnetActorGetterFacet(msg.sender).collateralSource().safeTransferFunds(payable(msg.sender), stake);
130130

131131
emit SubnetDestroyed(subnet.id);
132132
}

contracts/contracts/lib/AssetHelper.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ library AssetHelper {
1414
using ExcessivelySafeCall for address;
1515
using SafeERC20 for IERC20;
1616

17+
error TransferFailed(address, address, uint256);
18+
1719
uint16 constant private MAX_MEMORY_SIZE = 128;
1820

1921
/// @notice Assumes that the address provided belongs to a subnet rooted on this network,
@@ -82,6 +84,19 @@ library AssetHelper {
8284
}
8385
}
8486

87+
/// @notice Transfers the specified amount out of our treasury to the recipient address. Reverts on failure.
88+
function safeTransferFunds(Asset memory asset,
89+
address payable recipient,
90+
uint256 value
91+
) internal returns (bytes memory) {
92+
(bool success, bytes memory ret) = transferFunds(asset, recipient, value);
93+
if (!success) {
94+
revert TransferFailed(address(this), recipient, value);
95+
}
96+
97+
return ret;
98+
}
99+
85100
/// @notice Wrapper for an IERC20 transfer that bubbles up the success or failure
86101
/// and the return value instead of reverting so a cross-message receipt can be
87102
/// triggered from the execution.

0 commit comments

Comments
 (0)