fix(contracts): check transfer return value on profit sweep#307
Merged
fix(contracts): check transfer return value on profit sweep#307
Conversation
The profit sweep at executeOperation line 413 discarded the return value of IERC20(p.debtToken).transfer(COLD_WALLET, profit). Standard ERC-20s revert on failure, but BEP-20 and legacy tokens return `false` without reverting. A silent `false` would leave the profit stranded in this contract while the subsequent emit, Aave approval, and flashloan repayment all succeed — operator logs would show a successful liquidation while the cold wallet received nothing. Adopt the same bool-ok + require pattern already used by rescue() at :463 (no SafeERC20, consistent with the no-external-dependency policy). Other approve() call sites in this file also discard return values (lines 331, 344, 373, 390, 428) — tracked as a follow-up, out of scope here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mev-sim-auditorflaggedCharonLiquidator.sol:413as a P3 issue during static audit of PR #305:IERC20(p.debtToken).transfer(COLD_WALLET, profit)discarded the return value. Standard ERC-20s revert on failure, but BEP-20 and some legacy tokens returnfalsewithout reverting. A silentfalsewould strand profit in this contract while the emit, Aave approval, and flashloan repayment all succeed — operator logs would show a successful liquidation while the cold wallet received nothing.Fix
Adopt the same
bool ok; require(ok, ...)pattern already used byrescue()at:463. NoSafeERC20— consistent with the no-external-dependency policy stated at:440.Review (solidity-secure-dev): APPROVE
SafeERC20would violate no-deps policy.debtToken:executeOperationrejects re-entry atrequire(msg.sender == AAVE_POOL)andexecuteLiquidationisnonReentrant.LiquidationExecutedemit is AFTER therequire, so a failed sweep never emits a misleading success log.Follow-up (out of scope)
Five
approve()calls in the same file also discard their return values (lines 331, 344, 373, 390, 428). Tracked for a separate hardening PR; Venus-listed BSC tokens all conform today but the pattern carries the same theoretical gap.Test plan
forge build --force-> Compiler run successfulfalseon transfer causes executeOperation to revert with"profit: transfer failed". Runs on feat/25 (parallel-terminal scope) after this merges.