Skip to content
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

CCIP-4403 don't request lbtc attestation if payload is returned #1557

Merged
merged 3 commits into from
Dec 3, 2024
Merged
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
39 changes: 15 additions & 24 deletions core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lbtc
import (
"bytes"
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"net/url"
Expand Down Expand Up @@ -188,10 +187,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we returning destTokenData here instead of an error signaling unexpected input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is expected input
in destTokenData Lombard can send to us either full payload (if attestation is disabled) either sha256(payload)
In first case we won't call attestation at all

}
payloadHash := [32]byte(destTokenData)

msgID := hexutil.Encode(msg.MessageID[:])
payloadHashHex := hexutil.Encode(payloadHash[:])
Expand All @@ -213,6 +222,9 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E
attestation = attestationCandidate
}
}
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,
"attestationStatus", attestation.Status, "attestation", attestation)
switch attestation.Status {
Expand All @@ -232,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[:])}}
Expand Down
Loading