Skip to content
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

Remove destinationAddress and destinationChainID from Warp Message #920

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 6 additions & 24 deletions contracts/contracts/ExampleWarp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,43 @@ contract ExampleWarp {
address constant WARP_ADDRESS = 0x0200000000000000000000000000000000000005;
IWarpMessenger warp = IWarpMessenger(WARP_ADDRESS);

// sendWarpMessage sends a warp message to the specified destination chain and address pair containing the payload
function sendWarpMessage(
bytes32 destinationChainID,
address destinationAddress,
bytes calldata payload
) external {
warp.sendWarpMessage(destinationChainID, destinationAddress, payload);
// sendWarpMessage sends a warp message containing the payload
function sendWarpMessage(bytes calldata payload) external {
warp.sendWarpMessage(payload);
}

// validateWarpMessage retrieves the warp message attached to the transaction and verifies all of its attributes.
function validateWarpMessage(
uint32 index,
bytes32 sourceChainID,
address originSenderAddress,
bytes32 destinationChainID,
address destinationAddress,
bytes calldata payload
) external view {
(WarpMessage memory message, bool valid) = warp.getVerifiedWarpMessage(index);
require(valid);
require(message.sourceChainID == sourceChainID);
require(message.originSenderAddress == originSenderAddress);
require(message.destinationChainID == destinationChainID);
require(message.destinationAddress == destinationAddress);
require(keccak256(message.payload) == keccak256(payload));
}

function validateInvalidWarpMessage(
uint32 index
) external view {
function validateInvalidWarpMessage(uint32 index) external view {
(WarpMessage memory message, bool valid) = warp.getVerifiedWarpMessage(index);
require(!valid);
require(message.sourceChainID == bytes32(0));
require(message.originSenderAddress == address(0));
require(message.destinationChainID == bytes32(0));
require(message.destinationAddress == address(0));
require(keccak256(message.payload) == keccak256(bytes("")));
}

// validateWarpBlockHash retrieves the warp block hash attached to the transaction and verifies it matches the
// expected block hash.
function validateWarpBlockHash(
uint32 index,
bytes32 sourceChainID,
bytes32 blockHash
) external view {
function validateWarpBlockHash(uint32 index, bytes32 sourceChainID, bytes32 blockHash) external view {
(WarpBlockHash memory warpBlockHash, bool valid) = warp.getVerifiedWarpBlockHash(index);
require(valid);
require(warpBlockHash.sourceChainID == sourceChainID);
require(warpBlockHash.blockHash == blockHash);
}

function validateInvalidWarpBlockHash(
uint32 index
) external view {
function validateInvalidWarpBlockHash(uint32 index) external view {
(WarpBlockHash memory warpBlockHash, bool valid) = warp.getVerifiedWarpBlockHash(index);
require(!valid);
require(warpBlockHash.sourceChainID == bytes32(0));
Expand Down
25 changes: 6 additions & 19 deletions contracts/contracts/interfaces/IWarpMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pragma solidity ^0.8.0;
struct WarpMessage {
bytes32 sourceChainID;
address originSenderAddress;
bytes32 destinationChainID;
address destinationAddress;
bytes payload;
}

Expand All @@ -19,12 +17,7 @@ struct WarpBlockHash {
}

interface IWarpMessenger {
event SendWarpMessage(
bytes32 indexed destinationChainID,
address indexed destinationAddress,
address indexed sender,
bytes message
);
event SendWarpMessage(address indexed sender, bytes message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

note: since we removed two index fields with this change, we could include the unsigned warp message ID if we want to.

This should be a separate change if we want it though. cc @michaelkaplan13 @ceyonur

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup that's what I thought after seeing this lol. It would be a great change!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that'd be a great idea. To confirm, that's the ID used for querying validators for their signature of a specific message right?


// sendWarpMessage emits a request for the subnet to send a warp message from [msg.sender]
// with the specified parameters.
Expand All @@ -33,29 +26,23 @@ interface IWarpMessenger {
// precompile.
// Each validator then adds the UnsignedWarpMessage encoded in the log to the set of messages
// it is willing to sign for an off-chain relayer to aggregate Warp signatures.
function sendWarpMessage(
bytes32 destinationChainID,
address destinationAddress,
bytes calldata payload
) external;
function sendWarpMessage(bytes calldata payload) external;

// getVerifiedWarpMessage parses the pre-verified warp message in the
// predicate storage slots as a WarpMessage and returns it to the caller.
// If the message exists and passes verification, returns the verified message
// and true.
// Otherwise, returns false and the empty value for the message.
function getVerifiedWarpMessage(uint32 index)
external view
returns (WarpMessage calldata message, bool valid);
function getVerifiedWarpMessage(uint32 index) external view returns (WarpMessage calldata message, bool valid);

// getVerifiedWarpBlockHash parses the pre-verified WarpBlockHash message in the
// predicate storage slots as a WarpBlockHash message and returns it to the caller.
// If the message exists and passes verification, returns the verified message
// and true.
// Otherwise, returns false and the empty value for the message.
function getVerifiedWarpBlockHash(uint32 index)
external view
returns (WarpBlockHash calldata warpBlockHash, bool valid);
function getVerifiedWarpBlockHash(
uint32 index
) external view returns (WarpBlockHash calldata warpBlockHash, bool valid);

// getBlockchainID returns the snow.Context BlockchainID of this chain.
// This blockchainID is the hash of the transaction that created this blockchain on the P-Chain
Expand Down
20 changes: 0 additions & 20 deletions plugin/evm/ExampleWarp.abi
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
[
{
"inputs": [
{
"internalType": "bytes32",
"name": "destinationChainID",
"type": "bytes32"
},
{
"internalType": "address",
"name": "destinationAddress",
"type": "address"
},
{
"internalType": "bytes",
"name": "payload",
Expand Down Expand Up @@ -101,16 +91,6 @@
"name": "originSenderAddress",
"type": "address"
},
{
"internalType": "bytes32",
"name": "destinationChainID",
"type": "bytes32"
},
{
"internalType": "address",
"name": "destinationAddress",
"type": "address"
},
{
"internalType": "bytes",
"name": "payload",
Expand Down
Loading
Loading