Skip to content

Commit

Permalink
evm: TransferSent(bytes32), fixes #503
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Oct 2, 2024
1 parent 6a1a3d9 commit 68a7ca4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ event TransferSent(
);
```

```solidity
/// @notice Emitted when a message is sent from the nttManager.
/// @dev Topic0
/// 0x3e6ae56314c6da8b461d872f41c6d0bb69317b9d0232805aaccfa45df1a16fa0.
/// @param digest The digest of the message.
event TransferSent(bytes32 indexed digest);
```

2. **Rate Limit**

A transfer can be rate-limited (see [here](../README.md#rate-limiting-and-cancel-flows) for more details) both on the source and destination chains. If a transfer is rate-limited on the source chain and the `shouldQueue` flag is enabled, it is added to an outbound queue. The transfer can be released after the configured `_rateLimitDuration` has expired via the [`completeOutboundQueuedTransfer`] method. The `OutboundTransferQueued` and `OutboundTransferRateLimited` events are emitted.
Expand Down
4 changes: 4 additions & 0 deletions evm/src/NttManager/NttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
seq
);

emit TransferSent(
TransceiverStructs._nttManagerMessageDigest(chainId, encodedNttManagerPayload)
);

// return the sequence number
return seq;
}
Expand Down
6 changes: 6 additions & 0 deletions evm/src/interfaces/INttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ interface INttManager is IManagerBase {
uint64 msgSequence
);

/// @notice Emitted when a message is sent from the nttManager.
/// @dev Topic0
/// 0x3e6ae56314c6da8b461d872f41c6d0bb69317b9d0232805aaccfa45df1a16fa0.
/// @param digest The digest of the message.
event TransferSent(bytes32 indexed digest);

/// @notice Emitted when the peer contract is updated.
/// @dev Topic0
/// 0x1456404e7f41f35c3daac941bb50bad417a66275c3040061b4287d787719599d.
Expand Down
9 changes: 8 additions & 1 deletion evm/src/libraries/TransceiverStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ library TransceiverStructs {
uint16 sourceChainId,
NttManagerMessage memory m
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(sourceChainId, encodeNttManagerMessage(m)));
return _nttManagerMessageDigest(sourceChainId, encodeNttManagerMessage(m));
}

function _nttManagerMessageDigest(
uint16 sourceChainId,
bytes memory encodedNttManagerMessage
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(sourceChainId, encodedNttManagerMessage));
}

function encodeNttManagerMessage(
Expand Down
25 changes: 24 additions & 1 deletion evm/test/IntegrationStandalone.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,18 @@ contract TestEndToEndBase is Test, IRateLimiterEvents {

vm.stopPrank();

// Get the TransferSent(bytes32) event to ensure it matches up with the TransferRedeemed(bytes32) event later
Vm.Log[] memory recordedLogs = vm.getRecordedLogs();
bytes32 sentEventDigest;
for (uint256 i = 0; i < recordedLogs.length; i++) {
if (recordedLogs[i].topics[0] == keccak256("TransferSent(bytes32)")) {
sentEventDigest = recordedLogs[i].topics[1];
}
}
require(sentEventDigest != bytes32(0), "TransferSent(bytes32) event should be found");

// Get and sign the log to go down the other pipe. Thank you to whoever wrote this code in the past!
Vm.Log[] memory entries = guardian.fetchWormholeMessageFromLog(vm.getRecordedLogs());
Vm.Log[] memory entries = guardian.fetchWormholeMessageFromLog(recordedLogs);
bytes[] memory encodedVMs = new bytes[](entries.length);
for (uint256 i = 0; i < encodedVMs.length; i++) {
encodedVMs[i] = guardian.fetchSignedMessageFromLogs(entries[i], chainId1);
Expand All @@ -209,6 +219,19 @@ contract TestEndToEndBase is Test, IRateLimiterEvents {
);
}

// Get the TransferRedeemed(bytes32) event to ensure it matches up with the TransferSent(bytes32) event earlier
recordedLogs = vm.getRecordedLogs();
bytes32 recvEventDigest;
for (uint256 i = 0; i < recordedLogs.length; i++) {
if (recordedLogs[i].topics[0] == keccak256("TransferRedeemed(bytes32)")) {
recvEventDigest = recordedLogs[i].topics[1];
}
}
require(
sentEventDigest == recvEventDigest,
"TransferRedeemed(bytes32) event should match TransferSent(bytes32)"
);

// Can't resubmit the same message twice
(IWormhole.VM memory wormholeVM,,) = wormhole.parseAndVerifyVM(encodedVMs[0]);
vm.expectRevert(
Expand Down

0 comments on commit 68a7ca4

Please sign in to comment.