From c4b0ba59e94a9975eea0e73d3591382628632392 Mon Sep 17 00:00:00 2001 From: Aleksandr Bukata Date: Mon, 2 Dec 2024 15:18:43 +0000 Subject: [PATCH] handle extra-data --- .../ccip/internal/ccipdata/lbtc_reader.go | 9 ++++---- .../ocr2/plugins/ccip/tokendata/lbtc/lbtc.go | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/lbtc_reader.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/lbtc_reader.go index 5a22b76809..f183c32950 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/lbtc_reader.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/lbtc_reader.go @@ -1,7 +1,6 @@ package ccipdata import ( - "bytes" "context" "fmt" @@ -39,7 +38,7 @@ func (d lbtcPayload) Validate() error { } type LBTCReader interface { - GetLBTCMessageInTx(ctx context.Context, payloadHash []byte, txHash string) ([]byte, error) + GetLBTCMessageInTx(ctx context.Context, payloadHash [32]byte, txHash string) ([]byte, error) Close() error } @@ -83,7 +82,7 @@ func NewLBTCReaderWithCache(lggr logger.Logger, jobID string, transmitter common return r, nil } -func (r *LBTCReaderImpl) GetLBTCMessageInTx(ctx context.Context, payloadHash []byte, txHash string) ([]byte, error) { +func (r *LBTCReaderImpl) GetLBTCMessageInTx(ctx context.Context, payloadHash [32]byte, txHash string) ([]byte, error) { var lpLogs []logpoller.Log // fetch all the lbtc logs for the provided tx hash @@ -113,11 +112,11 @@ func (r *LBTCReaderImpl) GetLBTCMessageInTx(ctx context.Context, payloadHash []b } for _, log := range lpLogs { topics := log.GetTopics() - if currentPayloadHash := topics[3]; bytes.Equal(currentPayloadHash[:], payloadHash) { + if currentPayloadHash := topics[3]; currentPayloadHash == payloadHash { return parseLBTCDepositPayload(log.Data) } } - return nil, fmt.Errorf("payload with hash=%s not found in logs", hexutil.Encode(payloadHash)) + return nil, fmt.Errorf("payload with hash=%s not found in logs", hexutil.Encode(payloadHash[:])) } func parseLBTCDepositPayload(logData []byte) ([]byte, error) { diff --git a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go index 74c61fae82..01dbb3bc6c 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go @@ -1,7 +1,6 @@ package lbtc import ( - "bytes" "context" "crypto/sha256" "fmt" @@ -262,17 +261,23 @@ func (s *TokenDataReader) getLBTCPayloadAndHash(ctx context.Context, msg cciptyp if err != nil { return nil, [32]byte{}, err } - payloadHash := decodedSourceTokenData.ExtraData - if len(payloadHash) != 32 { - s.lggr.Warnw("SourceTokenData.extraData is not 32 bytes. LBTC Attestation probably disabled onchain", "payloadHash", payloadHash) + destTokenData := decodedSourceTokenData.ExtraData + var payloadHash [32]byte + if len(destTokenData) != 32 { + payloadHash = sha256.Sum256(destTokenData) + s.lggr.Warnw("SourceTokenData.extraData size is not 32. It could be a LBTC payload, not LBTC payload sha256. "+ + "Probably this message is sent when LBTC attestation was disabled onchain. Will use sha256 from this value", + "destTokenData", destTokenData, "newPayloadHash", payloadHash) + } else { + payloadHash = [32]byte(destTokenData) } - payload, err := s.lbtcReader.GetLBTCMessageInTx(ctx, payloadHash, msg.TxHash) + actualPayload, err := s.lbtcReader.GetLBTCMessageInTx(ctx, payloadHash, msg.TxHash) if err != nil { return nil, [32]byte{}, err } - actualPayloadHash := sha256.Sum256(payload) - if bytes.Equal(actualPayloadHash[:], payloadHash) { - return payload, [32]byte(payloadHash), nil + actualPayloadHash := sha256.Sum256(actualPayload) + if actualPayloadHash == payloadHash { + return actualPayload, payloadHash, nil } return nil, [32]byte{}, fmt.Errorf("payload hash mismatch: expected %x, got %x", payloadHash, actualPayloadHash) }