Skip to content

Update warp msg format #1686

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 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
BCLookup: m,
Metrics: vmMetrics,

WarpSigner: warp.NewSigner(m.StakingBLSKey, chainParams.ID),
WarpSigner: warp.NewSigner(m.StakingBLSKey, m.NetworkID, chainParams.ID),

ValidatorState: m.validatorState,
ChainDataDir: chainDataDir,
Expand Down
53 changes: 26 additions & 27 deletions proto/pb/warp/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/warp/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ service Signer {
}

message SignRequest {
bytes source_chain_id = 1;
bytes destination_chain_id = 2;
uint32 network_id = 1;
bytes source_chain_id = 2;
bytes payload = 3;
}

Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/warp/gwarp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func NewClient(client pb.SignerClient) *Client {

func (c *Client) Sign(unsignedMsg *warp.UnsignedMessage) ([]byte, error) {
resp, err := c.client.Sign(context.Background(), &pb.SignRequest{
SourceChainId: unsignedMsg.SourceChainID[:],
DestinationChainId: unsignedMsg.DestinationChainID[:],
Payload: unsignedMsg.Payload,
NetworkId: unsignedMsg.NetworkID,
SourceChainId: unsignedMsg.SourceChainID[:],
Payload: unsignedMsg.Payload,
})
if err != nil {
return nil, err
Expand Down
7 changes: 1 addition & 6 deletions vms/platformvm/warp/gwarp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ func (s *Server) Sign(_ context.Context, unsignedMsg *pb.SignRequest) (*pb.SignR
return nil, err
}

destinationChainID, err := ids.ToID(unsignedMsg.DestinationChainId)
if err != nil {
return nil, err
}

msg, err := warp.NewUnsignedMessage(
unsignedMsg.NetworkId,
sourceChainID,
destinationChainID,
unsignedMsg.Payload,
)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions vms/platformvm/warp/gwarp/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"
Expand All @@ -17,11 +18,12 @@ import (
)

type testSigner struct {
client *Client
server warp.Signer
sk *bls.SecretKey
chainID ids.ID
closeFn func()
client *Client
server warp.Signer
sk *bls.SecretKey
networkID uint32
chainID ids.ID
closeFn func()
}

func setupSigner(t testing.TB) *testSigner {
Expand All @@ -33,9 +35,10 @@ func setupSigner(t testing.TB) *testSigner {
chainID := ids.GenerateTestID()

s := &testSigner{
server: warp.NewSigner(sk, chainID),
sk: sk,
chainID: chainID,
server: warp.NewSigner(sk, constants.UnitTestID, chainID),
sk: sk,
networkID: constants.UnitTestID,
chainID: chainID,
}

listener, err := grpcutils.NewListener()
Expand Down Expand Up @@ -63,7 +66,7 @@ func setupSigner(t testing.TB) *testSigner {
func TestInterface(t *testing.T) {
for _, test := range warp.SignerTests {
s := setupSigner(t)
test(t, s.client, s.sk, s.chainID)
test(t, s.client, s.sk, s.networkID, s.chainID)
s.closeFn()
}
}
3 changes: 2 additions & 1 deletion vms/platformvm/warp/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
)

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

unsignedMsg, err := NewUnsignedMessage(
ids.GenerateTestID(),
constants.UnitTestID,
ids.GenerateTestID(),
[]byte("payload"),
)
Expand Down
6 changes: 6 additions & 0 deletions vms/platformvm/warp/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Signature interface {
Verify(
ctx context.Context,
msg *UnsignedMessage,
networkID uint32,
pChainState validators.State,
pChainHeight uint64,
quorumNum uint64,
Expand Down Expand Up @@ -67,11 +68,16 @@ func (s *BitSetSignature) NumSigners() (int, error) {
func (s *BitSetSignature) Verify(
ctx context.Context,
msg *UnsignedMessage,
networkID uint32,
pChainState validators.State,
pChainHeight uint64,
quorumNum uint64,
quorumDen uint64,
) error {
if msg.NetworkID != networkID {
return errWrongNetworkID
}

subnetID, err := pChainState.GetSubnetID(ctx, msg.SourceChainID)
if err != nil {
return err
Expand Down
Loading