fix(order-vault): gate record_transfer_in behind CONTROLLER auth - #703
Merged
IbrahimIjai merged 1 commit intoAug 31, 2026
Conversation
SO4-Markets#541) record_transfer_in resyncs the vault's recorded per-token balance and was fully public — callable by any address at any time, unlike every other state-mutating function in this contract (transfer_out is CONTROLLER-gated). This let an attacker front-run a victim's deposit: call record_transfer_in right after the victim's collateral transfer lands but before their create_order executes, resyncing the recorded balance so create_order sees delta == 0 and reverts with ZeroCollateral — stranding the victim's tokens in the vault with no path to reclaim them. Gate it to CONTROLLER, mirroring transfer_out in the same file, and update the two order_handler call sites (create_order, create_orders) to pass the handler's own address as caller, matching how they already call transfer_out.
|
@dev-debbie-umoh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Issue #386 ("order_vault: unauthenticated record_transfer_in lets deposits be stolen or stranded") was closed, but
record_transfer_inincontracts/order_vault/src/lib.rswas never actually changed — it remained fully public with norequire_auth()/CONTROLLER check, unliketransfer_outin the same file.Anyone could call
order_vault.record_transfer_in(token)directly right after observing a victim's deposit land but before the victim's owncreate_ordercall executes. This resyncs the recorded balance to the current on-chain balance, so the victim's subsequentcreate_orderseesdelta == 0, reverts withZeroCollateral, and the victim's tokens are stuck in the vault (transfer_outis CONTROLLER-gated and only ever invoked against a matchingOrderPropsthat was never created).Fix
record_transfer_innow takes acaller: Address, callscaller.require_auth(), and is gated to CONTROLLER — mirroringtransfer_outin the same file.order_handlercall sites (create_order,create_orders) to pass the handler's own address ascaller, matching how they already calltransfer_out.record_transfer_indirectly.Closes #541
Test plan
cargo test -p order-vault— 8 passed, 0 failed (includes newrecord_transfer_in_by_non_controller_panics)cargo test -p order-handler --lib— 63 passed, 0 failed (3 unrelated pre-existing failures on unmodifiedmaintoo:custom_heartbeat_timeout_is_respected,execute_order_records_keeper_heartbeat,keeper_goes_stale_after_timeout_and_role_is_revocable— oracle price-lookup issue unrelated to this change, verified independently)