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

Questions about SEP102: Adjustment of Used Gas #42

Closed
llwslc opened this issue Jan 29, 2022 · 15 comments
Closed

Questions about SEP102: Adjustment of Used Gas #42

llwslc opened this issue Jan 29, 2022 · 15 comments

Comments

@llwslc
Copy link

llwslc commented Jan 29, 2022

gas_used = gas_limit - gas_remained
if gas_used * 4 < gas_limit then /*the estimated gas consumption is more than four times of real gas consumption*/
    gas_used = gas_limit /* no gas fee will be returned*/
else if gas_used * 2 < gas_limit then /*the estimated gas consumption is more than two times of real gas consumption*/
    gas_used = (gas_used + gas_limit) / 2
else then /*the estimated gas consumption is no larger than two times of real gas consumption*/
    /* return the gas fee just as ethereum*/
endif
returned_gas_fee = (gas_limit - gas_used) * gas_price

This penalty can be bypassed with a small piece of code, which doesn't really make much sense. And hope to improve the accuracy of the estimated gas.

uint gasLimit = gasleft() + 21200;
...
while (true) {
    if ((gasleft() * 100) / gasLimit < 50) break;
}
@wangkui0508
Copy link
Contributor

I can not fully understand your pseudo code. Can you elaborate on it?
Can you show us a demo whose gas is badly estimated? We need test cases.

@llwslc
Copy link
Author

llwslc commented Feb 8, 2022

https://www.smartscan.cash/block/2989379

I think this is more typical.

@llwslc
Copy link
Author

llwslc commented Feb 8, 2022

We had to add the following code to ensure that gas was sufficient.

const gasLimit = await contract.estimateGas.func();
const tx = await contract.func({ gasLimit: gasLimit.toNumber() * 1.2 });

@llwslc
Copy link
Author

llwslc commented Feb 8, 2022

I think smartBCH is not able to correctly estimate the gas of this function.

// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.8.0;

contract testGas {
    function ignorePenalties() external   {
        uint gasLimit = gasleft() + 21200;
        while (true) {
            if ((gasleft() * 100) / gasLimit < 50) break;
        }
    }
}

@llwslc
Copy link
Author

llwslc commented Feb 8, 2022

Some txs sent to your email, it is sent by protonmail. Maybe in the trash mail.

@wangkui0508
Copy link
Contributor

Got the mail. We'll study it.

@llwslc llwslc closed this as completed Feb 18, 2022
@llwslc
Copy link
Author

llwslc commented Feb 20, 2022

https://www.smartscan.cash/block/3183469 Is this block normal?

@llwslc
Copy link
Author

llwslc commented Feb 20, 2022

This low-level bug, made me execute 61 reverted transactions today, until I manually raised the gaslimit. What a bad day!

@llwslc llwslc reopened this Feb 20, 2022
@wangkui0508
Copy link
Contributor

Please make your question more specific. Why is this block abnormal?
SEP102 is not meant to make arbitrage easy and gas-efficient. We do not view it as a bug.

@llwslc
Copy link
Author

llwslc commented Feb 21, 2022

Is it normal for too many transactions to fail because of insufficient gas? Now, let's say the gas estimate is 100, if you set it to 100, it may fail due to out of gas, if you set it to 120, it will execute successfully, and only consume 80.

@wangkui0508
Copy link
Contributor

Well, if normal DApp's users have such a problem, we'd better figure out a way to optimize it. If only arbitrage transactions suffer from this, then it is not the first priority to optimize it. For arbitrage, fairness is more important than gas efficiency. If you have such a problem, other arbitragers have it too. So it is fair.

@llwslc
Copy link
Author

llwslc commented Feb 21, 2022

I see, the goal of SmartBCH is that the normal dApp user can execute one or two simple transactions without problems. If some complex transactions go wrong, it doesn't really matter. Because all other complex contracts are also not executed correctly.

SmartBCH does not promise that complex contracts will be executed correctly, please write some simple contracts.

If everyone has a problem, it's not a problem, it's fair. That's a good point. Stay hungry, stay foolish, and everyone will feel fair.

There really shouldn't be any quality requirements for personal projects. Anyway, good job!

@llwslc llwslc closed this as completed Feb 21, 2022
@wangkui0508
Copy link
Contributor

Now complex contracts are executing correctly on smartBCH. They work just as the specifications, including SEP102. Sorry, we cannot take your words as the specification.
Feel free to reopen this issue when you find some real bugs. And hope your arbitrage goes smoothly in the future.

@llwslc
Copy link
Author

llwslc commented Feb 21, 2022

Thanks, classifying one transaction as a normal dApp transaction or an arbitrage transaction to determine if there is a bug is the most interesting thing I learned about EVM.

@yougotwill
Copy link

We had to add the following code to ensure that gas was sufficient.

const gasLimit = await contract.estimateGas.func();
const tx = await contract.func({ gasLimit: gasLimit.toNumber() * 1.2 });

Thank you for this information. I was having the same problem.

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

3 participants