diff --git a/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json b/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json index 60b727a3..bb5fcdbb 100644 --- a/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json +++ b/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json @@ -226,7 +226,7 @@ "arguments": [ "0x01" ], - "gasLimit": "5,000,000" + "gasLimit": "200000000" }, "expect": { "out": [], diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index eff2bbbf..9c6ab54b 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -9,6 +9,7 @@ pub mod esdt_safe_proxy; use transaction::{CallData, EthTransaction}; const MIN_GAS_LIMIT_FOR_SC_CALL: u64 = 10_000_000; +const MAX_GAS_LIMIT_FOR_SC_CALL: u64 = 249999999; const DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK: u64 = 20_000_000; // 20 million const DELAY_BEFORE_OWNER_CAN_CANCEL_TRANSACTION: u64 = 300; const MIN_GAS_TO_SAVE_PROGRESS: u64 = 100_000; @@ -71,13 +72,16 @@ pub trait BridgeProxyContract: }; if call_data.endpoint.is_empty() - || call_data.gas_limit == 0 || call_data.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL + || call_data.gas_limit > MAX_GAS_LIMIT_FOR_SC_CALL { self.finish_execute_gracefully(tx_id); return; } + let gas_left = self.blockchain().get_gas_left(); + require!(gas_left > call_data.gas_limit + DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK, "Not enough gas to execute"); + let tx_call = self .tx() .to(&tx.to) diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 9d4ca725..efd2237f 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -291,6 +291,7 @@ fn bridge_proxy_execute_crowdfunding_test() { .tx() .from(OWNER_ADDRESS) .to(BRIDGE_PROXY_ADDRESS) + .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .execute(1u32) .run(); @@ -384,6 +385,7 @@ fn multiple_deposit_test() { .tx() .from(OWNER_ADDRESS) .to(BRIDGE_PROXY_ADDRESS) + .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .execute(1u32) .run(); @@ -400,6 +402,7 @@ fn multiple_deposit_test() { .tx() .from(OWNER_ADDRESS) .to(BRIDGE_PROXY_ADDRESS) + .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .execute(2u32) .run(); @@ -485,6 +488,7 @@ fn test_lowest_tx_id() { .tx() .from(OWNER_ADDRESS) .to(BRIDGE_PROXY_ADDRESS) + .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .execute(i) .run(); @@ -505,6 +509,7 @@ fn test_lowest_tx_id() { .tx() .from(OWNER_ADDRESS) .to(BRIDGE_PROXY_ADDRESS) + .gas(200_000_000) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .execute(i) .run();