18

I'm thinking of storing some data in logs by emitting events but I cannot easily find the answers to the following questions:

  1. What is the total size limit of one event?
  2. Can I store lots of string32 in event log data and what encoding is used for them?
  3. How much would it cost?

The flow would be: send transaction to a contract with a string included -> contract does its job -> contract emits an event with job results + the passed string.

General advices on this idea are also welcome.

2 Answers 2

24

Most of the answers for what's possible are in the Yellow Paper. From Equation 20, page 5:

A log entry, O, is a tuple of a logger’s address, Oa , a series of 32-bytes log topics, Ot, and some number of bytes of data, Od

  1. There is no size limit to the data: you will be limited by how much Ether you have. (And of course the block gas limit.)
  2. If using Solidity, it appears you can only log a single bytes32 data. But the Yellow Paper above is clear that there is no limit to the number of bytes for log data. Solidity does allow up to 4 topics (the maximum supported by the EVM).
  3. Appendix G is a table of all gas costs, and here are the prices related to LOGs. 375 gas for a LOG operation. 375 gas for each topic. 8 gas for each byte of a LOG operation's data.
2
  • 5
    I've created a test contract - pastebin.com/ijbey3X5, deployed it (0x847b87bb729f6cc7d50b0f245c2e243c708f3540) and tried. I've been able to log 200 UTF symbols without any problem. I've paid 27268 gas for empty string and 53089 gas for 200 UTF symbols, but the dependence is not linear.
    – Aldekein
    Commented Mar 2, 2016 at 21:44
  • 1
    @Aldekein 53089/200 = 265 gas per byte. 10x more than I expected. Very odd, but that's your contract there being mined...
    – Paul S
    Commented Jul 31, 2017 at 22:52
9

The size limit of one event is a function of the block's gas limit, which as of now tends to be around 3,145,192 (i.e., the first seven digits of pi). According to Jonathan Patrick, logging costs 76 gas per byte. So I'd assume you could get in around 41kb per log event.

Your Answer

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

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