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

fix(evm): allow estimateGas with no funds #2885

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ func TestLoopWithGasLeft(t *testing.T) {
require.Greater(t, usedGas[1], usedGas[0])
}

func TestEstimateGasWithoutFunds(t *testing.T) {
env := initEVM(t)
ethKey, _ := env.soloChain.NewEthereumAccountWithL2Funds()
iscTest := env.deployISCTestContract(ethKey)

callData, err := iscTest.abi.Pack("loopWithGasLeft")
require.NoError(t, err)
estimatedGas, err := env.evmChain.EstimateGas(ethereum.CallMsg{
From: common.Address{},
To: &iscTest.address,
Data: callData,
}, nil)
require.NoError(t, err)
require.NotZero(t, estimatedGas)
t.Log(estimatedGas)
}

func TestLoopWithGasLeftEstimateGas(t *testing.T) {
env := initEVM(t)
ethKey, ethAddr := env.soloChain.NewEthereumAccountWithL2Funds()
Expand Down
4 changes: 4 additions & 0 deletions packages/vm/vmimpl/runreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ func (reqctx *requestContext) calculateAffordableGasBudget() (budget, maxTokensT
gasBudget = reqctx.vm.chainInfo.GasLimits.MinGasPerRequest
}

if reqctx.vm.task.EstimateGasMode {
return gasBudget, math.MaxUint64
}
Comment on lines +330 to +332
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this result in "false positive" estimations?

basically in situations where the estimation would result in insufficient funds for gas * price + value

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, certainly. I don't think there is a solution that fits every use case. I'd imagine that it should be possible to estimate the gas before actually depositing the funds, but we should probably adopt the same behavior than other networks.

cc @fijter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's 'wrong' we should do the same thing other networks are doing here yeah :)


// calculate how many tokens for gas fee can be guaranteed after taking into account the allowance
guaranteedFeeTokens := reqctx.calcGuaranteedFeeTokens()
// calculate how many tokens maximum will be charged taking into account the budget
Expand Down