Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce gas use limit for omnichain call hooks #424

Closed
lumtis opened this issue Nov 6, 2024 · 1 comment
Closed

Enforce gas use limit for omnichain call hooks #424

lumtis opened this issue Nov 6, 2024 · 1 comment
Assignees

Comments

@lumtis
Copy link
Member

lumtis commented Nov 6, 2024

Related: zeta-chain/node#3084

A limit for the gas usage must be set. We set a gas limit value in the call in zeta-chain/node#3106 however this requires the next chain upgrade to fix the issue

This issue is about setting a temporary workaround at the smart contract level and upgrade the GatewayZEVM

Since no gas limit is not manually set currently, the gas limit is set with the estimated call function.

We can therefore revert automatically when the "gasleft" value is above a certain threshold
https://www.rareskills.io/post/solidity-gasleft

Example: if the developer onCall is too expensive, gasleft will be set to a high value because of the gas estimated.

Example:

function execute(
        MessageContext calldata context,
        address zrc20,
        uint256 amount,
        address target,
        bytes calldata message
    )
        external
        nonReentrant
        onlyFungible
        whenNotPaused
    {
        if (zrc20 == address(0) || target == address(0)) revert ZeroAddress();

        require(gasleft() < 1000000)

        UniversalContract(target).onCall(context, zrc20, amount, message);
    }
@lumtis lumtis self-assigned this Nov 15, 2024
@lumtis
Copy link
Member Author

lumtis commented Nov 18, 2024

After experimentation this solution can't be used: it rely on using gasleft() to prevent tx with high estimated gas limit. The problem is that the check will be run when estimating the gas limit, it will create discrepancies given that gasleft() will return a different value when tx is simulated. This makes the solution unreliable because the tx simulation is different than the tx execution.

@lumtis lumtis closed this as completed Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant