From 580edf0243ac16a52242580e07cbc0d5fa0e6349 Mon Sep 17 00:00:00 2001 From: Bruce Riley Date: Wed, 30 Oct 2024 08:55:02 -0500 Subject: [PATCH] evm: Fix dstChain on attestMessage --- evm/script/DeployWormholeTransceiver.s.sol | 39 ++++++----------- evm/sh/deployWormholeTransceiver.sh | 2 +- evm/src/WormholeTransceiver.sol | 14 +----- evm/test/WormholeTransceiver.t.sol | 50 ++++++++++++---------- 4 files changed, 42 insertions(+), 63 deletions(-) diff --git a/evm/script/DeployWormholeTransceiver.s.sol b/evm/script/DeployWormholeTransceiver.s.sol index 2f1430f..d692628 100644 --- a/evm/script/DeployWormholeTransceiver.s.sol +++ b/evm/script/DeployWormholeTransceiver.s.sol @@ -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)); } diff --git a/evm/sh/deployWormholeTransceiver.sh b/evm/sh/deployWormholeTransceiver.sh index d09ef3c..1ef0549 100755 --- a/evm/sh/deployWormholeTransceiver.sh +++ b/evm/sh/deployWormholeTransceiver.sh @@ -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} diff --git a/evm/src/WormholeTransceiver.sol b/evm/src/WormholeTransceiver.sol index 2416c8c..39630b1 100644 --- a/evm/src/WormholeTransceiver.sol +++ b/evm/src/WormholeTransceiver.sol @@ -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); @@ -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. } diff --git a/evm/test/WormholeTransceiver.t.sol b/evm/test/WormholeTransceiver.t.sol index ece671a..ca50047 100644 --- a/evm/test/WormholeTransceiver.t.sol +++ b/evm/test/WormholeTransceiver.t.sol @@ -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, @@ -164,7 +159,6 @@ contract WormholeTransceiverTest is Test { uint8 consistencyLevel = 200; uint16 ourChain = 42; - uint256 ourevmChain = 31337; uint16 srcChain = 42; uint16 destChain = 43; @@ -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. @@ -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 { @@ -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 wrongDestChain = destChain + 1; + WormholeTransceiverForTest destTransceiver2 = new WormholeTransceiverForTest( + wrongDestChain, 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 {