5

I have been playing around with parity's "eth_estimateGas" call to determine different tokens gas requirements. Generally using this code:

 let transfer_data = contract.transfer.getData("<destinaton ETH address>", 1);
    let gas_limit = await rpcCall("eth_estimateGas",[{
        to: contractData.contractAddress,
        from: "<source ETH address>",
        data:transfer_data
    }]);

I'm getting different results based on the from address. If that address has done thousands of transactions (like exchange's) the amount of gas used is significantly higher then an address thats only done 10's of transactions. Nothing else modified beside the from address.

My only theory is if the nonce is quite high, the contract or evm has to do more verification that it does in fact have the correct balance to complete the send.

What am I missing?

EDIT: Here's an example data. Token: FunFair

From address has high nonce Contract Address: 0x419d0d8bdd9af5e606ae2232ed285aff190e711b From Address: 0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98 To Adress: 0x6d8401b8ed8755bb4d01a89072860c98c236dc78 https://etherscan.io/tx/0xc407d8320f44745f88244400c3750875e1858e0ee6a1106bafbde424c289a6ef Gas Used: 58999

From address has low nonce Contract Address: 0x419d0d8bdd9af5e606ae2232ed285aff190e711b From Address: 0x8c301c986e6d23117f17394722272fcd16d43efd To Adress: 0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be https://etherscan.io/tx/0x708fb93a22f4ddd3d410f7280fb3800c8ff96deed5d4fafa12244d0f74e48045 Gas Used: 29127

Plugging those values into the parity call, the estimate results have roughly the same variance.

2
  • To debug this without just guessing, we'd need to see the contract address, the destination address, and the from addresses you're comparing. The number of transactions previously made by the account have no direct impact.
    – user19510
    Feb 27, 2018 at 18:14
  • thanks @smarx, I updated the question with a specific example. Feb 27, 2018 at 18:34

1 Answer 1

5

I'm too lazy to 100% confirm, but I'm pretty sure that in the example you gave, the key difference is that the cheaper transaction was for the full token balance of the sender. This means they ended up with a balance of zero. Setting a value in storage from a non-zero value to a zero value gives you a gas refund, lowering the cost of the transaction. (This incentivizes cleaning up storage.)

2
  • Interesting! I'm going to dig into that a bit more.. if that is indeed whats happening i'll mark as solved! Feb 27, 2018 at 20:50
  • 2
    There are two thing happening. As pointed by smarx, in the cheaper transaction the sender transfer all of its tokens (15k refund), and the receiver already has a non-zero balance. In the more expensive the sender doesn't send full balance and the recipient has zero tokens previously and has to pay for a new slot storage (around 20k). The first uses +15k gas than a 'normal' transfer, and the second has -15k gas refund, the total is close to the difference 30k between both calls.
    – Ismael
    Feb 28, 2018 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.