Skip to content

Commit

Permalink
Merge pull request #43 from gnosis/ref/message-id
Browse files Browse the repository at this point in the history
ref: message id
  • Loading branch information
allemanfredi authored Feb 12, 2024
2 parents bff9b15 + 1b1dd89 commit d6db43b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/evm/contracts/Yaho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IAdapter } from "./interfaces/IAdapter.sol";

contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
mapping(uint256 => bytes32) private _pendingMessageHashes;
uint256 public currentNonce;

/// @inheritdoc IYaho
function dispatchMessage(
Expand Down Expand Up @@ -146,7 +147,7 @@ contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
) internal returns (uint256, bytes32) {
address sender = msg.sender;
Message memory message = Message(
keccak256(abi.encode(blockhash(block.number - 1), gasleft())),
currentNonce,
targetChainId,
threshold,
sender,
Expand All @@ -158,6 +159,9 @@ contract Yaho is IYaho, MessageIdCalculator, MessageHashCalculator {
bytes32 messageHash = calculateMessageHash(message);
uint256 messageId = calculateMessageId(block.chainid, address(this), messageHash);
_pendingMessageHashes[messageId] = messageHash;
unchecked {
++currentNonce;
}
emit MessageDispatched(messageId, message);
return (messageId, messageHash);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/contracts/interfaces/IMessage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IReporter } from "./IReporter.sol";
import { IAdapter } from "./IAdapter.sol";

struct Message {
bytes32 salt;
uint256 nonce;
uint256 targetChainId;
uint256 threshold;
address sender;
Expand Down
10 changes: 5 additions & 5 deletions packages/evm/test/utils/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Configs = {
id: string
receiver: `0x${string}`
targetChainId: number
salt: string
nonce: number
reporters: `0x${string}`[]
adapters: `0x${string}`[]
}
Expand All @@ -19,17 +19,17 @@ class Message {
public id: string
public receiver: `0x${string}`
public targetChainId: number
public salt: string
public nonce: number
public reporters: `0x${string}`[]
public adapters: `0x${string}`[]

constructor({ data, sender, threshold, id, receiver, targetChainId, salt, reporters, adapters }: Configs) {
constructor({ data, sender, threshold, id, receiver, targetChainId, nonce, reporters, adapters }: Configs) {
this.id = id
this.sender = sender
this.targetChainId = targetChainId
this.receiver = receiver
this.data = data
this.salt = salt
this.nonce = nonce
this.reporters = reporters
this.adapters = adapters
this.threshold = threshold
Expand All @@ -42,7 +42,7 @@ class Message {

serialize() {
return [
this.salt,
this.nonce,
this.targetChainId,
this.threshold,
this.sender,
Expand Down

0 comments on commit d6db43b

Please sign in to comment.