Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: Fix dstChain on attestMessage #3

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions evm/script/DeployWormholeTransceiver.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,26 @@ import "forge-std/Script.sol";
contract DeployWormholeTransceiver is Script {
function test() public {} // Exclude this from coverage report.

function dryRun(
uint16 ourChain,
uint256 evmChain,
address admin,
address router,
address wormhole,
uint8 consistencyLevel
) public {
_deploy(ourChain, evmChain, admin, router, wormhole, consistencyLevel);
function dryRun(uint16 ourChain, address admin, address router, address wormhole, uint8 consistencyLevel) public {
_deploy(ourChain, admin, router, wormhole, consistencyLevel);
}

function run(
uint16 ourChain,
uint256 evmChain,
address admin,
address router,
address wormhole,
uint8 consistencyLevel
) public returns (address deployedAddress) {
function run(uint16 ourChain, address admin, address router, address wormhole, uint8 consistencyLevel)
public
returns (address deployedAddress)
{
vm.startBroadcast();
(deployedAddress) = _deploy(ourChain, evmChain, admin, router, wormhole, consistencyLevel);
(deployedAddress) = _deploy(ourChain, admin, router, wormhole, consistencyLevel);
vm.stopBroadcast();
}

function _deploy(
uint16 ourChain,
uint256 evmChain,
address admin,
address router,
address wormhole,
uint8 consistencyLevel
) internal returns (address deployedAddress) {
function _deploy(uint16 ourChain, address admin, address router, address wormhole, uint8 consistencyLevel)
internal
returns (address deployedAddress)
{
bytes32 salt = keccak256(abi.encodePacked(wormholeTransceiverVersionString));
WormholeTransceiver wormholeTransceiver =
new WormholeTransceiver{salt: salt}(ourChain, evmChain, admin, router, wormhole, consistencyLevel);
new WormholeTransceiver{salt: salt}(ourChain, admin, router, wormhole, consistencyLevel);

return (address(wormholeTransceiver));
}
Expand Down
2 changes: 1 addition & 1 deletion evm/sh/deployWormholeTransceiver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if [ "${CONSISTENCY_LEVEL}X" == "X" ]; then
fi

forge script ./script/DeployWormholeTransceiver.s.sol:DeployWormholeTransceiver \
--sig "run(uint16,uint256,address,address,address,uint8)" $OUR_CHAIN_ID $EVM_CHAIN_ID $ADMIN $ROUTER $WORMHOLE $CONSISTENCY_LEVEL \
--sig "run(uint16,address,address,address,uint8)" $OUR_CHAIN_ID $ADMIN $ROUTER $WORMHOLE $CONSISTENCY_LEVEL \
--rpc-url "$RPC_URL" \
--private-key "$MNEMONIC" \
--broadcast ${FORGE_ARGS}
Expand Down
14 changes: 2 additions & 12 deletions evm/src/WormholeTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,18 @@ contract WormholeTransceiver is IWormholeTransceiver {
// ==================== Immutables ===============================================

uint16 public immutable ourChain;
uint256 immutable evmChain;
IRouterTransceiver public immutable router;
IWormhole public immutable wormhole;
uint8 public immutable consistencyLevel;

// ==================== Constructor ==============================================

constructor(
uint16 _ourChain,
uint256 _evmChain,
address _admin,
address _router,
address _wormhole,
uint8 _consistencyLevel
) {
constructor(uint16 _ourChain, address _admin, address _router, address _wormhole, uint8 _consistencyLevel) {
assert(_ourChain != 0);
assert(_evmChain != 0);
assert(_admin != address(0));
assert(_router != address(0));
assert(_wormhole != address(0));
// Not checking consistency level since maybe zero is valid?
evmChain = _evmChain;
ourChain = _ourChain;
admin = _admin;
router = IRouterTransceiver(_router);
Expand Down Expand Up @@ -214,7 +204,7 @@ contract WormholeTransceiver is IWormholeTransceiver {
// Not validating that the dest chain is our chain because the router does that.

// Post the message to the router.
router.attestMessage(srcChain, srcAddr, sequence, ourChain, dstAddr, payloadHash);
router.attestMessage(srcChain, srcAddr, sequence, dstChain, dstAddr, payloadHash);

// We don't need to emit an event here because _verifyMessage already did.
}
Expand Down
50 changes: 27 additions & 23 deletions evm/test/WormholeTransceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import "../src/WormholeTransceiver.sol";
import "../src/interfaces/IWormholeTransceiver.sol";

contract WormholeTransceiverForTest is WormholeTransceiver {
constructor(
uint16 _ourChain,
uint256 _ourevmChain,
address _admin,
address _router,
address srcWormhole,
uint8 _consistencyLevel
) WormholeTransceiver(_ourChain, _ourevmChain, _admin, _router, srcWormhole, _consistencyLevel) {}
constructor(uint16 _ourChain, address _admin, address _router, address srcWormhole, uint8 _consistencyLevel)
WormholeTransceiver(_ourChain, _admin, _router, srcWormhole, _consistencyLevel)
{}

function encodePayload(
UniversalAddress srcAddr,
Expand Down Expand Up @@ -164,7 +159,6 @@ contract WormholeTransceiverTest is Test {
uint8 consistencyLevel = 200;

uint16 ourChain = 42;
uint256 ourevmChain = 31337;

uint16 srcChain = 42;
uint16 destChain = 43;
Expand All @@ -182,12 +176,11 @@ contract WormholeTransceiverTest is Test {
routerAddr = address(srcRouter);
destRouter = new MockRouter(destChain);
srcWormhole = new MockWormhole(srcChain);
srcTransceiver = new WormholeTransceiverForTest(
srcChain, ourevmChain, admin, routerAddr, address(srcWormhole), consistencyLevel
);
srcTransceiver =
new WormholeTransceiverForTest(srcChain, admin, routerAddr, address(srcWormhole), consistencyLevel);
destWormhole = new MockWormhole(destChain);
destTransceiver = new WormholeTransceiverForTest(
destChain, ourevmChain, admin, address(destRouter), address(destWormhole), consistencyLevel
destChain, admin, address(destRouter), address(destWormhole), consistencyLevel
);

// Give everyone some money to play with.
Expand All @@ -208,25 +201,19 @@ contract WormholeTransceiverTest is Test {
function test_invalidInit() public {
// ourChain can't be zero.
vm.expectRevert();
new WormholeTransceiver(0, ourevmChain, admin, address(destRouter), address(destWormhole), consistencyLevel);

// evmChain can't be zero.
vm.expectRevert();
new WormholeTransceiver(destChain, 0, admin, address(destRouter), address(destWormhole), consistencyLevel);
new WormholeTransceiver(0, admin, address(destRouter), address(destWormhole), consistencyLevel);

// admin can't be zero.
vm.expectRevert();
new WormholeTransceiver(
destChain, ourevmChain, address(0), address(destRouter), address(destWormhole), consistencyLevel
);
new WormholeTransceiver(destChain, address(0), address(destRouter), address(destWormhole), consistencyLevel);

// router can't be zero.
vm.expectRevert();
new WormholeTransceiver(destChain, ourevmChain, admin, address(0), address(destWormhole), consistencyLevel);
new WormholeTransceiver(destChain, admin, address(0), address(destWormhole), consistencyLevel);

// wormhole can't be zero.
vm.expectRevert();
new WormholeTransceiver(destChain, ourevmChain, admin, address(destRouter), address(0), consistencyLevel);
new WormholeTransceiver(destChain, admin, address(destRouter), address(0), consistencyLevel);
}

function test_updateAdmin() public {
Expand Down Expand Up @@ -464,6 +451,23 @@ contract WormholeTransceiverTest is Test {
vm.expectRevert(abi.encodeWithSelector(IWormholeTransceiver.InvalidVaa.selector, "This is bad!"));
destTransceiver.receiveMessage(vaa);
destWormhole.setValidFlag(true, "");

// The transceiver should not block a message with the wrong dest chain because the router does that.
uint16 diffDestChain = destChain + 1;
WormholeTransceiverForTest destTransceiver2 = new WormholeTransceiverForTest(
diffDestChain, admin, address(destRouter), address(destWormhole), consistencyLevel
);
vm.startPrank(admin);
destTransceiver2.setPeer(srcChain, UniversalAddressLibrary.fromAddress(address(srcTransceiver)).toBytes32());
vm.startPrank(integratorAddr);
destTransceiver2.receiveMessage(vaa);

require(destRouter.lastSourceChain() == srcChain, "srcChain is wrong 2");
require(destRouter.lastSourceAddress() == srcAddr, "srcAddr is wrong 2");
require(destRouter.lastSequence() == sequence, "sequence is wrong 2");
require(destRouter.lastDestinationChain() == dstChain, "dstChain in vaa is wrong");
require(destRouter.lastDestinationAddress() == dstAddr, "dstAddr is wrong 2");
require(destRouter.lastPayloadHash() == payloadHash, "payloadHash is wrong 2");
}

function test_encodeDecode() public {
Expand Down
Loading