Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

fix: vulnerability causing division by zero with price rate calculation #66

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/action/execute/create_margin_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ fn create_margin_open_order(
return Err(StdError::generic_err("not valid collateral").into());
}

if let Some(price) = &trigger_price {
if price.rate.is_zero() {
return Err(StdError::generic_err("trigger_price: The rate cannot be zero").into());
}
}

let order = MarginOrder::new_open(
&info.sender,
&position,
Expand Down Expand Up @@ -222,6 +228,12 @@ fn create_margin_close_order(
return Err(StdError::generic_err("this position had an order already assigned").into());
};

if let Some(price) = &trigger_price {
if price.rate.is_zero() {
return Err(StdError::generic_err("trigger_price: The rate cannot be zero").into());
}
}

let order = MarginOrder::new_close(
&info.sender,
mtp.position,
Expand Down
6 changes: 6 additions & 0 deletions src/action/execute/create_spot_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub fn create_spot_order(
return Err(StdError::not_found("order price").into());
}

if let Some(price) = &order_price {
if price.rate.is_zero() {
return Err(StdError::generic_err("order_price: The rate cannot be zero").into());
}
}

check_denom_error(
&order_source_denom,
&order_target_denom,
Expand Down
Loading