You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The transferCrossChain function includes multiple external calls and relies on a fixed gas limit through gasLimitAmount. This design can lead to operational failures during high network demand and introduces risks due to inadequate external call validation.
function transferCrossChain(
addressdestination,
addressreceiver,
uint256amount
) public {
if (receiver ==address(0)) revertInvalidAddress();
_burn(msg.sender, amount);
(addressgasZRC20, uint256gasFee) =IZRC20(destination)
.withdrawGasFeeWithGasLimit(gasLimitAmount);
if (destination != gasZRC20) revertInvalidAddress();
if (!IZRC20(destination).transferFrom(msg.sender, address(this), gasFee))
revertTransferFailed();
if (!IZRC20(destination).approve(address(gateway), gasFee)) {
revertApproveFailed();
}
bytesmemory message =abi.encode(receiver, amount, 0, msg.sender);
CallOptions memory callOptions =CallOptions(gasLimitAmount, false);
RevertOptions memory revertOptions =RevertOptions(
address(this),
true,
address(0),
abi.encode(amount, msg.sender),
gasLimitAmount
);
The gasLimitAmount is immutable, preventing adaptation to fluctuating gas requirements.
External calls (IZRC20 and gateway.call) lack comprehensive validation, exposing the function to potential failures or misbehavior from external contracts.
How It Can Be Harmful
Operational Failures: Fixed gas limits may lead to transaction failures during high network congestion, leaving tokens burned without completing the transfer.
External Call Risks: Unchecked external calls can result in unexpected reverts or malicious behavior.
How to Mitigate the Issue
1.Make Gas Limit Adjustable: Replace the immutable gasLimitAmount with a state variable and provide a setter function for the owner:
uint256public gasLimitAmount;
function setGasLimit(uint256gas) external onlyOwner {
require(gas >0, "Invalid gas limit");
gasLimitAmount = gas;
}
2. Validate External Calls: Use try/catch blocks to handle failures gracefully and emit events for better debugging:
3.Log Gas Fee Usage: Emit detailed events to trace gas fee calculations and usage.
References:
SWC-128: DoS with Block Gas Limit
Highlights vulnerabilities caused by fixed gas limits and their impact on operational functionality. SWC Registry - SWC-128
OpenZeppelin Adjustable Parameters
Guidance on implementing adjustable parameters to improve contract flexibility. OpenZeppelin Blog
CVE-2018-14732
Denial of Service (DoS) vulnerability caused by insufficient gas limit validation. CVE-2018-14732
CVE-2020-26272
Highlights issues related to external contract interactions that may result in unintended behaviors or failures. CVE-2020-26272
The text was updated successfully, but these errors were encountered:
Vulnerability Details
The
transferCrossChain
function includes multiple external calls and relies on a fixed gas limit throughgasLimitAmount
. This design can lead to operational failures during high network demand and introduces risks due to inadequate external call validation.Analysis
The vulnerable implementation is as follows:
standard-contracts/contracts/nft/contracts/evm/UniversalNFT.sol
Line 23 in a08166a
gasLimitAmount
is immutable, preventing adaptation to fluctuating gas requirements.IZRC20
andgateway.call
) lack comprehensive validation, exposing the function to potential failures or misbehavior from external contracts.How It Can Be Harmful
How to Mitigate the Issue
1.Make Gas Limit Adjustable: Replace the immutable gasLimitAmount with a state variable and provide a setter function for the owner:
2. Validate External Calls: Use try/catch blocks to handle failures gracefully and emit events for better debugging:
3.Log Gas Fee Usage: Emit detailed events to trace gas fee calculations and usage.
References:
SWC-128: DoS with Block Gas Limit
Highlights vulnerabilities caused by fixed gas limits and their impact on operational functionality.
SWC Registry - SWC-128
OpenZeppelin Adjustable Parameters
Guidance on implementing adjustable parameters to improve contract flexibility.
OpenZeppelin Blog
CVE-2018-14732
Denial of Service (DoS) vulnerability caused by insufficient gas limit validation.
CVE-2018-14732
CVE-2020-26272
Highlights issues related to external contract interactions that may result in unintended behaviors or failures.
CVE-2020-26272
The text was updated successfully, but these errors were encountered: