As the L2 and sidechain ecosystem grows, it will become increasingly useful for accounts to be able to pass messages between environments.
Recently, @maurelian suggested a standard interface for cross-domain ERC20 transfers. In this post, I suggest that similar standardization for cross-domain messages would be useful.
There is some early discussion in this Twitter thread, but since no one has mentioned an existing standard yet, I figured I’d kick off a discussion here.
Motivation
There are multiple layer 2 and sidechain solutions being developed in parallel or already in production. Several have already developed systems for passing messages between their network and others (for example: xDai’s AMB, Matic’s Data Tunnel, and Abitrum’s EthBridge). However, their interface’s are inconsistent, which creates an unnecessarily complicated user/developer experience.
This proposal seeks to establish a standard interface to be used for passing messages between environments.
The proposal does not seek to standardize the method by which messages are validated, this should be at the discretion of the implementation.
Specification
Note: this is rough and will probably need to be revised
interface messageBridge {
/**********
* Events *
**********/
/*
@dev Emits when a new message is created
@param from Address that called passMessage() on source chain
@param to The address that the message should be passed to on the destination chain
@param chainId The ID of the destination chain
@param data The message to be passed
*/
event newMessage(
address from,
address to,
uint256 chainId,
bytes32 messageId,,
bytes data
);
/*
@dev Emits when a new proof is published
@param messageId ID of the message the proof is for
@param proof Proof that the message is valid, to be used as the _proof parameter for executeMessage()
*/
event newProof(
bytes32 messageId,
bytes32 proof
);
/*
@dev Emits when a message is executed
@param from Address that called passMessage() on source chain
@param to The address that the message was passed to on the destination chain
@param chainId The ID of the source chain
@param data The message that was passed
*/
event messageExecuted(
address from,
address to,
uint256 chainId,
bytes32 messageId,
bytes data
);
/********************
* Public Functions *
********************/
/*
@dev Passes a message from source chain to destination chain and returns a unique message ID
@param _to The address that the message should be passed to on the destination chain
@param chainId The ID of the destination chain
@param data The message to be passed
@returns _messageId unique ID for this message
*/
function passMessage(
address _to,
uint256 _destinationChainId,
bytes memory _data
)
external
returns (bytes32 _messageId);
/*
@dev asks the contract for proof that a given message is valid
@param _messageId ID of the message to be validated
@notice This may be called on the source or destination chain, depending on the implementation
*/
function requestProof(
bytes32 _messageId
)
external;
/*
@dev Returns proof that a given message is valid
@param _messageId ID of the message to be validated
@returns _proof Proof that the message is valid, to be used as the _proof parameter for executeMessage()
@notice This may be called on the source or destination chain, depending on the implementation
*/
function getProof(
bytes32 _messageId
)
external
returns (bytes32 _proof);
/*
@dev Executes a given message on destination chain, only if the given proof is valid
@param _from The address that called passMessage() on the source chain
@param _to The address that the message should be passed to on the destination chain
@param _chainId The ID of the source chain
@param _data The message that was passed
@param _proof Proof that the message is valid
*/
function executeMessage(
address _from,
address _to,
uint256 _sourceChainId,
bytes memory _data,
bytes32 _proof
)
external;
}
Request For Feedback
This proposal is early and quite rough. Constructive feedback would be very much appreciated. Have at it!