Skip to content

Change switchboard and socket address types to bytes32 #135

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

Merged
merged 3 commits into from
May 21, 2025
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
8 changes: 4 additions & 4 deletions contracts/evmx/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract contract ForwarderStorage is IForwarder {
/// @notice chain slug on which the contract is deployed
uint32 public chainSlug;
/// @notice on-chain address associated with this forwarder
address public onChainAddress;
bytes32 public onChainAddress;

// slot 51
/// @notice caches the latest async promise address for the last call
Expand Down Expand Up @@ -51,7 +51,7 @@ contract Forwarder is ForwarderStorage, Initializable, AddressResolverUtil {
/// @param addressResolver_ address resolver contract
function initialize(
uint32 chainSlug_,
address onChainAddress_,
bytes32 onChainAddress_,
address addressResolver_
) public initializer {
chainSlug = chainSlug_;
Expand Down Expand Up @@ -79,7 +79,7 @@ contract Forwarder is ForwarderStorage, Initializable, AddressResolverUtil {

/// @notice Returns the on-chain address associated with this forwarder.
/// @return The on-chain address.
function getOnChainAddress() external view returns (address) {
function getOnChainAddress() external view returns (bytes32) {
return onChainAddress;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ contract Forwarder is ForwarderStorage, Initializable, AddressResolverUtil {
) = IAppGateway(msg.sender).getOverrideParams();

// get the switchboard address from the watcher precompile config
address switchboard = watcherPrecompileConfig().switchboards(chainSlug, sbType);
bytes32 switchboard = watcherPrecompileConfig().switchboards(chainSlug, sbType);

// Queue the call in the middleware.
deliveryHelper__().queue(
Expand Down
15 changes: 9 additions & 6 deletions contracts/evmx/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../interfaces/IPromise.sol";

import {InvalidPromise, FeesNotSet, AsyncModifierNotUsed} from "../../utils/common/Errors.sol";
import {FAST} from "../../utils/common/Constants.sol";
import { toBytes32Format } from "../../utils/common/Converters.sol";

/// @title AppGatewayBase
/// @notice Abstract contract for the app gateway
Expand Down Expand Up @@ -122,7 +123,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
/// @param isValid Boolean flag indicating whether the contract is authorized (true) or not (false)
/// @dev This function retrieves the onchain address using the contractId and chainSlug, then calls the watcher precompile to update the plug's validity status
function _setValidPlug(uint32 chainSlug_, bytes32 contractId, bool isValid) internal {
address onchainAddress = getOnChainAddress(contractId, chainSlug_);
bytes32 onchainAddress = getOnChainAddress(contractId, chainSlug_);
watcherPrecompileConfig().setIsValidPlug(chainSlug_, onchainAddress, isValid);
}

Expand Down Expand Up @@ -154,15 +155,17 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
isValidPromise[asyncPromise] = true;
onCompleteData = abi.encode(chainSlug_, true);

bytes32 switchboardAddress = watcherPrecompileConfig().switchboards(chainSlug_, sbType);

QueuePayloadParams memory queuePayloadParams = QueuePayloadParams({
chainSlug: chainSlug_,
callType: CallType.DEPLOY,
isParallel: overrideParams.isParallelCall,
isPlug: isPlug_,
writeFinality: overrideParams.writeFinality,
asyncPromise: asyncPromise,
switchboard: watcherPrecompileConfig().switchboards(chainSlug_, sbType),
target: address(0),
switchboard: switchboardAddress,
target: toBytes32Format(address(0)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just do target: bytes32(0) instead of initializing address and then converting to bytes32.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging anyway since this is small

appGateway: address(this),
gasLimit: overrideParams.gasLimit,
value: overrideParams.value,
Expand Down Expand Up @@ -190,7 +193,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
/// @notice Gets the socket address
/// @param chainSlug_ The chain slug
/// @return socketAddress_ The socket address
function getSocketAddress(uint32 chainSlug_) public view returns (address) {
function getSocketAddress(uint32 chainSlug_) public view returns (bytes32) {
return watcherPrecompileConfig().sockets(chainSlug_);
}

Expand All @@ -201,9 +204,9 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
function getOnChainAddress(
bytes32 contractId_,
uint32 chainSlug_
) public view returns (address onChainAddress) {
) public view returns (bytes32 onChainAddress) {
if (forwarderAddresses[contractId_][chainSlug_] == address(0)) {
return address(0);
return bytes32(0x0);
}

onChainAddress = IForwarder(forwarderAddresses[contractId_][chainSlug_])
Expand Down
2 changes: 1 addition & 1 deletion contracts/evmx/interfaces/IAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IAppGateway {
function getOnChainAddress(
bytes32 contractId_,
uint32 chainSlug_
) external view returns (address onChainAddress);
) external view returns (bytes32 onChainAddress);

/// @notice get the forwarder address of a contract
/// @param contractId_ The contract id
Expand Down
2 changes: 1 addition & 1 deletion contracts/evmx/interfaces/IForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity ^0.8.21;
interface IForwarder {
/// @notice Returns the on-chain address of the contract being referenced
/// @return The on-chain address
function getOnChainAddress() external view returns (address);
function getOnChainAddress() external view returns (bytes32);

/// @notice Returns the chain slug of the on chain contract
/// @return The chain slug
Expand Down
24 changes: 12 additions & 12 deletions contracts/evmx/interfaces/IWatcherPrecompileConfig.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import {AppGatewayConfig, PlugConfig} from "../../utils/common/Structs.sol";
import {AppGatewayConfig, PlugConfigGeneric} from "../../utils/common/Structs.sol";

/// @title IWatcherPrecompileConfig
/// @notice Interface for the Watcher Precompile system that handles payload verification and execution
Expand All @@ -11,16 +11,16 @@ interface IWatcherPrecompileConfig {
function evmxSlug() external view returns (uint32);

/// @notice Maps chain slug to their associated switchboard
function switchboards(uint32 chainSlug, bytes32 sbType) external view returns (address);
function switchboards(uint32 chainSlug, bytes32 sbType) external view returns (bytes32);

/// @notice Maps chain slug to their associated socket
function sockets(uint32 chainSlug) external view returns (address);
function sockets(uint32 chainSlug) external view returns (bytes32);

/// @notice Maps chain slug to their associated contract factory plug
function contractFactoryPlug(uint32 chainSlug) external view returns (address);
function contractFactoryPlug(uint32 chainSlug) external view returns (bytes32);

/// @notice Maps chain slug to their associated fees plug
function feesPlug(uint32 chainSlug) external view returns (address);
function feesPlug(uint32 chainSlug) external view returns (bytes32);

/// @notice Maps nonce to whether it has been used
function isNonceUsed(uint256 nonce) external view returns (bool);
Expand All @@ -29,28 +29,28 @@ interface IWatcherPrecompileConfig {
function isValidPlug(
address appGateway,
uint32 chainSlug,
address plug
bytes32 plug
) external view returns (bool);

/// @notice Sets the switchboard for a network
function setSwitchboard(uint32 chainSlug_, bytes32 sbType_, address switchboard_) external;
function setSwitchboard(uint32 chainSlug_, bytes32 sbType_, bytes32 switchboard_) external;

/// @notice Sets valid plugs for each chain slug
/// @dev This function is used to verify if a plug deployed on a chain slug is valid connection to the app gateway
function setIsValidPlug(uint32 chainSlug_, address plug_, bool isValid_) external;
function setIsValidPlug(uint32 chainSlug_, bytes32 plug_, bool isValid_) external;

/// @notice Retrieves the configuration for a specific plug on a network
function getPlugConfigs(
uint32 chainSlug_,
address plug_
) external view returns (bytes32, address);
bytes32 plug_
) external view returns (bytes32, bytes32);

/// @notice Verifies connections between components
function verifyConnections(
uint32 chainSlug_,
address target_,
bytes32 target_,
address appGateway_,
address switchboard_,
bytes32 switchboard_,
address middleware_
) external view;

Expand Down
4 changes: 2 additions & 2 deletions contracts/evmx/payload-delivery/FeesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ contract FeesManager is FeesManagerStorage, Initializable, Ownable, AddressResol
return transmitterCredits > watcherFees ? transmitterCredits - watcherFees : 0;
}

function _getSwitchboard(uint32 chainSlug_) internal view returns (address) {
function _getSwitchboard(uint32 chainSlug_) internal view returns (bytes32) {
return watcherPrecompile__().watcherPrecompileConfig__().switchboards(chainSlug_, sbType);
}

Expand Down Expand Up @@ -483,7 +483,7 @@ contract FeesManager is FeesManagerStorage, Initializable, Ownable, AddressResol
deliveryHelper__().queue(queuePayloadParams);
}

function _getFeesPlugAddress(uint32 chainSlug_) internal view returns (address) {
function _getFeesPlugAddress(uint32 chainSlug_) internal view returns (bytes32) {
return watcherPrecompileConfig().feesPlug(chainSlug_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract contract DeliveryUtils is
/// @notice Gets the payload delivery plug address
/// @param chainSlug_ The chain identifier
/// @return address The address of the payload delivery plug
function getDeliveryHelperPlugAddress(uint32 chainSlug_) public view returns (address) {
function getDeliveryHelperPlugAddress(uint32 chainSlug_) public view returns (bytes32) {
return watcherPrecompileConfig().contractFactoryPlug(chainSlug_);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/evmx/payload-delivery/app-gateway/RequestQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract contract RequestQueue is DeliveryUtils {

function _createDeployPayloadDetails(
QueuePayloadParams memory queuePayloadParams_
) internal returns (bytes memory payload, address target) {
) internal returns (bytes memory payload, bytes32 target) {
bytes32 salt = keccak256(
abi.encode(queuePayloadParams_.appGateway, queuePayloadParams_.chainSlug, saltCounter++)
);
Expand Down Expand Up @@ -204,7 +204,7 @@ abstract contract RequestQueue is DeliveryUtils {
QueuePayloadParams memory queuePayloadParams_
) internal returns (PayloadSubmitParams memory) {
bytes memory payload = queuePayloadParams_.payload;
address target = queuePayloadParams_.target;
bytes32 target = queuePayloadParams_.target;
if (queuePayloadParams_.callType == CallType.DEPLOY) {
(payload, target) = _createDeployPayloadDetails(queuePayloadParams_);
}
Expand Down
52 changes: 26 additions & 26 deletions contracts/evmx/watcherPrecompile/WatcherPrecompileConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Ownable} from "solady/auth/Ownable.sol";
import "../interfaces/IWatcherPrecompileConfig.sol";
import {AddressResolverUtil} from "../AddressResolverUtil.sol";
import {InvalidWatcherSignature, NonceUsed} from "../../utils/common/Errors.sol";
import "./core/WatcherIdUtils.sol";
import {toBytes32Format} from "../../utils/common/Converters.sol";

/// @title WatcherPrecompileConfig
/// @notice Configuration contract for the Watcher Precompile system
Expand All @@ -29,28 +29,28 @@ contract WatcherPrecompileConfig is

// slot 102: _plugConfigs
/// @notice Maps network and plug to their configuration
/// @dev chainSlug => plug => PlugConfig
mapping(uint32 => mapping(address => PlugConfig)) internal _plugConfigs;
/// @dev chainSlug => plug => PlugConfigGeneric
mapping(uint32 => mapping(bytes32 => PlugConfigGeneric)) internal _plugConfigs;

// slot 103: switchboards
/// @notice Maps chain slug to their associated switchboard
/// @dev chainSlug => sb type => switchboard address
mapping(uint32 => mapping(bytes32 => address)) public switchboards;
mapping(uint32 => mapping(bytes32 => bytes32)) public switchboards;

// slot 104: sockets
/// @notice Maps chain slug to their associated socket
/// @dev chainSlug => socket address
mapping(uint32 => address) public sockets;
mapping(uint32 => bytes32) public sockets;

// slot 105: contractFactoryPlug
/// @notice Maps chain slug to their associated contract factory plug
/// @dev chainSlug => contract factory plug address
mapping(uint32 => address) public contractFactoryPlug;
mapping(uint32 => bytes32) public contractFactoryPlug;

// slot 106: feesPlug
/// @notice Maps chain slug to their associated fees plug
/// @dev chainSlug => fees plug address
mapping(uint32 => address) public feesPlug;
mapping(uint32 => bytes32) public feesPlug;

// slot 107: isNonceUsed
/// @notice Maps nonce to whether it has been used
Expand All @@ -59,19 +59,19 @@ contract WatcherPrecompileConfig is

// slot 108: isValidPlug
// appGateway => chainSlug => plug => isValid
mapping(address => mapping(uint32 => mapping(address => bool))) public isValidPlug;
mapping(address => mapping(uint32 => mapping(bytes32 => bool))) public isValidPlug;

/// @notice Emitted when a new plug is configured for an app gateway
/// @param appGatewayId The id of the app gateway
/// @param chainSlug The identifier of the destination network
/// @param plug The address of the plug
event PlugAdded(bytes32 appGatewayId, uint32 chainSlug, address plug);
event PlugAdded(bytes32 appGatewayId, uint32 chainSlug, bytes32 plug);

/// @notice Emitted when a switchboard is set for a network
/// @param chainSlug The identifier of the network
/// @param sbType The type of switchboard
/// @param switchboard The address of the switchboard
event SwitchboardSet(uint32 chainSlug, bytes32 sbType, address switchboard);
event SwitchboardSet(uint32 chainSlug, bytes32 sbType, bytes32 switchboard);

/// @notice Emitted when contracts are set for a network
/// @param chainSlug The identifier of the network
Expand All @@ -80,17 +80,17 @@ contract WatcherPrecompileConfig is
/// @param feesPlug The address of the fees plug
event OnChainContractSet(
uint32 chainSlug,
address socket,
address contractFactoryPlug,
address feesPlug
bytes32 socket,
bytes32 contractFactoryPlug,
bytes32 feesPlug
);

/// @notice Emitted when a valid plug is set for an app gateway
/// @param appGateway The address of the app gateway
/// @param chainSlug The identifier of the network
/// @param plug The address of the plug
/// @param isValid Whether the plug is valid
event IsValidPlugSet(address appGateway, uint32 chainSlug, address plug, bool isValid);
event IsValidPlugSet(address appGateway, uint32 chainSlug, bytes32 plug, bool isValid);

error InvalidGateway();
error InvalidSwitchboard();
Expand Down Expand Up @@ -124,7 +124,7 @@ contract WatcherPrecompileConfig is

for (uint256 i = 0; i < configs_.length; i++) {
// Store the plug configuration for this network and plug
_plugConfigs[configs_[i].chainSlug][configs_[i].plug] = PlugConfig({
_plugConfigs[configs_[i].chainSlug][configs_[i].plug] = PlugConfigGeneric({
appGatewayId: configs_[i].appGatewayId,
switchboard: configs_[i].switchboard
});
Expand All @@ -137,9 +137,9 @@ contract WatcherPrecompileConfig is
/// @param chainSlug_ The identifier of the network
function setOnChainContracts(
uint32 chainSlug_,
address socket_,
address contractFactoryPlug_,
address feesPlug_
bytes32 socket_,
bytes32 contractFactoryPlug_,
bytes32 feesPlug_
) external onlyOwner {
sockets[chainSlug_] = socket_;
contractFactoryPlug[chainSlug_] = contractFactoryPlug_;
Expand All @@ -155,7 +155,7 @@ contract WatcherPrecompileConfig is
function setSwitchboard(
uint32 chainSlug_,
bytes32 sbType_,
address switchboard_
bytes32 switchboard_
) external onlyOwner {
switchboards[chainSlug_][sbType_] = switchboard_;
emit SwitchboardSet(chainSlug_, sbType_, switchboard_);
Expand All @@ -167,7 +167,7 @@ contract WatcherPrecompileConfig is
/// @param chainSlug_ The identifier of the network
/// @param plug_ The address of the plug
/// @param isValid_ Whether the plug is valid
function setIsValidPlug(uint32 chainSlug_, address plug_, bool isValid_) external {
function setIsValidPlug(uint32 chainSlug_, bytes32 plug_, bool isValid_) external {
isValidPlug[msg.sender][chainSlug_][plug_] = isValid_;
emit IsValidPlugSet(msg.sender, chainSlug_, plug_, isValid_);
}
Expand All @@ -180,8 +180,8 @@ contract WatcherPrecompileConfig is
/// @dev Returns zero addresses if configuration doesn't exist
function getPlugConfigs(
uint32 chainSlug_,
address plug_
) public view returns (bytes32, address) {
bytes32 plug_
) public view returns (bytes32, bytes32) {
return (
_plugConfigs[chainSlug_][plug_].appGatewayId,
_plugConfigs[chainSlug_][plug_].switchboard
Expand All @@ -196,9 +196,9 @@ contract WatcherPrecompileConfig is
/// @param switchboard_ The address of the switchboard
function verifyConnections(
uint32 chainSlug_,
address target_,
bytes32 target_,
address appGateway_,
address switchboard_,
bytes32 switchboard_,
address middleware_
) external view {
// if target is contractFactoryPlug, return
Expand All @@ -207,8 +207,8 @@ contract WatcherPrecompileConfig is
middleware_ == address(deliveryHelper__()) && target_ == contractFactoryPlug[chainSlug_]
) return;

(bytes32 appGatewayId, address switchboard) = getPlugConfigs(chainSlug_, target_);
if (appGatewayId != WatcherIdUtils.encodeAppGatewayId(appGateway_)) revert InvalidGateway();
(bytes32 appGatewayId, bytes32 switchboard) = getPlugConfigs(chainSlug_, target_);
if (appGatewayId != toBytes32Format(appGateway_)) revert InvalidGateway();
if (switchboard != switchboard_) revert InvalidSwitchboard();
}

Expand Down
Loading