Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Call Data and Deserialization Gas Cost

Brecht Devos edited this page Sep 19, 2018 · 3 revisions

Call Data and Deserialization Gas Cost

At the moment of writing, the deserialization gas cost test uses about 81,000 gas. Let's examine why the cost is so high.

Transaction cost

The fixed cost for every transaction is 21,000. So the actual cost is about 60,000 gas.

Call data cost

From the yellow paper:

  • 4 gas is paid for every zero byte of data or code for a transaction
  • 68 gas is paid for every non-zero byte of data or code for a transaction

With this we can easily calculate how much the data costs to send. For the test case we calculate 43,172 gas.

Let's calculate the cost of some common things we need to send:

  • A signature (v, r, s): (32+32+1)*68 = 4420 gas
  • An address: 20*68 = 1360 gas
  • Numbers in a uint256: in general, these will contain a lot of zeros. Let's say on average 6 non-zero bytes: 6 * 68 + 26 * 4 = 512 gas

Signatures

For the 2 order test case we have to send 5 signatures:

  • Every order has a signature AND a dual author signature
  • The miner has a signature of all ring data

-> Total cost signatures: (2*2 + 1) * 4420 = 22,100 gas

Addresses

Every order in the test needs 4 addresses

  • Owner
  • TokenS
  • Dual author address
  • Wallet

LRC is used to pay fees so we don't need to store the feeToken

We also send the miner and feeRecipient (these are not the same in the test, and do not equal tx.origin)

-> Total cost addresses: (2*4 + 2) * 1360 = 13,600 gas

Numbers

Every order contains some uint256 numbers

  • amountS
  • amountB
  • feeAmount
  • validSince (can be reduced to a uint64)

-> Total cost: (4 * 2) * 512 = 4,000 gas

Misc data

There's also the feePercentage, spendables indices, specs, ... which in total has a cost of ~2,000 gas

Deserialization

Using the above, the actual deserialization currently consumes 60,000 - 43,000 = 17,000 gas in the test case. This can definitely still be improved a bit.