-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warp contract implementation (#718)
* Add warp contract implementation * Cleanup predicate test * Fix new function signature * Replace invalid fuzz test with unit test * Add chain config to enable warp API for warp e2e test * remove unused var * Add experimental warning and move warp precompile to x/ package * fix warning label * Fix warning * vm test nits * Improve sendWarpMessenger sol comment * more vm warp test nits * Move warp params into params package * More vm warp test nits * Address more PR comments * Remove triggerTx2 * Add check for expected topics from sendWarpMessage log * Fix config test * Fix incorrect replace * remove unnecessary echo * Address comments * Address comments * Address PR comments * Improve comments * Convert [32]byte type to common.Hash * Add base cost for getVerifiedWarpMessage * fix require equal type check * Fix updated awm message format * Update warp message format * Move IWarpMessenger.sol to interfaces/ * Add newline to warp genesis * uncomment assertion * Fix broken links in README
- Loading branch information
1 parent
402510e
commit 5dbfa82
Showing
27 changed files
with
3,660 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./interfaces/IWarpMessenger.sol"; | ||
|
||
contract ExampleWarp { | ||
address constant WARP_ADDRESS = 0x0200000000000000000000000000000000000005; | ||
WarpMessenger warp = WarpMessenger(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); | ||
} | ||
|
||
|
||
// validateWarpMessage retrieves the warp message attached to the transaction and verifies all of its attributes. | ||
function validateWarpMessage( | ||
bytes32 originChainID, | ||
address originSenderAddress, | ||
bytes32 destinationChainID, | ||
address destinationAddress, | ||
bytes calldata payload | ||
) external view { | ||
(WarpMessage memory message, bool exists) = warp.getVerifiedWarpMessage(); | ||
require(exists); | ||
require(message.originChainID == originChainID); | ||
require(message.originSenderAddress == originSenderAddress); | ||
require(message.destinationChainID == destinationChainID); | ||
require(message.destinationAddress == destinationAddress); | ||
require(keccak256(message.payload) == keccak256(payload)); | ||
} | ||
|
||
// validateGetBlockchainID checks that the blockchainID returned by warp matches the argument | ||
function validateGetBlockchainID(bytes32 blockchainID) external view { | ||
require(blockchainID == warp.getBlockchainID()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// (c) 2022-2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
struct WarpMessage { | ||
bytes32 originChainID; | ||
address originSenderAddress; | ||
bytes32 destinationChainID; | ||
address destinationAddress; | ||
bytes payload; | ||
} | ||
|
||
interface WarpMessenger { | ||
event SendWarpMessage( | ||
bytes32 indexed destinationChainID, | ||
address indexed destinationAddress, | ||
address indexed sender, | ||
bytes message | ||
); | ||
|
||
// sendWarpMessage emits a request for the subnet to send a warp message from [msg.sender] | ||
// with the specified parameters. | ||
// This emits a SendWarpMessage log from the precompile. When the corresponding block is accepted | ||
// the Accept hook of the Warp precompile is invoked with all accepted logs emitted by the Warp | ||
// 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; | ||
|
||
// getVerifiedWarpMessage parses the pre-verified warp message in the | ||
// predicate storage slots as a WarpMessage and returns it to the caller. | ||
// Returns false if no such predicate exists. | ||
function getVerifiedWarpMessage() | ||
external view | ||
returns (WarpMessage calldata message, bool exists); | ||
|
||
// Note: getVerifiedWarpMessage takes no arguments because it returns a single verified | ||
// message that is encoded in the predicate (inside the tx access list) of the transaction. | ||
// The alternative design to this is to verify messages during the EVM's execution in which | ||
// case there would be no predicate and the block would encode the hits/misses that occur | ||
// throughout its execution. | ||
// This would result in the following alternative function signature: | ||
// function verifyMessage(bytes calldata signedWarpMsg) external returns (WarpMessage calldata message); | ||
|
||
// 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 | ||
// and is not related to the Ethereum ChainID. | ||
function getBlockchainID() external view returns (bytes32 blockchainID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.