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

Add warp contract implementation #718

Merged
merged 37 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ed77e1f
Add warp contract implementation
aaronbuchwald Jul 10, 2023
15ef5de
Cleanup predicate test
aaronbuchwald Jul 11, 2023
059d7f9
Fix new function signature
aaronbuchwald Jul 11, 2023
d955a11
Replace invalid fuzz test with unit test
aaronbuchwald Jul 11, 2023
81520a5
Add chain config to enable warp API for warp e2e test
aaronbuchwald Jul 11, 2023
ee3c039
remove unused var
aaronbuchwald Jul 11, 2023
c70159e
Add experimental warning and move warp precompile to x/ package
aaronbuchwald Jul 11, 2023
6a44f20
fix warning label
aaronbuchwald Jul 11, 2023
72e0a1f
Fix warning
aaronbuchwald Jul 11, 2023
8de1e35
vm test nits
aaronbuchwald Jul 20, 2023
2c64fe6
Improve sendWarpMessenger sol comment
aaronbuchwald Jul 20, 2023
51b0dee
more vm warp test nits
aaronbuchwald Jul 20, 2023
8053091
Move warp params into params package
aaronbuchwald Jul 20, 2023
2bfd284
More vm warp test nits
aaronbuchwald Jul 20, 2023
bcef7a9
Address more PR comments
aaronbuchwald Jul 20, 2023
90adf6f
Remove triggerTx2
aaronbuchwald Jul 20, 2023
99f43c7
Add check for expected topics from sendWarpMessage log
aaronbuchwald Jul 20, 2023
70cd4ed
Merge branch 'master' into warp-contract
aaronbuchwald Jul 20, 2023
c023439
Fix config test
aaronbuchwald Jul 20, 2023
4fbb599
Fix incorrect replace
aaronbuchwald Jul 20, 2023
b4a7056
remove unnecessary echo
aaronbuchwald Jul 20, 2023
e4ae637
Address comments
aaronbuchwald Jul 21, 2023
119be31
Address comments
aaronbuchwald Jul 24, 2023
eb93a70
Address PR comments
aaronbuchwald Jul 24, 2023
533bb58
Merge branch 'master' into warp-contract
aaronbuchwald Jul 24, 2023
56d2322
Improve comments
aaronbuchwald Jul 25, 2023
9507e18
Convert [32]byte type to common.Hash
aaronbuchwald Jul 25, 2023
1ad4ea6
Add base cost for getVerifiedWarpMessage
aaronbuchwald Jul 25, 2023
471d0bd
fix require equal type check
aaronbuchwald Jul 25, 2023
d3cf0e3
merge
aaronbuchwald Jul 26, 2023
6b35ece
Fix updated awm message format
aaronbuchwald Jul 26, 2023
c64deae
Update warp message format
aaronbuchwald Jul 27, 2023
19567d8
Move IWarpMessenger.sol to interfaces/
aaronbuchwald Jul 27, 2023
26c0deb
Add newline to warp genesis
aaronbuchwald Jul 27, 2023
063a82f
uncomment assertion
aaronbuchwald Jul 27, 2023
744434c
Fix broken links in README
aaronbuchwald Jul 31, 2023
a607a84
Merge branch 'master' into warp-contract
aaronbuchwald Jul 31, 2023
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
Prev Previous commit
Next Next commit
Update warp message format
  • Loading branch information
aaronbuchwald committed Jul 27, 2023
commit c64deae75a07ec1f0e913c1de47e99aaa9758efc
10 changes: 5 additions & 5 deletions contracts/contracts/IWarpMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ pragma solidity ^0.8.0;

struct WarpMessage {
bytes32 originChainID;
bytes32 originSenderAddress;
address originSenderAddress;
bytes32 destinationChainID;
bytes32 destinationAddress;
address destinationAddress;
bytes payload;
}

