Skip to content

Commit

Permalink
evm: sendMessage for WormholeGuardiansAdapterWithExecutor is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Dec 18, 2024
1 parent 7deb17c commit 7b32ba4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions evm/src/WormholeGuardiansAdapterWithExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.19;

import "wormhole-solidity-sdk/libraries/BytesParsing.sol";
import "example-messaging-executor/evm/src/interfaces/IExecutor.sol";
import "example-messaging-executor/evm/src/libraries/ExecutorMessages.sol";

import "./WormholeGuardiansAdapter.sol";

Expand All @@ -11,6 +12,10 @@ string constant wormholeGuardiansAdapterWithExecutorVersionString = "WormholeGua
contract WormholeGuardiansAdapterWithExecutor is WormholeGuardiansAdapter {
using BytesParsing for bytes; // Used to parse the instructions

// ==================== Immutables ===============================================

bytes32 public emitterAddress;

// Version number of the encoded adapter instructions.
uint8 private constant INST_VERSION = 1;

Expand Down Expand Up @@ -44,6 +49,7 @@ contract WormholeGuardiansAdapterWithExecutor is WormholeGuardiansAdapter {
) WormholeGuardiansAdapter(_ourChain, _admin, _endpoint, _wormhole, _consistencyLevel) {
assert(_executor != address(0));
executor = IExecutor(_executor);
emitterAddress = UniversalAddressLibrary.fromAddress(address(this)).toBytes32();
}

/// @inheritdoc IAdapter
Expand All @@ -62,15 +68,20 @@ contract WormholeGuardiansAdapterWithExecutor is WormholeGuardiansAdapter {
address refundAddr,
bytes calldata instructions
) external payable override onlyEndpoint {
bytes memory payload = _encodePayload(srcAddr, sequence, dstChain, dstAddr, payloadHash);
wormhole.publishMessage{value: msg.value}(0, payload, consistencyLevel);
emit MessageSent(srcAddr, dstChain, dstAddr, sequence, payloadHash);

(uint256 execMsgValue, bytes memory signedQuote, bytes memory relayInstructions) =
_parseInstructions(instructions);

bytes memory payload = _encodePayload(srcAddr, sequence, dstChain, dstAddr, payloadHash);
uint64 coreSeq = wormhole.publishMessage{value: msg.value - execMsgValue}(0, payload, consistencyLevel);
emit MessageSent(srcAddr, dstChain, dstAddr, sequence, payloadHash);

executor.requestExecution{value: execMsgValue}(
dstChain, dstAddr.toBytes32(), refundAddr, signedQuote, payload, relayInstructions
dstChain,
dstAddr.toBytes32(),
refundAddr,
signedQuote,
ExecutorMessages.makeVAAV1Request(ourChain, emitterAddress, coreSeq),
relayInstructions
);
}

Expand Down
4 changes: 2 additions & 2 deletions evm/test/WormholeGuardiansAdapterWithExecutor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ contract WormholeGuardiansAdapterWithExecutorTest is Test {
uint64 sequence = 42;
bytes32 payloadHash = keccak256("message one");
address refundAddr = userA;
uint256 deliverPrice = 382;
uint256 deliverPrice = 1000;

uint256 execMsgValue = 123;
bytes memory signedQuote = "Hi, Mom!";
Expand All @@ -240,7 +240,7 @@ contract WormholeGuardiansAdapterWithExecutorTest is Test {
require(srcWormhole.messagesSent() == 1, "Message count is wrong");
require(srcWormhole.lastNonce() == 0, "Nonce is wrong");
require(srcWormhole.lastConsistencyLevel() == consistencyLevel, "Consistency level is wrong");
require(srcWormhole.lastDeliveryPrice() == deliverPrice, "Deliver price is wrong");
require(srcWormhole.lastDeliveryPrice() == deliverPrice - execMsgValue, "Deliver price is wrong");

bytes memory expectedPayload = srcAdapter.encodePayload(srcAddr, sequence, dstChain, dstAddr, payloadHash);
require(
Expand Down

0 comments on commit 7b32ba4

Please sign in to comment.