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

debug_traceCall returning inaccurate gasUsed when both blockOverrides and stateOverrides are used #29996

Open
Bitwise0x opened this issue Jun 14, 2024 · 4 comments

Comments

@Bitwise0x
Copy link

Bitwise0x commented Jun 14, 2024

System information
Geth 1.14.5
Go Version: go1.22.4

The gas returned from debug_traceCall with stateOverrides often resulting inaccuracy when trying to simulate for the next block. Over estimating in all the cases. Am I missing something?

``` ` // Adding 12 seconds to the current timestamp
nextBlockTime = header.Time + 12
tx := request{To: transaction.To().Hex(), From: from.Hex(), Value: fmt.Sprintf("0x%x", transaction.Value()), Gas: fmt.Sprintf("0x%x", transaction.Gas()), GasPrice: "0x" + transaction.GasFeeCap().Text(16),Data: hexutil.Encode(transaction.Data())}
	params := make(map[string]interface{})
	params[]"tracer"] = "callTracer"
	params["tracerConfig"] = tracerConfig{OnlyTopCall: true}
        params["blockOverrides"] = make(map[string]interface{})
	params["blockOverrides"].(map[string]interface{})["number"] = "0x" + nextBlock.Text(16)
	params["blockOverrides"].(map[string]interface{})["time"] = fmt.Sprintf("0x%x", nextBlockTime)
	if overrides != nil {
		params["stateOverrides"] = make(map[string]interface{})
		switch stateoverride := params["stateOverrides"].(type) {
		case map[string]interface{}:
			for key, value := range overrides {
				stateoveride[key] = make(map[string]interface{})
				switch statediff := stateoveride[key].(type) {
				case map[string]interface{}:
					statediff["stateDiff"] = make(map[string]string)
					statediff["stateDiff"] = value
				}
			}
		}
	}
gClient.Call(&result, "debug_traceCall", tx, "latest", params)``
@Bitwise0x
Copy link
Author

@Bitwise0x Bitwise0x changed the title debug_traceCall returning inaccurate gasUsed debug_traceCall returning inaccurate gasUsed when both blockOverrides and stateOverrides are used Jun 16, 2024
@s1na
Copy link
Contributor

s1na commented Jun 17, 2024

The gas returned is how much gas was used during the simulation. It is not necessarily a good estimate for submitting the tx. For that you should rather use eth_estimateGas.

Otherwise if it is inaccurate it helps if you demonstrate what you expect and what is returned.

@Bitwise0x
Copy link
Author

@s1na
Why is debug_traceCall not accurate when both stateOverrides and blockOverrides are used within the same call? I am trying to simulate my transaction beneath another transaction, and was expecting an accurate gasUsed.

debug_traceCall with just blockOverrides works perfectly. however, when combined with stateOverrides, it overestimates gas usage by approximately 5-15k.

@s1na
Copy link
Contributor

s1na commented Jun 23, 2024

@Bitwise0x This is a difficult question to answer. You are modifying the state, that can change the flow of execution and require a different amount of gas. When submitting on chain the state might not be the same as in your override though.

Ideally you give me something to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants