Skip to content

Commit

Permalink
evm: forge fmt
Browse files Browse the repository at this point in the history
This partially undoes #501, which itself updated formatting after an
upstream foundry change. That upstream change has been reverted
foundry-rs/foundry#8762, so we do the same here.
  • Loading branch information
kcsongor committed Aug 29, 2024
1 parent f4d970e commit 2e23893
Show file tree
Hide file tree
Showing 37 changed files with 321 additions and 107 deletions.
4 changes: 3 additions & 1 deletion evm/script/helpers/DeployWormholeNttBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ contract DeployWormholeNttBase is ParseNttConfig {
// gas on testnet, pick up the phone and start dialing!
uint256 constant MIN_WORMHOLE_GAS_LIMIT = 150000;

function deployNttManager(DeploymentParams memory params) internal returns (address) {
function deployNttManager(
DeploymentParams memory params
) internal returns (address) {
// Deploy the Manager Implementation.
NttManager implementation = new NttManager(
params.token,
Expand Down
4 changes: 3 additions & 1 deletion evm/script/helpers/ParseNttConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ contract ParseNttConfig is Script {

mapping(uint16 => bool) duplicateChainIds;

function toUniversalAddress(address evmAddr) internal pure returns (bytes32 converted) {
function toUniversalAddress(
address evmAddr
) internal pure returns (bytes32 converted) {
assembly ("memory-safe") {
converted := and(0xffffffffffffffffffffffffffffffffffffffff, evmAddr)
}
Expand Down
44 changes: 33 additions & 11 deletions evm/src/NttManager/ManagerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ abstract contract ManagerBase is
return (enabledTransceivers, instructions, priceQuotes, totalPriceQuote);
}

function _refundToSender(uint256 refundAmount) internal {
function _refundToSender(
uint256 refundAmount
) internal {
// refund the price quote back to sender
(bool refundSuccessful,) = payable(msg.sender).call{value: refundAmount}("");

Expand All @@ -283,7 +285,9 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function isMessageApproved(bytes32 digest) public view returns (bool) {
function isMessageApproved(
bytes32 digest
) public view returns (bool) {
uint8 threshold = getThreshold();
return messageAttestations(digest) >= threshold && threshold > 0;
}
Expand All @@ -294,7 +298,9 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function isMessageExecuted(bytes32 digest) public view returns (bool) {
function isMessageExecuted(
bytes32 digest
) public view returns (bool) {
return _getMessageAttestationsStorage()[digest].executed;
}

Expand All @@ -305,14 +311,18 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function messageAttestations(bytes32 digest) public view returns (uint8 count) {
function messageAttestations(
bytes32 digest
) public view returns (uint8 count) {
return countSetBits(_getMessageAttestations(digest));
}

// =============== Admin ==============================================================

/// @inheritdoc IManagerBase
function upgrade(address newImplementation) external onlyOwner {
function upgrade(
address newImplementation
) external onlyOwner {
_upgrade(newImplementation);
}

Expand All @@ -326,7 +336,9 @@ abstract contract ManagerBase is
}

/// @notice Transfer ownership of the Manager contract and all Transceiver contracts to a new owner.
function transferOwnership(address newOwner) public override onlyOwner {
function transferOwnership(
address newOwner
) public override onlyOwner {
super.transferOwnership(newOwner);
// loop through all the registered transceivers and set the new owner of each transceiver to the newOwner
address[] storage _registeredTransceivers = _getRegisteredTransceiversStorage();
Expand All @@ -338,7 +350,9 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function setTransceiver(address transceiver) external onlyOwner {
function setTransceiver(
address transceiver
) external onlyOwner {
_setTransceiver(transceiver);

_Threshold storage _threshold = _getThresholdStorage();
Expand All @@ -365,7 +379,9 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function removeTransceiver(address transceiver) external onlyOwner {
function removeTransceiver(
address transceiver
) external onlyOwner {
_removeTransceiver(transceiver);

_Threshold storage _threshold = _getThresholdStorage();
Expand All @@ -381,7 +397,9 @@ abstract contract ManagerBase is
}

/// @inheritdoc IManagerBase
function setThreshold(uint8 threshold) external onlyOwner {
function setThreshold(
uint8 threshold
) external onlyOwner {
if (threshold == 0) {
revert ZeroThreshold();
}
Expand Down Expand Up @@ -410,7 +428,9 @@ abstract contract ManagerBase is
}

/// @dev Returns the bitmap of attestations from enabled transceivers for a given message.
function _getMessageAttestations(bytes32 digest) internal view returns (uint64) {
function _getMessageAttestations(
bytes32 digest
) internal view returns (uint64) {
uint64 enabledTransceiverBitmap = _getEnabledTransceiversBitmap();
return
_getMessageAttestationsStorage()[digest].attestedTransceivers & enabledTransceiverBitmap;
Expand All @@ -425,7 +445,9 @@ abstract contract ManagerBase is

// @dev Mark a message as executed.
// This function will retuns `true` if the message has already been executed.
function _replayProtect(bytes32 digest) internal returns (bool) {
function _replayProtect(
bytes32 digest
) internal returns (bool) {
// check if this message has already been executed
if (isMessageExecuted(digest)) {
return true;
Expand Down
12 changes: 9 additions & 3 deletions evm/src/NttManager/NttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
// =============== Public Getters ========================================================

/// @inheritdoc INttManager
function getPeer(uint16 chainId_) external view returns (NttManagerPeer memory) {
function getPeer(
uint16 chainId_
) external view returns (NttManagerPeer memory) {
return _getPeersStorage()[chainId_];
}

Expand Down Expand Up @@ -132,7 +134,9 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
}

/// @inheritdoc INttManager
function setOutboundLimit(uint256 limit) external onlyOwner {
function setOutboundLimit(
uint256 limit
) external onlyOwner {
uint8 toDecimals = tokenDecimals();
_setOutboundLimit(limit.trim(toDecimals, toDecimals));
}
Expand Down Expand Up @@ -241,7 +245,9 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
}

/// @inheritdoc INttManager
function completeInboundQueuedTransfer(bytes32 digest) external nonReentrant whenNotPaused {
function completeInboundQueuedTransfer(
bytes32 digest
) external nonReentrant whenNotPaused {
// find the message in the queue
InboundQueuedTransfer memory queuedTransfer = getInboundQueuedTransfer(digest);
if (queuedTransfer.txTimestamp == 0) {
Expand Down
12 changes: 9 additions & 3 deletions evm/src/NttManager/TransceiverRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ abstract contract TransceiverRegistry {

// =============== Storage Getters/Setters ========================================

function _setTransceiver(address transceiver) internal returns (uint8 index) {
function _setTransceiver(
address transceiver
) internal returns (uint8 index) {
mapping(address => TransceiverInfo) storage transceiverInfos = _getTransceiverInfosStorage();
_EnabledTransceiverBitmap storage _enabledTransceiverBitmap = _getTransceiverBitmapStorage();
address[] storage _enabledTransceivers = _getEnabledTransceiversStorage();
Expand Down Expand Up @@ -181,7 +183,9 @@ abstract contract TransceiverRegistry {
return transceiverInfos[transceiver].index;
}

function _removeTransceiver(address transceiver) internal {
function _removeTransceiver(
address transceiver
) internal {
mapping(address => TransceiverInfo) storage transceiverInfos = _getTransceiverInfosStorage();
_EnabledTransceiverBitmap storage _enabledTransceiverBitmap = _getTransceiverBitmapStorage();
address[] storage _enabledTransceivers = _getEnabledTransceiversStorage();
Expand Down Expand Up @@ -276,7 +280,9 @@ abstract contract TransceiverRegistry {
}

// @dev Check that the transceiver is in a valid state.
function _checkTransceiverInvariants(address transceiver) private view {
function _checkTransceiverInvariants(
address transceiver
) private view {
mapping(address => TransceiverInfo) storage transceiverInfos = _getTransceiverInfosStorage();
_EnabledTransceiverBitmap storage _enabledTransceiverBitmap = _getTransceiverBitmapStorage();
_NumTransceivers storage _numTransceivers = _getNumTransceiversStorage();
Expand Down
12 changes: 9 additions & 3 deletions evm/src/Transceiver/Transceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ abstract contract Transceiver is
address public immutable nttManagerToken;
address immutable deployer;

constructor(address _nttManager) {
constructor(
address _nttManager
) {
nttManager = _nttManager;
nttManagerToken = INttManager(nttManager).token();
deployer = msg.sender;
Expand Down Expand Up @@ -63,11 +65,15 @@ abstract contract Transceiver is

/// @dev transfer the ownership of the transceiver to a new address
/// the nttManager should be able to update transceiver ownership.
function transferTransceiverOwnership(address newOwner) external onlyNttManager {
function transferTransceiverOwnership(
address newOwner
) external onlyNttManager {
_transferOwnership(newOwner);
}

function upgrade(address newImplementation) external onlyOwner {
function upgrade(
address newImplementation
) external onlyOwner {
_upgrade(newImplementation);
}

Expand Down
12 changes: 9 additions & 3 deletions evm/src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ contract WormholeTransceiver is
}

/// @inheritdoc IWormholeTransceiver
function receiveMessage(bytes memory encodedMessage) external {
function receiveMessage(
bytes memory encodedMessage
) external {
uint16 sourceChainId;
bytes memory payload;
(sourceChainId, payload) = _verifyMessage(encodedMessage);
Expand Down Expand Up @@ -240,7 +242,9 @@ contract WormholeTransceiver is
emit SendTransceiverMessage(recipientChain, transceiverMessage);
}

function _verifyMessage(bytes memory encodedMessage) internal returns (uint16, bytes memory) {
function _verifyMessage(
bytes memory encodedMessage
) internal returns (uint16, bytes memory) {
// verify VAA against Wormhole Core Bridge contract
(IWormhole.VM memory vm, bool valid, string memory reason) =
wormhole.parseAndVerifyVM(encodedMessage);
Expand All @@ -267,7 +271,9 @@ contract WormholeTransceiver is
return (vm.emitterChainId, vm.payload);
}

function _verifyBridgeVM(IWormhole.VM memory vm) internal view returns (bool) {
function _verifyBridgeVM(
IWormhole.VM memory vm
) internal view returns (bool) {
checkFork(wormholeTransceiver_evmChainId);
return getWormholePeer(vm.emitterChainId) == vm.emitterAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,37 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce
// =============== Public Getters ======================================================

/// @inheritdoc IWormholeTransceiverState
function isVAAConsumed(bytes32 hash) public view returns (bool) {
function isVAAConsumed(
bytes32 hash
) public view returns (bool) {
return _getWormholeConsumedVAAsStorage()[hash];
}

/// @inheritdoc IWormholeTransceiverState
function getWormholePeer(uint16 chainId) public view returns (bytes32) {
function getWormholePeer(
uint16 chainId
) public view returns (bytes32) {
return _getWormholePeersStorage()[chainId];
}

/// @inheritdoc IWormholeTransceiverState
function isWormholeRelayingEnabled(uint16 chainId) public view returns (bool) {
function isWormholeRelayingEnabled(
uint16 chainId
) public view returns (bool) {
return _getWormholeRelayingEnabledChainsStorage()[chainId].toBool();
}

/// @inheritdoc IWormholeTransceiverState
function isSpecialRelayingEnabled(uint16 chainId) public view returns (bool) {
function isSpecialRelayingEnabled(
uint16 chainId
) public view returns (bool) {
return _getSpecialRelayingEnabledChainsStorage()[chainId].toBool();
}

/// @inheritdoc IWormholeTransceiverState
function isWormholeEvmChain(uint16 chainId) public view returns (bool) {
function isWormholeEvmChain(
uint16 chainId
) public view returns (bool) {
return _getWormholeEvmChainIdsStorage()[chainId].toBool();
}

Expand Down Expand Up @@ -266,15 +276,21 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce

// ============= Internal ===============================================================

function _checkInvalidRelayingConfig(uint16 chainId) internal view returns (bool) {
function _checkInvalidRelayingConfig(
uint16 chainId
) internal view returns (bool) {
return isWormholeRelayingEnabled(chainId) && !isWormholeEvmChain(chainId);
}

function _shouldRelayViaStandardRelaying(uint16 chainId) internal view returns (bool) {
function _shouldRelayViaStandardRelaying(
uint16 chainId
) internal view returns (bool) {
return isWormholeRelayingEnabled(chainId) && isWormholeEvmChain(chainId);
}

function _setVAAConsumed(bytes32 hash) internal {
function _setVAAConsumed(
bytes32 hash
) internal {
_getWormholeConsumedVAAsStorage()[hash] = true;
}

Expand Down
Loading

0 comments on commit 2e23893

Please sign in to comment.