Why can't smart contracts access events

Looking through posts here most refer to the doc saying that smart contracts can't access event data.

The Log and its event data is not accessible from within contracts (not even from the contract that created them).

But I didn't find a mention to why is that,if it's cheaper to store data in event logs why aren't contracts able to read it,is it a choice made by the developers or is there something that I missed about events which makes them unusable for smart contracts,I think being able to interact with event logs, even if it's read only, would be pretty useful.

Answers 3

  • This is second-hand information and speculation. I tried to reach out to people who did the original event.

    • Logs were intended to be used as a proof for third party systems that something happened in a blockchain. Now logs are used by bridges between different blockchains for this purpose.

    • Logs were intended to be purgeable i.e. full nodes have logged only for X years - this is why the gas cost is lower.

    • Logs are indexed so they are easy to search on the client-side (e.g. all transactions to this address). However, such queries would be too expensive in smart contracts.

    • Because logs may or may not be there, they cannot be accessed from the state that needs to be deterministic

    Note that some other blockchains do not have the log concept on the full node level. For EOS, you need to have a third-party application to index the blockchain events to have useful output from it for applications like explorers, dashboards and such.

    For example, free CloudFlare Ethereum node stores events only worth of 128 blocks.


  • But I didn't find a mention to why is that,

    because first: you don't need that in a contract, and event is a message from the inside to the outside, why would a contract need to access events of other contracts? Only for some weird use case. Second, you would spend a lot of Gas and your transaction wouldn't fit inside a block.

    if it's cheaper to store data in event logs why aren't contracts able to read it,

    they way to stored data is by SSTORE instruction. Please use the system as it was conceptually designed.

    that I missed about events which makes them unusable for smart contracts,

    contracts don't need to read events

    read only, would be pretty useful.

    not useful at all, the universe of a contract is too small to handle the information of the entire blockchain


  • Events use one of the LOG operations. The output of LOG operations is not accessible from smart contracts by design - it allows clients to avoid storing event/log data as an optimization and as a result the LOG operation has a low gas cost reflecting the reduced hardware cost. In other words, SSTORE is expensive because it provides a guarantee that smart contracts can access the data later on, LOG is cheap because the client can "forget" about the data after it has processed the event.


Related Questions