hats-finance / Most--Aleph-Zero-Bridge-0xab7c1d45ae21e7133574746b2985c58e0ae2e61d

Aleph Zero bridge to Ethereum
Apache License 2.0
0 stars 1 forks source link

Lack of possible changes on various gas variables #30

Open hats-bug-reporter[bot] opened 5 months ago

hats-bug-reporter[bot] commented 5 months ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0xc4a211bc5db6e439b9d5e3e87e3ccea9c5ce4c2e8f0c1d9b4a5fb465982c0c86 Severity: minor

Description: Description

There are relay_gas_usage, min_gas_price, max_gas_price and default_gas_price in Most which are immutable since there is no way to update this value again after initialized in constructor.

These values need to have a modification access for further changes.

For example, based on the comments line 134, it's says, the relay_gas_usage value is calculated by summing total gas divided by current committee size and mul by 1.2

File: lib.rs
133:         /// How much gas does a single confirmation of a cross-chain transfer request use on the destination chain on average.
134:         /// This value is calculated by summing the total gas usage of *all* the transactions it takes to relay a single request and dividing it by the current committee size and multiplying by 1.2
135:         relay_gas_usage: u128,
136:         /// minimum gas price used to calculate the fee that can be charged for a cross-chain transfer request
137:         min_gas_price: u128,
138:         /// maximum gas price used to calculate the fee that can be charged for a cross-chain transfer request
139:         max_gas_price: u128,
140:         /// default gas price used to calculate the fee that is charged for a cross-chain transfer request if the gas price oracle is not available/malfunctioning
141:         default_gas_price: u128,
...
592:         pub fn get_base_fee(&self) -> Result<Balance, MostError> {
...
620:             let base_fee = gas_price
621:                 .checked_mul(self.data()?.relay_gas_usage)
622:                 .ok_or(MostError::Arithmetic)?
623:                 .checked_mul(100u128 + BASE_FEE_BUFFER_PERCENTAGE)
624:                 .ok_or(MostError::Arithmetic)?
625:                 .checked_div(100u128)
626:                 .ok_or(MostError::Arithmetic)?;
627:             Ok(base_fee)
628:         }

committee_sizes might grow, and this relay gas usage need to be updated to align with the growth, otherwise it will became lesser, affecting the base_fee. The relay_gas_usage is being used to calculate base_fee, gas_price * relay_gas_usage * 120 / 100.

Also, noticing gas_price_oracle can be changed, and this oracle will be compared with those immutable values (min_gas_price and max_gas_price, also will return default_gas_price if outdated), so if azero introduce change of gas, implementing this update of those immutable variables can mitigate the issue.

File: lib.rs
597:                 match gas_price_oracle
598:                     .call()
599:                     .get_price()
600:                     .gas_limit(ORACLE_CALL_GAS_LIMIT)
601:                     .try_invoke()
602:                 {
603:                     Ok(Ok((gas_price, timestamp))) => {
604:                         if timestamp + GAS_ORACLE_MAX_AGE < self.env().block_timestamp() {
605:                             self.data()?.default_gas_price
606:                         } else if gas_price < self.data()?.min_gas_price {
607:                             self.data()?.min_gas_price
608:                         } else if gas_price > self.data()?.max_gas_price {
609:                             self.data()?.max_gas_price
610:                         } else {
611:                             gas_price
612:                         }
613:                     }
614:                     _ => self.data()?.default_gas_price,
615:                 }

This is not a low, but instead a minor issue which doesn't need any PoC.

Recommendation

Consider to implement a function which can change those gas variables instead of making it immutable

krzysztofziobro commented 4 months ago

Valid submission - minor