# Estimate Gas ## Pimlico 1. What we are most concerned about is transactions don't fail due to lack of gas. Forcing users to set gas limit a bit high and getting a bigger gas refund than expected is not too big of a deal. 7. This shit is hard since a different state variable can cause a contract to go down a different code path, making transaction costs wildly different. One solution to this problem is to simulate across many blocks, not just the most recent block. 2. There's a `eth_estimateUserOperationGas` that in theory should solve this issue for us. However, if this is not a supported endpoint for the rpc provider and chain we are using, then this will be a big problem. Pimlico needs to support every chain we support for us to be able to use them as a bundler 3. Gas is three parts: - preVerificationGas: The amount of gas to pay for to compensate the bundler for pre-verification execution and calldata - verificationGas: The amount of gas to allocate for the verification step - callGasLimit: Simplest, can just get from simulating the transaction and returning how much it costs, similar to estimateGas ## User story Create an accurate estimate gas function. We don't care about the gas price, we just want to set the gas limit barely high enough to get the transaction to succeed ## Problems Sometimes gas estimation fails on the first check Gas estimation issue: Gas estimation fails on polygon. Current solution is to manually bump up the contract gas limit if the transaction is on polygon Sometimes gas estimation fails on arbitrum The likely problems to this solution(unless we want to do our own rewrite), is to get a list of all all bundlers for every network and test with them to get the best for each network. Sometimes when we get bad results, this is just because we have an incorrect combination of bundler JsonRpcProvider URL, chain Id, userOp, and entrypoint address ## Solutions 1. Get list of all bundlers - Alchemy Rust Bundler - Eth Infinitism Bundler - Voltaire Bundler - Stackup Bundler - Rust Bundler(AA-bundler) 2. We are currently using the pimlico bundler ## Questions ## Security - Worst case, we can make customers overspend on a reverted transaction