From c8bbe166ef4c38f346fa6c84a34f5bfc55a23bd4 Mon Sep 17 00:00:00 2001 From: 0xng Date: Fri, 21 Jun 2024 13:02:27 -0300 Subject: [PATCH 1/4] feat: message hash change --- specs/interop/predeploys.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/specs/interop/predeploys.md b/specs/interop/predeploys.md index 9a158c738..33fe652db 100644 --- a/specs/interop/predeploys.md +++ b/specs/interop/predeploys.md @@ -94,19 +94,21 @@ The `ExecutingMessage` event represents an executing message. It MUST be emitted to `executeMessage`. ```solidity -event ExecutingMessage(bytes,bytes); +event ExecutingMessage(bytes,bytes32); ``` -The data encoded in the event contains the `Identifier` and the `msg`. +The data encoded in the event contains the `Identifier` and the keccak hash of the `msg`. The following pseudocode shows the deserialization: ```solidity -(bytes memory identifier, bytes memory log) = abi.decode(log.data, (bytes, bytes)); +(bytes memory identifier, bytes32 logHash) = abi.decode(log.data, (bytes, bytes32)); Identifier id = abi.decode(identifier, (Identifier)); ``` It is not possible to use solidity structs directly in events, which is why it is ABI encoded -into `bytes` first. +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 @@ -133,7 +135,7 @@ function executeMessage(Identifier calldata _id, address _target, bytes calldata require(success); - emit ExecutingMessage(abi.encode(_id), _msg); + emit ExecutingMessage(abi.encode(_id), keccak256(_msg)); } ``` From da0fd63941116786137eaeda5d771a350d964ebb Mon Sep 17 00:00:00 2001 From: 0xng Date: Tue, 25 Jun 2024 12:16:54 -0300 Subject: [PATCH 2/4] fix: changing events arguments order --- specs/interop/predeploys.md | 8 ++++---- specs/interop/sequencer.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/specs/interop/predeploys.md b/specs/interop/predeploys.md index 33fe652db..e86597356 100644 --- a/specs/interop/predeploys.md +++ b/specs/interop/predeploys.md @@ -94,14 +94,14 @@ The `ExecutingMessage` event represents an executing message. It MUST be emitted to `executeMessage`. ```solidity -event ExecutingMessage(bytes,bytes32); +event ExecutingMessage(bytes32,bytes); ``` -The data encoded in the event contains the `Identifier` and the keccak hash of the `msg`. +The data encoded in the event contains the the keccak hash of the `msg` and the `Identifier`. The following pseudocode shows the deserialization: ```solidity -(bytes memory identifier, bytes32 logHash) = abi.decode(log.data, (bytes, bytes32)); +(bytes32 logHash, bytes memory identifier) = abi.decode(log.data, (bytes32, bytes)); Identifier id = abi.decode(identifier, (Identifier)); ``` @@ -135,7 +135,7 @@ function executeMessage(Identifier calldata _id, address _target, bytes calldata require(success); - emit ExecutingMessage(abi.encode(_id), keccak256(_msg)); + emit ExecutingMessage(keccak256(_msg), abi.encode(_id)); } ``` diff --git a/specs/interop/sequencer.md b/specs/interop/sequencer.md index 46fb9324c..e84ad52c9 100644 --- a/specs/interop/sequencer.md +++ b/specs/interop/sequencer.md @@ -103,7 +103,7 @@ if not success: for log in receipt.logs: if is_executing_message(log): - id, message = abi.decode(log.data) + messageHash, id = abi.decode(log.data) # assumes there is a client for each chain in the dependency set eth = clients[id.chainid] @@ -116,7 +116,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) From e9b3e7788836c0e00adeb9c84bca0dd1f32c84ab Mon Sep 17 00:00:00 2001 From: 0xng Date: Thu, 1 Aug 2024 12:25:02 -0300 Subject: [PATCH 3/4] chore: adding entire identifier to event signature --- specs/interop/predeploys.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/specs/interop/predeploys.md b/specs/interop/predeploys.md index e86597356..c0963d8a1 100644 --- a/specs/interop/predeploys.md +++ b/specs/interop/predeploys.md @@ -94,19 +94,18 @@ The `ExecutingMessage` event represents an executing message. It MUST be emitted to `executeMessage`. ```solidity -event ExecutingMessage(bytes32,bytes); +event ExecutingMessage(bytes32 msgHash, Identifier identifier); ``` The data encoded in the event contains the the keccak hash of the `msg` and the `Identifier`. The following pseudocode shows the deserialization: ```solidity -(bytes32 logHash, bytes memory identifier) = abi.decode(log.data, (bytes32, bytes)); +(bytes32 msgHash, bytes memory identifier) = abi.decode(log.data, (bytes32, bytes)); Identifier id = abi.decode(identifier, (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 +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. @@ -135,7 +134,7 @@ function executeMessage(Identifier calldata _id, address _target, bytes calldata require(success); - emit ExecutingMessage(keccak256(_msg), abi.encode(_id)); + emit ExecutingMessage(keccak256(_msg), _id); } ``` From 9a43170e291c2344d96326ba1ed4d002d844a002 Mon Sep 17 00:00:00 2001 From: 0xng Date: Thu, 1 Aug 2024 18:24:44 -0300 Subject: [PATCH 4/4] chore: making hash parameter indexed --- specs/interop/predeploys.md | 8 ++++---- specs/interop/sequencer.md | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/specs/interop/predeploys.md b/specs/interop/predeploys.md index c0963d8a1..d72e8154a 100644 --- a/specs/interop/predeploys.md +++ b/specs/interop/predeploys.md @@ -94,15 +94,15 @@ The `ExecutingMessage` event represents an executing message. It MUST be emitted to `executeMessage`. ```solidity -event ExecutingMessage(bytes32 msgHash, Identifier identifier); +event ExecutingMessage(bytes32 indexed msgHash, Identifier identifier); ``` -The data encoded in the event contains the the keccak hash of the `msg` and the `Identifier`. +The data encoded in the event contains the keccak hash of the `msg` and the `Identifier`. The following pseudocode shows the deserialization: ```solidity -(bytes32 msgHash, bytes memory identifier) = abi.decode(log.data, (bytes32, bytes)); -Identifier id = abi.decode(identifier, (Identifier)); +bytes32 msgHash = log.topics[1]; +Identifier identifier = abi.decode(log.data, (Identifier)); ``` Emitting the hash of the message is more efficient than emitting the diff --git a/specs/interop/sequencer.md b/specs/interop/sequencer.md index e84ad52c9..b6bdb2bb7 100644 --- a/specs/interop/sequencer.md +++ b/specs/interop/sequencer.md @@ -103,7 +103,8 @@ if not success: for log in receipt.logs: if is_executing_message(log): - messageHash, id = 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]