From bb951a1ea9426c392302bde30e87e0793baeedb9 Mon Sep 17 00:00:00 2001 From: FoxPink Date: Tue, 9 Jun 2026 23:16:58 +0700 Subject: [PATCH] fix: check ERC20 transfer return value in executeWithdrawal() - Bug fix: USDT returns false instead of reverting on failure; the contract would mark withdrawal as Executed despite funds not being sent - Add require on IERC20.transfer() return value - Gas: cache registry address in memory in _updateRegistryState() and createEscrow() --- src/Treasury.sol | 3 ++- src/escrow/SafeBaseEscrowV1.sol | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Treasury.sol b/src/Treasury.sol index 1ae4f05..3094213 100644 --- a/src/Treasury.sol +++ b/src/Treasury.sol @@ -152,7 +152,8 @@ contract Treasury is Initializable, UUPSUpgradeable, OwnableUpgradeable { (bool success,) = request.to.call{value: request.amount}(""); if (!success) revert TransferFailed(); } else { - IERC20(request.token).transfer(request.to, request.amount); + bool success = IERC20(request.token).transfer(request.to, request.amount); + if (!success) revert TransferFailed(); } emit WithdrawalExecuted(requestId); diff --git a/src/escrow/SafeBaseEscrowV1.sol b/src/escrow/SafeBaseEscrowV1.sol index 29be600..9efac3d 100644 --- a/src/escrow/SafeBaseEscrowV1.sol +++ b/src/escrow/SafeBaseEscrowV1.sol @@ -155,8 +155,9 @@ contract SafeBaseEscrowV1 is emit EscrowCreated(escrowId, msg.sender, _seller, _token, _amount, _deadline); - if (registry != address(0)) { - IRegistry(registry).indexEscrow(escrowId, msg.sender, _seller, _amount, block.timestamp); + address registry_ = registry; + if (registry_ != address(0)) { + IRegistry(registry_).indexEscrow(escrowId, msg.sender, _seller, _amount, block.timestamp); } return escrowId; @@ -369,8 +370,9 @@ contract SafeBaseEscrowV1 is function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} function _updateRegistryState(uint256 _escrowId) internal { - if (registry != address(0)) { - IRegistry(registry).updateEscrowState(_escrowId, uint8(escrows[_escrowId].state)); + address registry_ = registry; + if (registry_ != address(0)) { + IRegistry(registry_).updateEscrowState(_escrowId, uint8(escrows[_escrowId].state)); } }