interface WarpMessenger {
event SendWarpMessage(
bytes32 indexed destinationChainID,
bytes32 indexed destinationAddress,
bytes32 indexed sender,
address indexed destinationAddress,
address indexed sender,
bytes message
);

Expand All @@ -30,7 +30,7 @@ interface WarpMessenger {
// it is willing to sign for an off-chain relayer to aggregate Warp signatures.
function sendWarpMessage(
bytes32 destinationChainID,
bytes32 destinationAddress,
address destinationAddress,
bytes calldata payload
) external;

Expand Down
12 changes: 6 additions & 6 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestSendWarpMessage(t *testing.T) {

warpSendMessageInput, err := warp.PackSendWarpMessage(warp.SendWarpMessageInput{
DestinationChainID: common.Hash(vm.ctx.CChainID),
DestinationAddress: testEthAddrs[1].Hash(),
DestinationAddress: testEthAddrs[1],
Payload: payload,
})
require.NoError(err)
Expand Down Expand Up @@ -143,9 +143,9 @@ func TestReceiveWarpMessage(t *testing.T) {
payload := utils.RandomBytes(100)

addressedPayload, err := warpPayload.NewAddressedPayload(
ids.ID(testEthAddrs[0].Hash()),
vm.ctx.CChainID,
ids.ID(testEthAddrs[1].Hash()),
testEthAddrs[0],
common.Hash(vm.ctx.CChainID),
testEthAddrs[1],
payload,
)
require.NoError(err)
Expand Down Expand Up @@ -236,9 +236,9 @@ func TestReceiveWarpMessage(t *testing.T) {
expectedOutput, err := warp.PackGetVerifiedWarpMessageOutput(warp.GetVerifiedWarpMessageOutput{
Message: warp.WarpMessage{
OriginChainID: common.Hash(vm.ctx.ChainID),
OriginSenderAddress: testEthAddrs[0].Hash(),
OriginSenderAddress: testEthAddrs[0],
DestinationChainID: common.Hash(vm.ctx.CChainID),
DestinationAddress: testEthAddrs[1].Hash(),
DestinationAddress: testEthAddrs[1],
Payload: payload,
},
Exists: true,
Expand Down
2 changes: 1 addition & 1 deletion tests/warp/warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var _ = ginkgo.Describe("[Warp]", ginkgo.Ordered, func() {

packedInput, err := warp.PackSendWarpMessage(warp.SendWarpMessageInput{
DestinationChainID: common.Hash(blockchainIDB),
DestinationAddress: fundedAddress.Hash(),
DestinationAddress: fundedAddress,
Payload: payload,
})
gomega.Expect(err).Should(gomega.BeNil())
Expand Down
12 changes: 6 additions & 6 deletions warp/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ package payload
import (
"fmt"

"github.com/ava-labs/avalanchego/ids"
"github.com/ethereum/go-ethereum/common"
)

// AddressedPayload defines the format for delivering a point to point message across VMs
// ie. (ChainA, AddressA) -> (ChainB, AddressB)
type AddressedPayload struct {
SourceAddress ids.ID `serialize:"true"`
DestinationChainID ids.ID `serialize:"true"`
DestinationAddress ids.ID `serialize:"true"`
Payload []byte `serialize:"true"`
SourceAddress common.Address `serialize:"true"`
DestinationChainID common.Hash `serialize:"true"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we change this from ids.ID to common.Hash?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a no-op change from one alias to the other, but changed it to common.Hash to stick with using the common package instead of one from each.

DestinationAddress common.Address `serialize:"true"`
Payload []byte `serialize:"true"`

bytes []byte
}

// NewAddressedPayload creates a new *AddressedPayload and initializes it.
func NewAddressedPayload(sourceAddress ids.ID, destinationChainID ids.ID, destinationAddress ids.ID, payload []byte) (*AddressedPayload, error) {
func NewAddressedPayload(sourceAddress common.Address, destinationChainID common.Hash, destinationAddress common.Address, payload []byte) (*AddressedPayload, error) {
ap := &AddressedPayload{
SourceAddress: sourceAddress,
DestinationChainID: destinationChainID,
Expand Down
15 changes: 8 additions & 7 deletions warp/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestAddressedPayload(t *testing.T) {
require := require.New(t)

addressedPayload, err := NewAddressedPayload(
ids.GenerateTestID(),
ids.GenerateTestID(),
ids.GenerateTestID(),
common.Address(ids.GenerateTestShortID()),
common.Hash(ids.GenerateTestID()),
common.Address(ids.GenerateTestShortID()),
[]byte("payload"),
)
require.NoError(err)
Expand All @@ -35,11 +36,11 @@ func TestParseAddressedPayloadJunk(t *testing.T) {
}

func TestParseAddressedPayload(t *testing.T) {
base64Payload := "AAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwoLDA=="
base64Payload := "AAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAEBQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAwoLDA=="
payload := &AddressedPayload{
SourceAddress: ids.ID{1, 2, 3},
DestinationChainID: ids.ID{4, 5, 6},
DestinationAddress: ids.ID{7, 8, 9},
SourceAddress: common.Address{1, 2, 3},
DestinationChainID: common.Hash{4, 5, 6},
DestinationAddress: common.Address{7, 8, 9},
Payload: []byte{10, 11, 12},
}

Expand Down
20 changes: 10 additions & 10 deletions x/warp/contract.abi
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
},
{
"indexed": true,
"internalType": "bytes32",
"internalType": "address",
"name": "destinationAddress",
"type": "bytes32"
"type": "address"
},
{
"indexed": true,
"internalType": "bytes32",
"internalType": "address",
"name": "sender",
"type": "bytes32"
"type": "address"
},
{
"indexed": false,
Expand Down Expand Up @@ -55,19 +55,19 @@
"type": "bytes32"
},
{
"internalType": "bytes32",
"internalType": "address",
"name": "originSenderAddress",
"type": "bytes32"
"type": "address"
},
{
"internalType": "bytes32",
"name": "destinationChainID",
"type": "bytes32"
},
{
"internalType": "bytes32",
"internalType": "address",
"name": "destinationAddress",
"type": "bytes32"
"type": "address"
},
{
"internalType": "bytes",
Expand Down Expand Up @@ -96,9 +96,9 @@
"type": "bytes32"
},
{
"internalType": "bytes32",
"internalType": "address",
"name": "destinationAddress",
"type": "bytes32"
"type": "address"
},
{
"internalType": "bytes",
Expand Down
25 changes: 12 additions & 13 deletions x/warp/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/precompile/contract"
Expand Down Expand Up @@ -57,9 +56,9 @@ var (
// WarpMessage is an auto generated low-level Go binding around an user-defined struct.
type WarpMessage struct {
OriginChainID common.Hash
OriginSenderAddress common.Hash
OriginSenderAddress common.Address
DestinationChainID common.Hash
DestinationAddress common.Hash
DestinationAddress common.Address
Payload []byte
}

Expand All @@ -70,7 +69,7 @@ type GetVerifiedWarpMessageOutput struct {

type SendWarpMessageInput struct {
DestinationChainID common.Hash
DestinationAddress common.Hash
DestinationAddress common.Address
Payload []byte
}

Expand Down Expand Up @@ -162,9 +161,9 @@ func getVerifiedWarpMessage(accessibleState contract.AccessibleState, caller com
packedOutput, err := PackGetVerifiedWarpMessageOutput(GetVerifiedWarpMessageOutput{
Message: WarpMessage{
OriginChainID: common.Hash(warpMessage.SourceChainID),
OriginSenderAddress: common.Hash(addressedPayload.SourceAddress),
DestinationChainID: common.Hash(addressedPayload.DestinationChainID),
DestinationAddress: common.Hash(addressedPayload.DestinationAddress),
OriginSenderAddress: addressedPayload.SourceAddress,
DestinationChainID: addressedPayload.DestinationChainID,
DestinationAddress: addressedPayload.DestinationAddress,
Payload: addressedPayload.Payload,
},
Exists: true,
Expand Down Expand Up @@ -218,15 +217,15 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add
var (
sourceChainID = accessibleState.GetSnowContext().ChainID
destinationChainID = inputStruct.DestinationChainID
sourceAddress = caller.Hash()
sourceAddress = caller
destinationAddress = inputStruct.DestinationAddress
payload = inputStruct.Payload
)

addressedPayload, err := warpPayload.NewAddressedPayload(
ids.ID(sourceAddress),
ids.ID(destinationChainID),
ids.ID(destinationAddress),
sourceAddress,
destinationChainID,
destinationAddress,
payload,
)
if err != nil {
Expand All @@ -247,8 +246,8 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add
[]common.Hash{
WarpABI.Events["SendWarpMessage"].ID,
destinationChainID,
destinationAddress,
sourceAddress,
destinationAddress.Hash(),
sourceAddress.Hash(),
},
unsignedWarpMessage.Bytes(),
accessibleState.GetBlockContext().Number().Uint64(),
Expand Down
20 changes: 10 additions & 10 deletions x/warp/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestSendWarpMessage(t *testing.T) {

sendWarpMessageInput, err := PackSendWarpMessage(SendWarpMessageInput{
DestinationChainID: common.Hash(destinationChainID),
DestinationAddress: receiverAddr.Hash(),
DestinationAddress: receiverAddr,
Payload: sendWarpMessagePayload,
})
require.NoError(t, err)
Expand Down Expand Up @@ -143,8 +143,8 @@ func TestSendWarpMessage(t *testing.T) {

// require.Equal(t, unsignedWarpMsg.DestinationChainID, destinationChainID)
aaronbuchwald marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, unsignedWarpMsg.SourceChainID, blockchainID)
require.Equal(t, addressedPayload.DestinationAddress, ids.ID(receiverAddr.Hash()))
require.Equal(t, addressedPayload.SourceAddress, ids.ID(callerAddr.Hash()))
require.Equal(t, addressedPayload.DestinationAddress, receiverAddr)
require.Equal(t, addressedPayload.SourceAddress, callerAddr)
require.Equal(t, addressedPayload.Payload, sendWarpMessagePayload)
},
},
Expand All @@ -161,9 +161,9 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
sourceChainID := ids.GenerateTestID()
packagedPayloadBytes := []byte("mcsorley")
addressedPayload, err := warpPayload.NewAddressedPayload(
ids.ID(sourceAddress.Hash()),
destinationChainID,
ids.ID(destinationAddress.Hash()),
sourceAddress,
common.Hash(destinationChainID),
destinationAddress,
packagedPayloadBytes,
)
require.NoError(t, err)
Expand All @@ -188,9 +188,9 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
res, err := PackGetVerifiedWarpMessageOutput(GetVerifiedWarpMessageOutput{
Message: WarpMessage{
OriginChainID: common.Hash(sourceChainID),
OriginSenderAddress: sourceAddress.Hash(),
OriginSenderAddress: sourceAddress,
DestinationChainID: common.Hash(destinationChainID),
DestinationAddress: destinationAddress.Hash(),
DestinationAddress: destinationAddress,
Payload: packagedPayloadBytes,
},
Exists: true,
Expand Down Expand Up @@ -226,9 +226,9 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
res, err := PackGetVerifiedWarpMessageOutput(GetVerifiedWarpMessageOutput{
Message: WarpMessage{
OriginChainID: common.Hash(sourceChainID),
OriginSenderAddress: sourceAddress.Hash(),
OriginSenderAddress: sourceAddress,
DestinationChainID: common.Hash(destinationChainID),
DestinationAddress: destinationAddress.Hash(),
DestinationAddress: destinationAddress,
Payload: packagedPayloadBytes,
},
Exists: true,
Expand Down
8 changes: 7 additions & 1 deletion x/warp/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
subnetEVMUtils "github.com/ava-labs/subnet-evm/utils"
predicateutils "github.com/ava-labs/subnet-evm/utils/predicate"
warpPayload "github.com/ava-labs/subnet-evm/warp/payload"
"github.com/ethereum/go-ethereum/common"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -80,7 +81,12 @@ func init() {
}

var err error
addressedPayload, err = warpPayload.NewAddressedPayload(ids.GenerateTestID(), destinationChainID, ids.GenerateTestID(), []byte{1, 2, 3})
addressedPayload, err = warpPayload.NewAddressedPayload(
common.Address(ids.GenerateTestShortID()),
common.Hash(destinationChainID),
common.Address(ids.GenerateTestShortID()),
[]byte{1, 2, 3},
)
if err != nil {
panic(err)
}
Expand Down