IExecutable
Interface
Overview
The IExecutable
interface defines a standard for cross-chain or inter-process executable message handlers. Implementers of this interface must define how external execution requests, identified by a source and an action, are processed.
Interface
interface IExecutable {
function execute(string calldata _sourceChainName, string calldata _sourceAddress, string calldata action, bytes calldata _payload) external;
}
Function Details
execute
function execute(
string calldata _sourceChainName,
string calldata _sourceAddress,
string calldata _action,
bytes calldata _payload
) external;
_sourceChainName
: The name of the chain or system from which the execution request originates._sourceAddress
: The address of the sender on the source chain. This is typically used for access control or auditing._action
: An identifier for the message type._payload
: Data required to perform the action. This should be decoded and validated by the implementer depending on the message type.
Access Control
It is expected that only authorized callers (e.g. known source addresses, expected source chains, Reactor Gateway) are allowed to call this function. Implementers must enforce appropriate access control within their contract.
Usage Pattern
Contracts implementing IExecutable
typically:
- Decode the
payload
based on theaction
. - Validate the
sourceChainName
,sourceAddress
, andmsg.sender
. - Execute the corresponding logic based on the action type.
Example Implementation
contract MyExecutable is IExecutable {
address public reactorGateway;
function execute(
string calldata _sourceChainName,
string calldata _sourceAddress,
string calldata _action,
bytes calldata _payload
) external {
require(msg.sender == reactorGateway, "Unauthorized caller");
require(_sourceChainName == "ethereum", "Unauthorized source chain");
require(_sourceAddress == "0xAddress", "Unauthorized source address");
if (action == "cross_chain") {
(address recipient, uint256 amount) = abi.decode(payload, (address, uint256));
_mint(recipient, amount);
} else {
revert("Unknown action");
}
}
function _mint(address to, uint256 amount) internal {
// Minting logic here
}
}
Security Considerations
- Always validate the caller of
execute
to avoid arbitrary execution. - Decode and validate payloads rigorously to prevent data corruption or unexpected behavior.
- Use defensive programming practices when working with external inputs.
Last updated on