-
Notifications
You must be signed in to change notification settings - Fork 275
Add warp contract implementation #718
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
ed77e1f
Add warp contract implementation
aaronbuchwald 15ef5de
Cleanup predicate test
aaronbuchwald 059d7f9
Fix new function signature
aaronbuchwald d955a11
Replace invalid fuzz test with unit test
aaronbuchwald 81520a5
Add chain config to enable warp API for warp e2e test
aaronbuchwald ee3c039
remove unused var
aaronbuchwald c70159e
Add experimental warning and move warp precompile to x/ package
aaronbuchwald 6a44f20
fix warning label
aaronbuchwald 72e0a1f
Fix warning
aaronbuchwald 8de1e35
vm test nits
aaronbuchwald 2c64fe6
Improve sendWarpMessenger sol comment
aaronbuchwald 51b0dee
more vm warp test nits
aaronbuchwald 8053091
Move warp params into params package
aaronbuchwald 2bfd284
More vm warp test nits
aaronbuchwald bcef7a9
Address more PR comments
aaronbuchwald 90adf6f
Remove triggerTx2
aaronbuchwald 99f43c7
Add check for expected topics from sendWarpMessage log
aaronbuchwald 70cd4ed
Merge branch 'master' into warp-contract
aaronbuchwald c023439
Fix config test
aaronbuchwald 4fbb599
Fix incorrect replace
aaronbuchwald b4a7056
remove unnecessary echo
aaronbuchwald e4ae637
Address comments
aaronbuchwald 119be31
Address comments
aaronbuchwald eb93a70
Address PR comments
aaronbuchwald 533bb58
Merge branch 'master' into warp-contract
aaronbuchwald 56d2322
Improve comments
aaronbuchwald 9507e18
Convert [32]byte type to common.Hash
aaronbuchwald 1ad4ea6
Add base cost for getVerifiedWarpMessage
aaronbuchwald 471d0bd
fix require equal type check
aaronbuchwald d3cf0e3
merge
aaronbuchwald 6b35ece
Fix updated awm message format
aaronbuchwald c64deae
Update warp message format
aaronbuchwald 19567d8
Move IWarpMessenger.sol to interfaces/
aaronbuchwald 26c0deb
Add newline to warp genesis
aaronbuchwald 063a82f
uncomment assertion
aaronbuchwald 744434c
Fix broken links in README
aaronbuchwald a607a84
Merge branch 'master' into warp-contract
aaronbuchwald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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()); | ||
} | ||
} | ||
aaronbuchwald marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.