Skip to content

Commit 7683283

Browse files
authored
Merge branch 'main' into ARCH-328-keystore-interfaces-and-admin-implementation
2 parents e223a82 + 99a82a5 commit 7683283

File tree

10 files changed

+362
-65
lines changed

10 files changed

+362
-65
lines changed

pkg/loop/internal/pb/ccipocr3/models.pb.go

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/ccipocr3/models.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ message Message {
7575

7676
// BigInt represents a [big.Int].
7777
message BigInt {
78-
bytes value = 1;
78+
bool negative = 1;
79+
bytes value = 2;
7980
}
8081

8182
// TokenAmount is a helper type that defines a token and an amount.

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/ccip_provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type CCIPProviderClient struct {
2929
executePluginCodec ccipocr3.ExecutePluginCodec
3030
tokenDataEncoder ccipocr3.TokenDataEncoder
3131
sourceChainExtraDataCodec ccipocr3.SourceChainExtraDataCodec
32+
messageHasher ccipocr3.MessageHasher
3233
}
3334

3435
func NewCCIPProviderClient(b *net.BrokerExt, cc grpc.ClientConnInterface) *CCIPProviderClient {
@@ -48,6 +49,7 @@ func NewCCIPProviderClient(b *net.BrokerExt, cc grpc.ClientConnInterface) *CCIPP
4849
c.executePluginCodec = NewExecutePluginCodecClient(b.WithName("ExecutePluginCodec"), cc)
4950
c.tokenDataEncoder = NewTokenDataEncoderClient(b.WithName("TokenDataEncoder"), cc)
5051
c.sourceChainExtraDataCodec = NewSourceChainExtraDataCodecClient(b.WithName("SourceChainExtraDataCodec"), cc)
52+
c.messageHasher = NewMessageHasherClient(b.WithName("MessageHasher"), cc)
5153

5254
return c
5355
}
@@ -76,6 +78,7 @@ func (p *CCIPProviderClient) Codec() ccipocr3.Codec {
7678
ExecutePluginCodec: p.executePluginCodec,
7779
TokenDataEncoder: p.tokenDataEncoder,
7880
SourceChainExtraDataCodec: p.sourceChainExtraDataCodec,
81+
MessageHasher: p.messageHasher,
7982
}
8083
}
8184

@@ -104,4 +107,5 @@ func RegisterProviderServices(s *grpc.Server, provider types.CCIPProvider) {
104107
ccipocr3pb.RegisterExecutePluginCodecServer(s, NewExecutePluginCodecServer(codec.ExecutePluginCodec))
105108
ccipocr3pb.RegisterTokenDataEncoderServer(s, NewTokenDataEncoderServer(codec.TokenDataEncoder))
106109
ccipocr3pb.RegisterSourceChainExtraDataCodecServer(s, NewSourceChainExtraDataCodecServer(codec.SourceChainExtraDataCodec))
110+
ccipocr3pb.RegisterMsgHasherServer(s, NewMessageHasherServer(codec.MessageHasher))
107111
}

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/codec.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,53 @@ func (s *extraDataCodecBundleServer) DecodeTokenAmountDestExecData(ctx context.C
666666
DecodedMap: pbMap,
667667
}, nil
668668
}
669+
670+
// MessageHasher client
671+
var _ ccipocr3.MessageHasher = (*messageHasherClient)(nil)
672+
673+
type messageHasherClient struct {
674+
*net.BrokerExt
675+
grpc ccipocr3pb.MsgHasherClient
676+
}
677+
678+
func NewMessageHasherClient(broker *net.BrokerExt, cc grpc.ClientConnInterface) ccipocr3.MessageHasher {
679+
return &messageHasherClient{
680+
BrokerExt: broker,
681+
grpc: ccipocr3pb.NewMsgHasherClient(cc),
682+
}
683+
}
684+
685+
func (c *messageHasherClient) Hash(ctx context.Context, message ccipocr3.Message) (ccipocr3.Bytes32, error) {
686+
resp, err := c.grpc.HashMsg(ctx, &ccipocr3pb.HashMsgInput{
687+
Msg: messageToPb(message),
688+
})
689+
if err != nil {
690+
return ccipocr3.Bytes32{}, err
691+
}
692+
var hash ccipocr3.Bytes32
693+
copy(hash[:], resp.Hash)
694+
return hash, nil
695+
}
696+
697+
// MessageHasher server
698+
var _ ccipocr3pb.MsgHasherServer = (*messageHasherServer)(nil)
699+
700+
type messageHasherServer struct {
701+
ccipocr3pb.UnimplementedMsgHasherServer
702+
impl ccipocr3.MessageHasher
703+
}
704+
705+
func NewMessageHasherServer(impl ccipocr3.MessageHasher) ccipocr3pb.MsgHasherServer {
706+
return &messageHasherServer{impl: impl}
707+
}
708+
709+
func (s *messageHasherServer) HashMsg(ctx context.Context, req *ccipocr3pb.HashMsgInput) (*ccipocr3pb.HashMsgOutput, error) {
710+
message := pbToMessage(req.Msg)
711+
hash, err := s.impl.Hash(ctx, message)
712+
if err != nil {
713+
return nil, err
714+
}
715+
return &ccipocr3pb.HashMsgOutput{
716+
Hash: hash[:],
717+
}, nil
718+
}

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/convert.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ func pbBigIntToInt(b *ccipocr3pb.BigInt) *big.Int {
1717
return nil
1818
}
1919

