diff --git a/packages/evm/contracts/Yaho.sol b/packages/evm/contracts/Yaho.sol index 0422b3e9..8eacef42 100644 --- a/packages/evm/contracts/Yaho.sol +++ b/packages/evm/contracts/Yaho.sol @@ -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( @@ -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, @@ -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); } diff --git a/packages/evm/contracts/interfaces/IMessage.sol b/packages/evm/contracts/interfaces/IMessage.sol index 751e686d..9ec02029 100644 --- a/packages/evm/contracts/interfaces/IMessage.sol +++ b/packages/evm/contracts/interfaces/IMessage.sol @@ -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; diff --git a/packages/evm/test/utils/Message.ts b/packages/evm/test/utils/Message.ts index eefff1c9..8a16c75e 100644 --- a/packages/evm/test/utils/Message.ts +++ b/packages/evm/test/utils/Message.ts @@ -7,7 +7,7 @@ type Configs = { id: string receiver: `0x${string}` targetChainId: number - salt: string + nonce: number reporters: `0x${string}`[] adapters: `0x${string}`[] } @@ -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 @@ -42,7 +42,7 @@ class Message { serialize() { return [ - this.salt, + this.nonce, this.targetChainId, this.threshold, this.sender,