Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for invalid conversion rate (SlowMist N3) #139

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: add check for invalid conversion rate
  • Loading branch information
clostao committed Nov 7, 2023
commit c8866d7d37d5e466768004fcc341457a68a34475
13 changes: 13 additions & 0 deletions pallets/dnt-fee-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod pallet {
ERC20WithdrawFailed,
ERC20DepositFailed,
FeeVaultOverflow,
InvalidConversionRate,
InvalidPercentage,
}

Expand Down Expand Up @@ -103,6 +104,10 @@ pub mod pallet {
conversion_rate: (U256, U256),
amount: U256,
) -> Result<(), Self::Error> {
if conversion_rate.1 == U256::zero() {
return Err(Error::<T>::InvalidConversionRate);
}

let fee_vault = FeeVaultPrecompileAddressStorage::<T>::get().unwrap();
let mapped_amount = amount
.saturating_mul(conversion_rate.0)
Expand All @@ -123,6 +128,10 @@ pub mod pallet {
paid_amount: U256,
actual_amount: U256,
) -> Result<(), Self::Error> {
if conversion_rate.1 == U256::zero() {
return Err(Error::<T>::InvalidConversionRate);
}

let over_fee = paid_amount.saturating_sub(actual_amount);
let mapped_amount = over_fee
.saturating_mul(conversion_rate.0)
Expand All @@ -144,6 +153,10 @@ pub mod pallet {
validator: H160,
to: Option<H160>,
) -> Result<(U256, U256), Self::Error> {
if conversion_rate.1 == U256::zero() {
return Err(Error::<T>::InvalidConversionRate);
}

let fee_in_user_token = actual_amount
.saturating_mul(conversion_rate.0)
.div_mod(conversion_rate.1)
Expand Down
4 changes: 4 additions & 0 deletions pallets/sponsored-transactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ pub mod pallet {
payee: &H160,
amount: U256,
) -> Result<(), ()> {
if conversion_rate.1 == U256::zero() {
return Err(Error::<T>::InvalidConversionRate);
}

let actual_amount = amount
.saturating_mul(conversion_rate.0)
.div_mod(conversion_rate.1)
Expand Down
Loading