Skip to content

Commit 67df0d3

Browse files
Update warp msg format (#1686)
1 parent 4aa0d41 commit 67df0d3

14 files changed

+189
-98
lines changed

chains/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
475475
BCLookup: m,
476476
Metrics: vmMetrics,
477477

478-
WarpSigner: warp.NewSigner(m.StakingBLSKey, chainParams.ID),
478+
WarpSigner: warp.NewSigner(m.StakingBLSKey, m.NetworkID, chainParams.ID),
479479

480480
ValidatorState: m.validatorState,
481481
ChainDataDir: chainDataDir,

proto/pb/warp/message.pb.go

+26-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/warp/message.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ service Signer {
99
}
1010

1111
message SignRequest {
12-
bytes source_chain_id = 1;
13-
bytes destination_chain_id = 2;
12+
uint32 network_id = 1;
13+
bytes source_chain_id = 2;
1414
bytes payload = 3;
1515
}
1616

vms/platformvm/warp/gwarp/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func NewClient(client pb.SignerClient) *Client {
2323

2424
func (c *Client) Sign(unsignedMsg *warp.UnsignedMessage) ([]byte, error) {
2525
resp, err := c.client.Sign(context.Background(), &pb.SignRequest{
26-
SourceChainId: unsignedMsg.SourceChainID[:],
27-
DestinationChainId: unsignedMsg.DestinationChainID[:],
28-
Payload: unsignedMsg.Payload,
26+
NetworkId: unsignedMsg.NetworkID,
27+
SourceChainId: unsignedMsg.SourceChainID[:],
28+
Payload: unsignedMsg.Payload,
2929
})
3030
if err != nil {
3131
return nil, err

vms/platformvm/warp/gwarp/server.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ func (s *Server) Sign(_ context.Context, unsignedMsg *pb.SignRequest) (*pb.SignR
2929
return nil, err
3030
}
3131

32-
destinationChainID, err := ids.ToID(unsignedMsg.DestinationChainId)
33-
if err != nil {
34-
return nil, err
35-
}
36-
3732
msg, err := warp.NewUnsignedMessage(
33+
unsignedMsg.NetworkId,
3834
sourceChainID,
39-
destinationChainID,
4035
unsignedMsg.Payload,
4136
)
4237
if err != nil {

vms/platformvm/warp/gwarp/signer_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/require"
1010

1111
"github.com/ava-labs/avalanchego/ids"
12+
"github.com/ava-labs/avalanchego/utils/constants"
1213
"github.com/ava-labs/avalanchego/utils/crypto/bls"
1314
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
1415
"github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"
@@ -17,11 +18,12 @@ import (
1718
)
1819

1920
type testSigner struct {
20-
client *Client
21-
server warp.Signer
22-
sk *bls.SecretKey
23-
chainID ids.ID
24-
closeFn func()
21+
client *Client
22+
server warp.Signer
23+
sk *bls.SecretKey
24+
networkID uint32
25+
chainID ids.ID
26+
closeFn func()
2527
}
2628

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

3537
s := &testSigner{
36-
server: warp.NewSigner(sk, chainID),
37-
sk: sk,
38-
chainID: chainID,
38+
server: warp.NewSigner(sk, constants.UnitTestID, chainID),
39+
sk: sk,
40+
networkID: constants.UnitTestID,
41+
chainID: chainID,
3942
}
4043

4144
listener, err := grpcutils.NewListener()
@@ -63,7 +66,7 @@ func setupSigner(t testing.TB) *testSigner {
6366
func TestInterface(t *testing.T) {
6467
for _, test := range warp.SignerTests {
6568
s := setupSigner(t)
66-
test(t, s.client, s.sk, s.chainID)
69+
test(t, s.client, s.sk, s.networkID, s.chainID)
6770
s.closeFn()
6871
}
6972
}

vms/platformvm/warp/message_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import (
1010

1111
"github.com/ava-labs/avalanchego/codec"
1212
"github.com/ava-labs/avalanchego/ids"
13+
"github.com/ava-labs/avalanchego/utils/constants"
1314
"github.com/ava-labs/avalanchego/utils/crypto/bls"
1415
)
1516

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

1920
unsignedMsg, err := NewUnsignedMessage(
20-
ids.GenerateTestID(),
21+
constants.UnitTestID,
2122
ids.GenerateTestID(),
2223
[]byte("payload"),
2324
)

vms/platformvm/warp/signature.go

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Signature interface {
3737
Verify(
3838
ctx context.Context,
3939
msg *UnsignedMessage,
40+
networkID uint32,
4041
pChainState validators.State,
4142
pChainHeight uint64,
4243
quorumNum uint64,
@@ -67,11 +68,16 @@ func (s *BitSetSignature) NumSigners() (int, error) {
6768
func (s *BitSetSignature) Verify(
6869
ctx context.Context,
6970
msg *UnsignedMessage,
71+
networkID uint32,
7072
pChainState validators.State,
7173
pChainHeight uint64,
7274
quorumNum uint64,
7375
quorumDen uint64,
7476
) error {
77+
if msg.NetworkID != networkID {
78+
return errWrongNetworkID
79+
}
80+
7581
subnetID, err := pChainState.GetSubnetID(ctx, msg.SourceChainID)
7682
if err != nil {
7783
return err

0 commit comments

Comments
 (0)