Skip to content

Commit

Permalink
Remove destinationAddress and destinationChainID from Warp Message
Browse files Browse the repository at this point in the history
  • Loading branch information
nytzuga committed Oct 2, 2023
1 parent 075dded commit 8d8de76
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 205 deletions.
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);

// 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

0 comments on commit 8d8de76

Please sign in to comment.