From 82684b2e8be71f01083b8c74b5b24f1039b08a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 22 Nov 2024 00:37:02 +0200 Subject: [PATCH] bridge-proxy: allow empty endpoint only if empty args --- bridge-proxy/src/bridge-proxy.rs | 4 +- .../tests/bridge_proxy_blackbox_test.rs | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index 0d984ad4..f66581d4 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -67,8 +67,8 @@ pub trait BridgeProxyContract: } else { CallData::default() }; - - if call_data.endpoint.is_empty() + let non_empty_args = call_data.args.is_some(); + if (call_data.endpoint.is_empty() && non_empty_args) || call_data.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL || call_data.gas_limit > MAX_GAS_LIMIT_FOR_SC_CALL { diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 20e287fc..8536cfff 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -776,3 +776,72 @@ fn bridge_proxy_too_small_gas_sc_call_test() { .check_account(ESDT_SAFE_ADDRESS) .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); } + +#[test] +fn bridge_proxy_empty_endpoint_with_args_test() { + let mut test = BridgeProxyTestState::new(); + + test.world.start_trace(); + + test.multisig_deploy(); + test.deploy_bridge_proxy(); + test.deploy_crowdfunding(); + test.config_bridge(); + + let mut args = ManagedVec::new(); + let call_data: CallData = CallData { + endpoint: ManagedBuffer::new(), + gas_limit: GAS_LIMIT, + args: ManagedOption::some(args), + }; + + let call_data: ManagedBuffer = + ManagedSerializer::new().top_encode_to_managed_buffer(&call_data); + + let eth_tx = EthTransaction { + from: EthAddress { + raw_addr: ManagedByteArray::new_from_bytes(b"01020304050607080910"), + }, + to: ManagedAddress::from(CROWDFUNDING_ADDRESS.eval_to_array()), + token_id: BRIDGE_TOKEN_ID.into(), + amount: BigUint::from(500u64), + tx_nonce: 1u64, + call_data: ManagedOption::some(call_data), + }; + + let amount = BigUint::from(500u64); + // Destination is not an initialized contract + test.world + .tx() + .from(MULTI_TRANSFER_ADDRESS) + .to(BRIDGE_PROXY_ADDRESS) + .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) + .deposit(ð_tx, 1u64) + .egld_or_single_esdt( + &EgldOrEsdtTokenIdentifier::esdt(BRIDGE_TOKEN_ID), + 0, + &amount, + ) + .run(); + + test.world + .query() + .to(BRIDGE_PROXY_ADDRESS) + .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) + .get_pending_transaction_by_id(1u32) + .returns(ExpectValue(eth_tx)) + .run(); + + test.world + .tx() + .from(OWNER_ADDRESS) + .to(BRIDGE_PROXY_ADDRESS) + .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) + .execute(1u32) + .run(); + + // Refund: Funds are transfered to EsdtSafe + test.world + .check_account(ESDT_SAFE_ADDRESS) + .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); +}