2

This question is about Low-Level Interface to Logs, Solidity Documentation.

In given examples we are able to emit event normally:

pragma solidity ^0.4.0;

contract ClientReceipt {
    event Deposit(
        address indexed _from,
        bytes32 indexed _id,
        uint _value
    );

    function deposit(bytes32 _id) public payable {
        // Events are emitted using `emit`, followed by
        // the name of the event and the arguments
        // (if any) in parentheses. Any such invocation
        // (even deeply nested) can be detected from
        // the JavaScript API by filtering for `Deposit`.
        emit Deposit(msg.sender, _id, msg.value);
    }
}

Or on a low-level:

pragma solidity ^0.4.10;

contract C {
    function f() public payable {
        bytes32 _id = 0x420042;
        log3(
            bytes32(msg.value),
            bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20),
            bytes32(msg.sender),
            _id
        );
    }
}

After the example there is this note:

where the long hexadecimal number is equal to keccak256("Deposit(address,hash256,uint256)"), the signature of the event.


Questions:
1) What is hash256?
2) Why not bytes32?
3) hash256 == bytes32?

2

Update: This was an error in documentation and it was fixed with #3814 pull request.


I tried this algorithm in remix and it turnes out that the given note is misleading (at least for me).

Working example is bytes32(keccak256("Deposit(address,bytes32,uint256)")).

So, answering question: hash256 == bytes32 is theoretically true, but hash256 != bytes32 when you need to pass it as argument to keccak256 function (yes, quite trivially, frankly speaking).


Working example:

pragma solidity ^0.4.21;

contract Demo {
    event Deposit(
        address indexed _from,
        bytes32 indexed _id,
        uint256 _value
    );

    function highLevelEvent() public {
        bytes32 _id = 0x420042;
        emit Deposit(msg.sender, _id, 123);
    }

    function lowLevelEvent() public {
        bytes32 _id = 0x420042;
        log3(
            bytes32(123),
            bytes32(keccak256("Deposit(address,bytes32,uint256)")),
            bytes32(msg.sender),
            _id
        );
    }
}
  • 1
    It seems an error in the documentation please report it to developers so they can fix it. – Ismael Apr 4 '18 at 4:15
  • 1
    @Ismael done. Issue on github and pull request created. – Roman Frolov Apr 4 '18 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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