Skip to content

Commit

Permalink
evm: Enforce initializer on the transceivers as well
Browse files Browse the repository at this point in the history
  • Loading branch information
djb15 committed Feb 27, 2024
1 parent 1d7954a commit 553462f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions evm/src/Transceiver/Transceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ abstract contract Transceiver is
/// contract address and then add the new one.
address public immutable nttManager;
address public immutable nttManagerToken;
address immutable deployer;

constructor(address _nttManager) {
nttManager = _nttManager;
nttManagerToken = INttManager(nttManager).token();
deployer = msg.sender;
}

/// =============== MODIFIERS ===============================================
Expand All @@ -40,6 +42,11 @@ abstract contract Transceiver is
/// =============== ADMIN ===============================================

function _initialize() internal virtual override {
// check if the owner is the deployer of this contract
if (msg.sender != deployer) {
revert UnexpectedDeployer(deployer, msg.sender);
}

__ReentrancyGuard_init();
// owner of the transceiver is set to the owner of the nttManager
__PausedOwnable_init(msg.sender, getNttManagerOwner());
Expand Down
2 changes: 2 additions & 0 deletions evm/src/interfaces/ITransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity >=0.8.8 <0.9.0;
import "../libraries/TransceiverStructs.sol";

interface ITransceiver {
/// @notice The caller is not the deployer.
error UnexpectedDeployer(address deployer, address caller);
error CallerNotNttManager(address caller);
error CannotRenounceTransceiverOwnership(address currentOwner);
error CannotTransferTransceiverOwnership(address currentOwner, address newOwner);
Expand Down
10 changes: 10 additions & 0 deletions evm/test/IntegrationStandalone.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../src/NttManager/NttManager.sol";
import "../src/Transceiver/Transceiver.sol";
import "../src/interfaces/INttManager.sol";
import "../src/interfaces/IRateLimiter.sol";
import "../src/interfaces/ITransceiver.sol";
import "../src/interfaces/INttManagerEvents.sol";
import "../src/interfaces/IRateLimiterEvents.sol";
import {Utils} from "./libraries/Utils.sol";
Expand Down Expand Up @@ -80,6 +81,15 @@ contract TestEndToEndBase is Test, INttManagerEvents, IRateLimiterEvents {
wormholeTransceiverChain1 = MockWormholeTransceiverContract(
address(new ERC1967Proxy(address(wormholeTransceiverChain1Implementation), ""))
);

// Only the deployer should be able to initialize
vm.prank(userA);
vm.expectRevert(
abi.encodeWithSelector(ITransceiver.UnexpectedDeployer.selector, address(this), userA)
);
wormholeTransceiverChain1.initialize();

// Actually initialize properly now
wormholeTransceiverChain1.initialize();

nttManagerChain1.setTransceiver(address(wormholeTransceiverChain1));
Expand Down

0 comments on commit 553462f

Please sign in to comment.