Skip to content

Commit

Permalink
Merge pull request #254 from defi-wonderland/feat/execute-message-hash
Browse files Browse the repository at this point in the history
Adding messageHash to ExecutingMessage
  • Loading branch information
tynes authored Aug 1, 2024
2 parents 91daec6 + 9a43170 commit 7722954
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions specs/interop/predeploys.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,20 @@ The `ExecutingMessage` event represents an executing message. It MUST be emitted
to `executeMessage`.

```solidity
event ExecutingMessage(bytes,bytes);
event ExecutingMessage(bytes32 indexed msgHash, Identifier identifier);
```

The data encoded in the event contains the `Identifier` and the `msg`.
The data encoded in the event contains the keccak hash of the `msg` and the `Identifier`.
The following pseudocode shows the deserialization:

```solidity
(bytes memory identifier, bytes memory log) = abi.decode(log.data, (bytes, bytes));
Identifier id = abi.decode(identifier, (Identifier));
bytes32 msgHash = log.topics[1];
Identifier identifier = abi.decode(log.data, (Identifier));
```

It is not possible to use solidity structs directly in events, which is why it is ABI encoded
into `bytes` first.
Emitting the hash of the message is more efficient than emitting the
message in its entirety. Equality with the initiating message can be handled off-chain through
hash comparison.

### Reference implementation

Expand All @@ -133,7 +134,7 @@ function executeMessage(Identifier calldata _id, address _target, bytes calldata
require(success);
emit ExecutingMessage(abi.encode(_id), _msg);
emit ExecutingMessage(keccak256(_msg), _id);
}
```

Expand Down
5 changes: 3 additions & 2 deletions specs/interop/sequencer.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ if not success:

for log in receipt.logs:
if is_executing_message(log):
id, message = abi.decode(log.data)
id = abi.decode(log.data)
messageHash = log.topics[1]

# assumes there is a client for each chain in the dependency set
eth = clients[id.chainid]
Expand All @@ -116,7 +117,7 @@ for log in receipt.logs:
if len(log) == 0:
return False

if message != encode(log[0]):
if messageHash != hash(encode(log[0])):
return False

block = eth.getBlockByNumber(id.blocknumber)
Expand Down

0 comments on commit 7722954

Please sign in to comment.