go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

DoEstimateGas doesn't allow precompile override

Open nthpool opened this issue 7 months ago • 5 comments

System information

Geth version: latest CL client & version: N/A OS & Version: OSX Commit hash : (if develop)

Expected behaviour

eth_estimateGas should allow precompile overrides like debug_traceCall, eth_call, etc.

Actual behaviour

DoEstimateGas passes nil to overrides.Apply(state, nil); causing the error: account 0x0000000000000000000000000000000000000001 is not a precompile.

Steps to reproduce the behaviour

  1. attempt to override precompile:
{
	"jsonrpc":"2.0",
	"method":"eth_estimateGas",
	"params":[
    {
      "to": "0x4dbf9b62225c559a17c4d2ba966744f4634acee6",
      "from": "0x90d35fcd4c95afb1b93fa718efea95105a7eca91",
      "value": "0xab"
    },
    "latest",
    {
    "0x0000000000000000000000000000000000000001": {
      "code": "0x6080604052348015600e575f5ffd5b5061010f8061001c5f395ff3fe608060405260805f369050146047576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401603e9060bd565b60405180910390fd5b5f736e3242985e750d586d10987801e013214fc7b9a69050805f5260205ff35b5f82825260208201905092915050565b7f496e76616c696420696e707574206c656e6774680000000000000000000000005f82015250565b5f60a96014836067565b915060b2826077565b602082019050919050565b5f6020820190508181035f83015260d281609f565b905091905056fea26469706673582212206a69480728ed903c9dd012e3dedfa3475e2559a4d64e1518e1be9afcba3398be64736f6c634300081d0033",
      "movePrecompileToAddress": "0x0000000000000000000000000000000010000001"
    },
    "0x90d35fcd4c95afb1b93fa718efea95105a7eca91": {
      "balance": "0x43c33b3b2ab97a2ac7a00",
      "movePrecompileToAddress": null
    }
  }
  ],
	"id":"1"
}
  1. observe error response:
{
    "jsonrpc": "2.0",
    "id": "1",
    "error": {
        "code": -32000,
        "message": "account 0x0000000000000000000000000000000000000001 is not a precompile"
    }
}

Backtrace

[backtrace]

When submitting logs: please submit them as text and not screenshots.

nthpool avatar Apr 25 '25 19:04 nthpool

Right but the gas estimate will be off if this tx is ever to be submitted to the network. Maybe it helps if you mention what it is you're trying to do.

s1na avatar Apr 28 '25 13:04 s1na

ah, good point. i need to estimate a contract call that verifies an EIP-712 signed message from an end user, but without a valid signature. i'm trying to override ecrecover with some test code that allows me to specify the returned address. the gas discrepancy isn't a big deal for me in this case since i believe it will be constant.

nthpool avatar Apr 28 '25 13:04 nthpool

Right maybe so for your use case but I can imagine other users will be bitten by this. I'd rather raise an error if this field is set for estimateGas.

If the code you execute is known in advance and it doesn't use GAS opcode in tricky ways can't you get the gasUsed + 10% value of an eth_simulateV1 run as the estimated gas?

s1na avatar Apr 28 '25 14:04 s1na

If the code you execute is known in advance and it doesn't use GAS opcode in tricky ways can't you get the gasUsed + 10% value of an eth_simulateV1 run as the estimated gas?

the signed message may include a batch of execution calls from an end user, so unfortunately it's not always known ahead of time.

Right maybe so for your use case but I can imagine other users will be bitten by this. I'd rather raise an error if this field is set for estimateGas.

isn't this true for overrides generally? i.e. overriding the state may alter the execution in ways that affects the estimate. i'd assume if a caller is overriding precompiles they are aware of this.

nthpool avatar Apr 28 '25 15:04 nthpool

Ok I stand corrected. Maybe it can be useful. Accepting PRs.

s1na avatar May 02 '25 10:05 s1na