Logs and Events

  • First topic in event logs will be the keccak256 of the event signature

  • Solidity vs. Yul version of event emissions:

event SomeLog(uint256 indexed a, uint256 indexed b);

function emitLog() external {
        emit SomeLog(5, 6);
    }

function yulEmitLog() external {
        assembly {
            // keccak256("SomeLog(uint256,uint256)")
            let
                signature
            := 0xc200138117cf199dd335a2c6079a6e1be01e6592b6a76d4b5fc31b169df819cc
            log3(0, 0, signature, 5, 6)
        }
    }
  • If we have non-indexed variables, we have to explicitly store them in memory, then input the location in memory in the log2 command

event SomeLogV2(uint256 indexed a, bool);

function v2YulEmitLog() external {
       assembly {
            // keccak256("SomeLogV2(uint256,bool)")
            let
                signature
            := 0x113cea0e4d6903d772af04edb841b17a164bff0f0d88609aedd1c4ac9b0c15c2
            mstore(0x00, 1) // load 1 (true) into the first 32 byte slot in memory 
            log2(0, 0x20, signature, 5) // add reference 0x20 in log statement 
        }

Last updated