Lack of validation in setlistforsell
allows changing denom while there is active bid, leading to stealing of other users' funds
#5
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-06
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_05_group
AI based duplicate group recommendation
selected for report
This submission will be included/highlighted in the audit report
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L619-L645
Vulnerability details
Impact
This vulnerability allows attacker to manipulate the token denom during an active bid. By exploiting this bug, attackers can cancel their own bids and receive refunds in a more valuable token than originally used, effectively stealing funds from the contract's pool of user deposits.
Description
The bug stems from a lack of validation in the
setlistforsell
function, which allows sellers to change the payment token (denom) even when there are active bids on a token.The
setbidtobuy
function, when used to cancel a bid, refunds the buyer using the current denom specified for the token:However, the
setlistforsell
function lacks checks for active bids, allowing a seller to change the denom at any time. This creates an exploit scenario where an attacker can:setlistforsell
again, changing the denom to a high-value token (e.g., USDC worth $1).setbidtobuy
, receiving a refund in the new, more valuable USDC.This exploit allows the attacker to drain funds from the contract that were deposited by other users. For example, if the attacker initially bid 1,000 TokenX (
$10
), they could receive 1,000 USDC ($1,000
) as a refund, effectively stealing USDC from the contract.Proof-of-Concept
The following test demonstrate the described scenario.
Boilerplate for PoC: https://gist.github.com/nnez/c76b1a867dd8dc441dbe552e048b796e
Steps
contracts/codedestate/src/multi_tests.rs
with boilerplate from above secret gist.cargo test h3_drain_funds_by_updates_selling_denom -- --nocapture
Recommended Mitigations
denom
while there is active bid.setlistforsell
while there is active bid might also introduce a deadlock for seller.OR
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: