I have an ERC-20 token contract on which I want to perform some testing on a local chain. I got my chain setup, contract deployment and testing scripts ready on my Windows machine. However, since I wanted to test with multiple miners which is not possible on my laptop, I decided to create the same setup on a docker image and run it on a more powerful server that I have access to. For some reason, with the same contract code, transfer transactions which used to take 34 000 gas on my windows setup, now take 6 700 000 gas per transfer on my docker. This kind of screws my tests which include sending many transactions, as now only 1 transaction is added per block (I have set the block limit to 10 000 000). I am very confused as of how can the same transaction take more than 100 times the gas it used to take?
While there are a few sources of normal variance:
- Different EVM versions have different OPCODE pricing
- Conditional branching in contracts, including ERC20, can lead to a range of possible transaction costs
There is no good reason for a valid transaction to shoot up many orders of magnitude. Unless it is a very strange token contract, there would be no iteration that would explain such a burn if everything is working.
It is possible the transaction is failing by consuming all gas. That gas consumption is in the range of a reasonable block gasLimit.
I would concentrate on your testing methodology. Start by confirming the costly transaction actually succeeded. Does the sending account have tokens to send on the test blockchain? Did the receiver get them?
You should also check and confirm the EVM version you are running in the containers. Make sure it is compatible and not too old for your bytecode because differences can cause that sort of behaviour.
Hope it helps.