With the following simple trick we can significantly lower the gas needed per transaction.
- We sort the transactions is such a way that similar transactions follow each other.
- We send the byte-for-byte difference compared to the previous transaction.
This will result in a lot of zeros when the transactions are very similar, saving a lot of gas (zero bytes are only 4 gas instead of 68)
Note that most transactions are independent of each other, so with thousands of transactions per block, the relayer has a lot of freedom to minimize gas costs.
Extra parameter tricks:
from: Keeping the addresses sorted on the total number of send/received transactions will make sure the most used addresses are more similar. This will probably add too much complexity.
Maybe it is more feasible to just keep a smaller list of most used addresses during the last day/week.
to: Reserving a few addresses in the address space for the most used addresses will make transactions using the address book more similar.
amount: It is more likely that the amounts are in rounded decimal format (1 Eth, 0.5 Eth, 3.2 Eth, etc). Having the amount in 2-base will shuffle the lower bits if you add a round decimal to it. Using a decimal(10-base) mantissa will keep the rounded decimal numbers more similar. I think using 3 bytes including a 3 bit mantissa will do the trick.
Sending the total amount (minus fee) in the account should also be a fixed code.
fee: Fixed code for last used fee.