pimlicolabs/alto

[Help] Unable to estimateUserOperationGas

Troublor opened this issue · 1 comments

Hi, very appreciate this great work.
However, I am trying to use alto on a local testnet and could not make estimateUserOperation json-rpc work. The error message is: Cannot decode zero data ("0x") with ABI parameters..

I investigated the code of alto and found that alto seems to call callExecute function in EntryPoint address during simulateHandleOp:

const targetCallData = encodeFunctionData({
abi: ExecuteSimulatorAbi,
functionName: "callExecute",
args: [userOperation.sender, userOperation.callData, 2_000_000n]
})
userOperation.callGasLimit = 0n
const error = await simulateHandleOp(userOperation, entryPoint, publicClient, true, entryPoint, targetCallData)

I don't think there is a function called callExecute in the entrypoint. Then I notice there is a special parameter in the RPC parameters called finalParam, which seems to instruct the RPC backend to replace the bytecode of entrypoint to a given ExecuteSimulator code.

const finalParam = replacedEntryPoint
? {
[userOperation.sender]: {
balance: toHex(100000_000000000000000000n)
},
[entryPoint]: {
code: ExecuteSimulatorDeployedBytecode
}
}
: {
[userOperation.sender]: {
balance: toHex(100000_000000000000000000n)
}
}
try {
await publicClient.request({
method: "eth_call",
params: [
// @ts-ignore
{
to: entryPoint,
data: encodeFunctionData({
abi: EntryPointAbi,
functionName: "simulateHandleOp",
args: [userOperation, targetAddress, targetCallData]
}),
gas: toHex(20_000_000)
},
// @ts-ignore
"latest",
// @ts-ignore
finalParam
]
})
} catch (e) {

Is this contract bytecode replacement feature in the Ethereum JSON-RPC standard? Or are you using a customized Ethereum node to handle such RPCs? How can I make this work on a local testnet (e.g., anvil)?

bytecode replacement is part of the Ethereum JSON-RPC spec (using StateOverrides). However not all rpc providers allow state overrides.

Anvil does support code overrides but if your rpc doesn't then you can run alto with the --noEthCallOverrideSupport flag