How do I calculate IPaymaster.GasAndDataLimits for my paymaster (v2.x.x)?


It seems that the actual relayCall transaction requires much more gas to be specified in IPaymaster.GasAndDataLimits than is actually used by my custom paymaster contract.

It’s unclear for me where this extra amount comes from and how do I calculate it correctly so that I could take it into account. I’ve read the IPaymaster.sol comments multiple times and made multiple tests to see if numbers add up. They don’t add up. I always end up getting at least 100k (or more) of extra gas used in gasUseWithoutPost at postRelayedCall callback than initially anticipated at maxPossibleGas of preRelayedCall callback.

Correct me if I’m wrong.

preRelayedCallGasLimit and postRelayedCallGasLimit are the gas limit for preRelayedCall function call and the gas limit for postRelayedCall correspondingly. Pretty self explanatory.

acceptanceBudget is the sum of preRelayedCallGasLimit and some overhead value which includes forwarder overhead, signature and Relay Hub overhead.

calldataSizeLimit is also pretty self explanatory. will be taken into account during total gas limit calculation and cannot exceed calldataSizeLimit value.

It seems that the only way to make the relayCall transaction to succeed is to make postRelayedCallGasLimit value much bigger than actually needed for postRelayedCall callback. In my case 20k is more than enough for the actual postRelayedCall function call, but I need to set this value to at least 125k so that the actual relayCall would not fail. But I can’t be sure that 125k will always be enough as I don’t understand how to calculate the actual overhead for every possible blockchain transaction.

Where does this magic overhead come from? And, more importantly, how can I take it into account in my paymaster?

1 Like