Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build/devenv/fakes/air.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = "/app/build/devenv/fakes"

[build]
cmd = "go build -o ./tmp/fake cmd"
cmd = "go build -o ./tmp/fake cmd/main.go"
bin = "/app/build/devenv/fakes/tmp/fake"
include_ext = ["go", "mod", "sum"]
exclude_dir = ["tmp", "vendor", "testdata", ".git"]
19 changes: 11 additions & 8 deletions build/devenv/fakes/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"log"

"github.com/smartcontractkit/devenv/ccip17/fakes/pkg/offchainstorage"

"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"

"github.com/smartcontractkit/devenv/ccip17/fakes/pkg/cctp"
"github.com/smartcontractkit/devenv/ccip17/fakes/pkg/offchainstorage"
)

func main() {
Expand All @@ -16,16 +17,18 @@ func main() {
}

// Create and configure the offchain storage API
api := offchainstorage.NewOffChainStorageAPI()

// Register the API endpoints
err = api.Register()
if err != nil {
offchainStorage := offchainstorage.NewOffChainStorageAPI()
if err = offchainStorage.Register(); err != nil {
panic(err)
}

log.Printf("Fake offchain storage API running on port %d", fake.DefaultFakeServicePort)

cctpAttestations := cctp.NewAttestationAPI()
if err = cctpAttestations.Register(); err != nil {
panic(err)
}
log.Printf("Fake CCTP Attestation API running on port %d", fake.DefaultFakeServicePort)

// Keep the server running
select {}
}
11 changes: 11 additions & 0 deletions build/devenv/fakes/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
github.com/go-resty/resty/v2 v2.16.5 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/holiman/uint256 v1.3.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.2 // indirect
Expand All @@ -64,6 +65,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
Expand All @@ -73,7 +75,11 @@ require (
github.com/rs/zerolog v1.34.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.9 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.79 // indirect
github.com/smartcontractkit/chainlink-common v0.9.6-0.20260114190811-74301cd99dc3 // indirect
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d // indirect
github.com/smartcontractkit/chainlink-testing-framework/framework v0.12.6 // indirect
github.com/smartcontractkit/libocr v0.0.0-20250912173940-f3ab0246e23d // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/testcontainers/testcontainers-go v0.39.0 // indirect
github.com/tklauser/go-sysconf v0.3.15 // indirect
Expand All @@ -87,12 +93,17 @@ require (
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.21.0 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
google.golang.org/grpc v1.76.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
98 changes: 97 additions & 1 deletion build/devenv/fakes/go.sum

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions build/devenv/fakes/pkg/cctp/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package cctp

import (
"encoding/json"
"fmt"
"net/http"
"sync"

"github.com/gin-gonic/gin"

cctpclient "github.com/smartcontractkit/chainlink-ccv/verifier/token/cctp"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
)

type RegisterAttestationRequest struct {
SourceDomain string `json:"sourceDomain" binding:"required"`
MessageID string `json:"messageID" binding:"required"`
Status string `json:"status" binding:"required"`
}

type AttestationAPI struct {
mu sync.RWMutex
responses map[string]cctpclient.Message
}

func NewAttestationAPI() *AttestationAPI {
return &AttestationAPI{
responses: make(map[string]cctpclient.Message),
}
}

// RegisterAttestation registers a new attestation response for a given sourceDomain.
func (a *AttestationAPI) RegisterAttestation(sourceDomain, messageID, status string) cctpclient.Message {
a.mu.Lock()
defer a.mu.Unlock()

// Construct hookData as 0x8e1d1a9d + messageID (without 0x prefix)
// Strip 0x prefix from messageID if present
cleanMessageID := messageID
if len(messageID) > 2 && messageID[:2] == "0x" {
cleanMessageID = messageID[2:]
}
hookData := "0x8e1d1a9d" + cleanMessageID

// Create a response based on the example attestation but with the provided sourceDomain, hookData and status
response := cctpclient.Message{
Message: "0xbbbbbb22",
EventNonce: "9682",
Attestation: "0xaaaaaa11",
DecodedMessage: cctpclient.DecodedMessage{
SourceDomain: sourceDomain,
DestinationDomain: "5",
Nonce: "569",
Sender: "0xb7317b4EFEa194a22bEB42506065D3772C2E95EF",
Recipient: "0xb7317b4EFEa194a22bEB42506065D3772C2E95EF",
DestinationCaller: "0xf2Edb1Ad445C6abb1260049AcDDCA9E84D7D8aaA",
MessageBody: "0x00000000000000050000000300000000000194c2a65fc943419a5ad590042fd67c9791fd015acf53a54cc823edb8ff81b9ed722e00000000000000000000000019330d10d9cc8751218eaf51e8885d058642e08a000000000000000000000000fc05ad74c6fe2e7046e091d6ad4f660d2a15976200000000c6fa7af3bedbad3a3d65f36aabc97431b1bbe4c2d2f6e0e47ca60203452f5d610000000000000000000000002d475f4746419c83be23056309a8e2ac33b30e3b0000000000000000000000000000000000000000000000000000000002b67df0feae5e08f5e6bf04d8c1de7dada9235c56996f4420b14371d6c6f3ddd2f2da78",
DecodedMessageBody: cctpclient.DecodedMessageBody{
BurnToken: "0x4Bc078D75390C0f5CCc3e7f59Ae2159557C5eb85",
MintRecipient: "0xb7317b4EFEa194a22bEB42506065D3772C2E95EF",
Amount: "5000",
MessageSender: "0x2609ac236def92d0992ff8bbcf810a59a9301bca",
HookData: hookData,
},
},
CCTPVersion: "2",
Status: cctpclient.AttestationStatus(status),
}

a.responses[sourceDomain] = response
return response
}

func (a *AttestationAPI) Register() error {
// POST endpoint to register attestation responses
err := fake.Func("POST", "/cctp/v2/attestations", func(ctx *gin.Context) {
var req RegisterAttestationRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

response := a.RegisterAttestation(req.SourceDomain, req.MessageID, req.Status)
ctx.JSON(http.StatusOK, response)
})
if err != nil {
return err
}

// GET endpoint to retrieve attestation by sourceDomain
err = fake.Func("GET", "/cctp/v2/messages/:sourceDomain", func(ctx *gin.Context) {
sourceDomain := ctx.Param("sourceDomain")

a.mu.RLock()
response, exists := a.responses[sourceDomain]
a.mu.RUnlock()

if !exists {
ctx.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("no attestation found for sourceDomain: %s", sourceDomain)})
return
}

// Return wrapped in "messages" array to match the expected format
wrappedResponse := cctpclient.Messages{
Messages: []cctpclient.Message{response},
}
responseBytes, err := json.Marshal(wrappedResponse)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

ctx.Data(http.StatusOK, "application/json", responseBytes)
})
if err != nil {
return err
}

return nil
}
10 changes: 10 additions & 0 deletions build/devenv/services/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ func defaults(in *IndexerInput) {
BatchSize: 100,
MaxBatchWaitTime: 50,
},
{
Type: config.ReaderTypeRest,
RestReaderConfig: config.RestReaderConfig{
BaseURL: "token-verifier-1:8700/v1/verification/results",
RequestTimeout: 10,
},
Name: "Token Verifier (Primary)",
BatchSize: 10,
MaxBatchWaitTime: 100,
},
},
Storage: config.StorageConfig{
Strategy: config.StorageStrategySink,
Expand Down
40 changes: 40 additions & 0 deletions build/devenv/services/tokenVerifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"strconv"
"time"

"github.com/smartcontractkit/chainlink-ccip/ccv/chains/evm/deployment/v1_7_0/operations/cctp_verifier"
"github.com/smartcontractkit/chainlink-ccv/verifier/token/cctp"

"github.com/BurntSushi/toml"
"github.com/Masterminds/semver/v3"

Expand Down Expand Up @@ -50,6 +53,8 @@ type TokenVerifierInput struct {
DefaultExecutorOnRampAddresses map[string]string `toml:"default_executor_on_ramp_addresses"`
// Maps to rmn_remote_addresses in the verifier config toml.
RMNRemoteAddresses map[string]string `toml:"rmn_remote_addresses"`

CCTPVerifierAddresses map[string]string `toml:"cctp_verifier_addresses"`
}

type TokenVerifierOutput struct {
Expand Down Expand Up @@ -202,6 +207,26 @@ func (v *TokenVerifierInput) buildVerifierConfiguration(config *token.Config) er
config.VerifierID = v.ContainerName
config.OnRampAddresses = v.OnRampAddresses
config.RMNRemoteAddresses = v.RMNRemoteAddresses
if len(config.TokenVerifiers) == 0 {
config.TokenVerifiers = make([]token.VerifierConfig, 0)
}

if len(v.CCTPVerifierAddresses) > 0 {
verifiers := make(map[string]any)
for k, addr := range v.CCTPVerifierAddresses {
verifiers[k] = addr
}
config.TokenVerifiers = append(config.TokenVerifiers, token.VerifierConfig{
Type: "cctp",
Version: "2.0",
CCTPConfig: &cctp.CCTPConfig{
AttestationAPI: "http://fake:9111/cctp",
AttestationAPIInterval: 100 * time.Millisecond,
AttestationAPITimeout: 1 * time.Second,
Verifiers: verifiers,
},
})
}

return nil
}
Expand All @@ -210,6 +235,7 @@ func ResolveContractsForTokenVerifier(ds datastore.DataStore, blockchains []*blo
ver.OnRampAddresses = make(map[string]string)
ver.DefaultExecutorOnRampAddresses = make(map[string]string)
ver.RMNRemoteAddresses = make(map[string]string)
ver.CCTPVerifierAddresses = make(map[string]string)

for _, chain := range blockchains {
networkInfo, err := chainsel.GetChainDetailsByChainIDAndFamily(chain.ChainID, chainsel.FamilyEVM)
Expand All @@ -218,6 +244,20 @@ func ResolveContractsForTokenVerifier(ds datastore.DataStore, blockchains []*blo
}
selectorStr := strconv.FormatUint(networkInfo.ChainSelector, 10)

cctpTokenVerifierAddressRef, err := ds.Addresses().Get(datastore.NewAddressRefKey(
networkInfo.ChainSelector,
datastore.ContractType(cctp_verifier.ResolverType),
semver.MustParse(cctp_verifier.Deploy.Version()),
"CCTP",
))
if err != nil {
framework.L.Info().
Str("chainID", chain.ChainID).
Msg("Failed to get CCTP Verifier address from datastore")
} else {
ver.CCTPVerifierAddresses[selectorStr] = cctpTokenVerifierAddressRef.Address
}

onRampAddressRef, err := ds.Addresses().Get(datastore.NewAddressRefKey(
networkInfo.ChainSelector,
datastore.ContractType(onrampoperations.ContractType),
Expand Down
22 changes: 0 additions & 22 deletions build/devenv/services/tokenVerifier.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ MetricReaderInterval = 5
TraceSampleRatio = 1.0
TraceBatchTimeout = 10

[[token_verifiers]]
type = "lbtc"
version = "1.0"
attestation_api = "https://lbtc-api.example.com"
attestation_api_timeout = "10s"
attestation_api_interval = "100ms"

[token_verifiers.addresses]
3379446385462418246 = "0x9ac06ca36bb3dfd6a70eeb508ea5a33dadecca55"
12922642891491394802 = "0xabb9d2d6f21b2be4d7250de972bd9f778accb3c5"

[[token_verifiers]]
type = "cctp"
version = "2.0"
attestation_api = "https://cctp-api.example.com"
attestation_api_timeout = "10s"
attestation_api_interval = "100ms"

[token_verifiers.addresses]
3379446385462418246 = "0x9ac06ca36bb3dfd6a70eeb508ea5a33dadecca55"
12922642891491394802 = "0xabb9d2d6f21b2be4d7250de972bd9f778accb3c5"


#[blockchain_infos]
# [blockchain_infos.3379446385462418246]
Expand Down
36 changes: 36 additions & 0 deletions build/devenv/tests/e2e/cctp_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package e2e

import (
"bytes"
"encoding/hex"
"encoding/json"
"net/http"
"testing"

"github.com/stretchr/testify/require"
)

// registerCCTPAttestation registers a CCTP attestation response with the fake service.
func registerCCTPAttestation(t *testing.T, messageID [32]byte, status string) {
// Convert messageID to hex string
messageIDHex := "0x" + hex.EncodeToString(messageID[:])

reqBody := map[string]string{
"sourceDomain": "100",
"messageID": messageIDHex,
"status": status,
}
reqJSON, err := json.Marshal(reqBody)
require.NoError(t, err)

// The fake service runs on port 9111
resp, err := http.Post(
"http://localhost:9111/cctp/v2/attestations",
"application/json",
bytes.NewBuffer(reqJSON),
)
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, http.StatusOK, resp.StatusCode, "Failed to register CCTP attestation")
}
Loading
Loading