Skip to content

Commit

Permalink
Merge pull request #233 from multiversx/max-gas-limit-execution
Browse files Browse the repository at this point in the history
max gas limit check
  • Loading branch information
iulianpascalau authored Oct 17, 2024
2 parents c38aeb7 + 2399de9 commit 10502db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"arguments": [
"0x01"
],
"gasLimit": "5,000,000"
"gasLimit": "200000000"
},
"expect": {
"out": [],
Expand Down
6 changes: 5 additions & 1 deletion bridge-proxy/src/bridge-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions bridge-proxy/tests/bridge_proxy_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 10502db

Please sign in to comment.