From dccd8a4a7e0fdaf23d5bd2bdbed3ec5afff509dd Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Sat, 12 Oct 2024 09:11:01 +0200 Subject: [PATCH] fix: limit gas usage by sequencer tx --- crates/wallet/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/wallet/src/lib.rs b/crates/wallet/src/lib.rs index 0f6f4e1..3ece829 100644 --- a/crates/wallet/src/lib.rs +++ b/crates/wallet/src/lib.rs @@ -138,6 +138,11 @@ pub enum OdysseyWalletError { /// This is likely an internal error, as most of the request is built by the sequencer. #[error("invalid tx request")] InvalidTransactionRequest, + /// The request was estimated to consume too much gas. + /// + /// The gas usage by each request is limited to counteract draining the sequencers funds. + #[error("request would use too much gas")] + GasEstimateTooHigh, /// An internal error occurred. #[error("internal error")] InternalError, @@ -267,6 +272,9 @@ where EthCall::estimate_gas_at(&self.inner.eth_api, request.clone(), BlockId::latest(), None) .await .map_err(Into::into)?; + if estimate >= U256::from(150_000) { + return Err(OdysseyWalletError::GasEstimateTooHigh.into()); + } request = request.gas_limit(estimate.to()); // set gas fees