From cdd6b9f09b7119470bc4ff4a01de04c29b44dfe9 Mon Sep 17 00:00:00 2001 From: Aleksandr Bukata Date: Tue, 3 Dec 2024 11:25:04 +0000 Subject: [PATCH 1/3] CCIP-4403 don't request lbtc attestation if payload is returned --- .../ocr2/plugins/ccip/tokendata/lbtc/lbtc.go | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go index dece927d02..63888d9848 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go @@ -188,10 +188,20 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E } } - payloadHash, err := s.getLBTCPayloadHash(msg, tokenIndex) + decodedSourceTokenData, err := abihelpers.DecodeAbiStruct[sourceTokenData](msg.SourceTokenData[tokenIndex]) if err != nil { - return []byte{}, errors.Wrap(err, "failed getting the LBTC message body") + return []byte{}, err + } + destTokenData := decodedSourceTokenData.ExtraData + // We don't have better way to determine if the extraData is a payload or sha256(payload) + // Last parameter of the payload struct is 32-bytes nonce (see Lombard's Bridge._deposit(...) method), + // so we can assume that payload always exceeds 32 bytes + if len(destTokenData) != 32 { + s.lggr.Infow("SourceTokenData.extraData size is not 32. This is deposit payload, not sha256(payload). Attestation is disabled onchain", + "destTokenData", hexutil.Encode(destTokenData)) + return destTokenData, nil } + payloadHash := [32]byte(destTokenData) msgID := hexutil.Encode(msg.MessageID[:]) payloadHashHex := hexutil.Encode(payloadHash[:]) @@ -207,12 +217,15 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E if len(attestationResp.Attestations) > 1 { s.lggr.Warnw("Multiple attestations received, expected one", "attestations", attestationResp.Attestations) } - var attestation messageAttestationResponse + var attestation *messageAttestationResponse for _, attestationCandidate := range attestationResp.Attestations { if attestationCandidate.MessageHash == payloadHashHex { - attestation = attestationCandidate + attestation = &attestationCandidate } } + if attestation == nil { + return nil, fmt.Errorf("requested attestation %s not found in response", payloadHashHex) + } s.lggr.Infow("Got response from attestation API", "messageID", msgID, "attestationStatus", attestation.Status, "attestation", attestation) switch attestation.Status { From 7c0d1df444cdcc126172892a4b37ae4360ec98ee Mon Sep 17 00:00:00 2001 From: Aleksandr Bukata Date: Tue, 3 Dec 2024 12:30:59 +0000 Subject: [PATCH 2/3] drop method --- .../ocr2/plugins/ccip/tokendata/lbtc/lbtc.go | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go index 63888d9848..da9fb86ce9 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go @@ -3,7 +3,6 @@ package lbtc import ( "bytes" "context" - "crypto/sha256" "encoding/json" "fmt" "net/url" @@ -245,27 +244,6 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E } } -func (s *TokenDataReader) getLBTCPayloadHash(msg cciptypes.EVM2EVMOnRampCCIPSendRequestedWithMeta, tokenIndex int) ([32]byte, error) { - decodedSourceTokenData, err := abihelpers.DecodeAbiStruct[sourceTokenData](msg.SourceTokenData[tokenIndex]) - if err != nil { - return [32]byte{}, err - } - destTokenData := decodedSourceTokenData.ExtraData - var payloadHash [32]byte - // We don't have better way to determine if the extraData is a payload or sha256(payload) - // Last parameter of the payload struct is 32-bytes nonce (see Lombard's Bridge._deposit(...) method), - // so we can assume that payload always exceeds 32 bytes - if len(destTokenData) != 32 { - payloadHash = sha256.Sum256(destTokenData) - s.lggr.Warnw("SourceTokenData.extraData size is not 32. Probably this is deposit payload, not sha256(payload). "+ - "This message was sent when LBTC attestation was disabled onchain. Will use sha256 from this value", - "destTokenData", destTokenData, "newPayloadHash", payloadHash) - } else { - payloadHash = [32]byte(destTokenData) - } - return payloadHash, nil -} - func (s *TokenDataReader) callAttestationApi(ctx context.Context, lbtcMessageHash [32]byte) (attestationResponse, error) { attestationUrl := fmt.Sprintf("%s/bridge/%s/%s", s.attestationApi.String(), apiVersion, attestationPath) request := attestationRequest{PayloadHashes: []string{hexutil.Encode(lbtcMessageHash[:])}} From 39431da252febe3806a0079bec9e0f5cc04b1787 Mon Sep 17 00:00:00 2001 From: Aleksandr Bukata Date: Tue, 3 Dec 2024 13:49:18 +0000 Subject: [PATCH 3/3] fix lint --- core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go index da9fb86ce9..f7aad6ee94 100644 --- a/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go +++ b/core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go @@ -216,13 +216,13 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E if len(attestationResp.Attestations) > 1 { s.lggr.Warnw("Multiple attestations received, expected one", "attestations", attestationResp.Attestations) } - var attestation *messageAttestationResponse + var attestation messageAttestationResponse for _, attestationCandidate := range attestationResp.Attestations { if attestationCandidate.MessageHash == payloadHashHex { - attestation = &attestationCandidate + attestation = attestationCandidate } } - if attestation == nil { + if attestation == (messageAttestationResponse{}) { return nil, fmt.Errorf("requested attestation %s not found in response", payloadHashHex) } s.lggr.Infow("Got response from attestation API", "messageID", msgID,