20-
if b.Value == nil {
21-
return nil
22-
}
23-
2420
if len(b.Value) == 0 {
2521
return big.NewInt(0)
2622
}
27-
return new(big.Int).SetBytes(b.Value)
23+
24+
i := new(big.Int).SetBytes(b.Value)
25+
if b.Negative {
26+
i = i.Neg(i)
27+
}
28+
return i
2829
}
2930

3031
// Helper function to convert protobuf BigInt to ccipocr3.BigInt, preserving nil
@@ -33,22 +34,26 @@ func pbToBigInt(b *ccipocr3pb.BigInt) ccipocr3.BigInt {
3334
return ccipocr3.BigInt{Int: nil}
3435
}
3536

36-
if b.Value == nil {
37-
return ccipocr3.BigInt{Int: nil}
38-
}
39-
4037
if len(b.Value) == 0 {
4138
return ccipocr3.BigInt{Int: big.NewInt(0)}
4239
}
43-
return ccipocr3.NewBigInt(new(big.Int).SetBytes(b.Value))
40+
41+
i := new(big.Int).SetBytes(b.Value)
42+
if b.Negative {
43+
i = i.Neg(i)
44+
}
45+
return ccipocr3.NewBigInt(i)
4446
}
4547

4648
// Helper function to convert big.Int to protobuf BigInt
4749
func intToPbBigInt(i *big.Int) *ccipocr3pb.BigInt {
4850
if i == nil {
4951
return nil
5052
}
51-
return &ccipocr3pb.BigInt{Value: i.Bytes()}
53+
return &ccipocr3pb.BigInt{
54+
Negative: i.Sign() < 0,
55+
Value: i.Bytes(),
56+
}
5257
}
5358

5459
// Helper function to convert ConfidenceLevel to protobuf uint32
@@ -864,6 +869,9 @@ func pbToTokenUpdatesUnix(pbUpdates map[string]*ccipocr3pb.TimestampedUnixBig) m
864869
var value *big.Int
865870
if pbUpdate.Value != nil && len(pbUpdate.Value.Value) > 0 {
866871
value = new(big.Int).SetBytes(pbUpdate.Value.Value)
872+
if pbUpdate.Value.Negative {
873+
value = value.Neg(value)
874+
}
867875
} else {
868876
value = big.NewInt(0)
869877
}

0 commit comments

Comments
 (0)