tevm-monorepo
tevm-monorepo copied to clipboard
CallResult will sometimes return different gas used and refunded whether createTransaction is true or false
Description
With some calls, depending on whether Tevm.contract:createTransaction
is set to true
or false
, the returned CallResult.executionGasUsed
and CallResult.gasRefund
will be different.
Take this example using two instances of the same token:
// Mint some of each tokens and approve the airdrop contract for spending them
await mintAndApproveBoth(tevm);
// Airdrop tokens
const gasData = await airdropBoth(tevm);
...
// ? LOGS:
// ┌─────────┬─────────┬───────────┐
// │ (index) │ gasUsed │ gasRefund │
// ├─────────┼─────────┼───────────┤
// │ false │ 63218 │ 29500 │
// │ true │ 51118 │ 59700 │
// │ diff │ -12100 │ 30200 │
// └─────────┴─────────┴───────────┘
// ? 'airdropERC20' with createTransaction: true used 12,100 less gas
// ? and refunded 30,200 more gas than with createTransaction: false
In this example, while there is no difference in gas for regular mint
and approve
ERC20 interactions, calling airdropERC20
on a custom airdrop contract will not return the same gas data whether the transaction is executed in a sandbox environment or in the same context as the previous ones.
Regardless of the parameters (lengths and values of the recipients/amounts), this will always return the same 12,100
decrease in gas used and 30,200
increase in gas refunded with createTransaction: true
.
As a side note, compared to a testnet transaction, the amount of gas used during execution seems more realistic with createTransaction: false
.
Version
There has been a lot of churn in Tevm. This might have been accidentally fixed but hasn't been verified yet