Pinned External Data Fetches for Daml Contracts
CIP: ?
Layer: Consensus (hard fork)
Title: Pinned External Data Fetches
Author: Elliott G. Dehnbostel
Discussions-To: https://lists.sync.global/g/cip-discuss
Comments-Summary: No comments yet
Status: Draft
Type: Standards Track
Created: 2026-04-13
License: CC0-1.0
Abstract
This CIP introduces a mechanism for Daml contract choices to issue TCP-based
requests to external services during transaction construction and pin the
cryptographically signed response data to the transaction. On validation and
replay, participants verify the pinned signature rather than re-executing the
external call, preserving Canton's deterministic execution model while enabling
smart contracts to consume off-chain data natively.
Specification
Overview
Today, Daml contracts are purely deterministic: given the same inputs, every
participant that validates a transaction arrives at the same result. External
data (e.g., price feeds, KYC attestations, off-chain state) must be brought
on-chain through application-level orchestration outside the contract model.
This CIP adds a new ledger-level primitive that allows a choice body to declare
an external data fetch. During transaction construction the submitting
participant executes the fetch; during validation all other participants verify
the pinned response instead of repeating the call.
External Data Fetch Primitive
A new Daml built-in is introduced:
```daml
fetchExternal : FetchRequest -> Update FetchResponse
```
Where:
```daml
data FetchRequest = FetchRequest
{ endpoint : Text -- TCP endpoint as "host:port"
, payload : ByteString -- request bytes sent to the service
, signerKeys : [PublicKey] -- accepted signing keys for the response
, maxBytes : Int -- maximum response size in bytes
, timeoutMs : Int -- network timeout in milliseconds
}
data FetchResponse = FetchResponse
{ body : ByteString -- response payload
, signature : ByteString -- cryptographic signature over (body, nonce)
, signerKey : PublicKey -- which key from signerKeys signed
, fetchedAt : Timestamp -- wall-clock time of the fetch
}
```
Transaction Construction (Submitter)
When the Daml engine encounters a `fetchExternal` call during command
interpretation on the submitting participant:
1. Open a TCP connection to `endpoint`.
2. Send `payload` prefixed with a 32-byte transaction-bound nonce generated
by the engine. The nonce binds the response to this specific transaction
to prevent replay of stale signed data across transactions.
3. Read up to `maxBytes` of response data within `timeoutMs`.
4. Verify that the response carries a valid signature from one of the
`signerKeys` over `SHA-256(nonce || body)`.
5. If verification succeeds, record the `FetchResponse` as a **pinned data
node** in the transaction view alongside the usual create/exercise nodes.
6. Return the `FetchResponse` to the Daml engine so the choice body can
branch on the data.
If the connection fails, times out, or the signature is invalid, command
interpretation fails and no transaction is submitted.
Transaction Validation (All Other Participants)
When a confirming participant or mediator processes a transaction containing
pinned data nodes:
1. Extract `(body, signature, signerKey, nonce)` from the pinned data node.
2. Verify that `signerKey` is in the `signerKeys` declared in the original
`FetchRequest`.
3. Verify the signature over `SHA-256(nonce || body)`.
4. Supply the verified `FetchResponse` to the Daml engine as a fixed input
(no network call is made).
5. Re-execute the choice body deterministically using the pinned data.
If signature verification fails, the participant rejects the transaction.
Nonce Generation
The transaction-bound nonce is derived as:
```
nonce = SHA-256(transaction_uuid || fetch_node_index)
```
Where `transaction_uuid` is the unique identifier assigned during command
interpretation and `fetch_node_index` is the zero-based index of the
`fetchExternal` call within the transaction. This ensures each fetch within
a transaction gets a unique nonce and that nonces cannot be predicted before
transaction construction begins.
External Service Protocol
External services that wish to be callable via `fetchExternal` must implement
the following TCP protocol:
1. Accept a connection.
2. Read the first 32 bytes as the nonce.
3. Read the remaining bytes as the application-level request payload.
4. Compute the response `body`.
5. Sign `SHA-256(nonce || body)` with the service's private key.
6. Return `length(body) as 4-byte big-endian || body || signature`.
7. Close the connection.
Services advertise their public keys out-of-band (e.g., via CNS metadata
entries or CIP governance). Contract authors embed the accepted keys in
their `FetchRequest.signerKeys`.
Privacy
Pinned data nodes inherit the same visibility rules as the transaction view
they belong to. Only stakeholders and confirming participants of that view
see the fetched data. The external service endpoint address is visible to
all confirming participants of the view but not to non-stakeholder observers.
Size and Cost Limits
- `maxBytes` is capped at a protocol-level maximum (proposed: 64 KiB) to
prevent pinned data from inflating transaction sizes unboundedly.
- Pinned data counts toward the transaction's traffic weight for
synchronizer fee calculation, using the same bytes-based accounting as
other transaction nodes.
- A transaction may contain at most 8 `fetchExternal` calls. This limit
is a protocol parameter adjustable by CIP.
Daml Surface Syntax
To make the primitive ergonomic, a standard library module is provided:
```daml
module DA.External (fetchExternal, FetchRequest(..), FetchResponse(..)) where
...
```
Contract authors use it as:
```daml
choice GetPrice : Decimal
with
oracle : FetchRequest
controller owner
do
resp <- fetchExternal oracle
let price = parseDecimal (toText resp.body)
-- use price in contract logic
pure price
```
Motivation
Canton's privacy and determinism guarantees are a core strength, but they come
at the cost of isolation from external systems. Today, bringing off-chain data
on-chain requires bespoke application-level plumbing:
- Price feeds (CIP-0079): Super Validators ingest Kaiko prices and
republish them via dedicated Daml contracts and automation triggers. Every
new data source requires a new contract model, a new automation pipeline,
and a new CIP to govern the feed.
- KYC/AML attestations: Compliance data from providers like TRM
ledger, introducing latency and trust assumptions at the application layer.
- Cross-chain state: Verifying state on other ledgers (e.g., confirming
an L1 deposit before releasing Canton-side assets) requires off-chain
relayers with no standard interface.
Each of these follows the same pattern: fetch external data, attest to its
authenticity, and feed it into contract logic. A general-purpose primitive
would eliminate redundant infrastructure, reduce the governance overhead of
adding new data sources, and let contract authors integrate external data
without waiting for purpose-built pipelines.
Furthermore, the TCP-level primitive (rather than HTTP) keeps the protocol
layer lean and avoids encoding opinions about application-layer protocols
into the consensus layer. Contract authors and library developers can build
HTTP, gRPC, or any other protocol on top.
Rationale
Why pin-and-verify rather than re-execute?
Re-executing the external call on every validating participant would require
all participants to have network access to the same service, would leak
information about which participants are validating which transactions, and
would introduce non-determinism if the service returns different data across
calls. Pinning the response and verifying the signature ensures deterministic
replay while requiring only the submitter to have network access.
Why TCP rather than HTTP?
HTTP is an application-layer protocol with significant complexity (headers,
content encoding, chunked transfer, TLS negotiation). Embedding an HTTP
client in the Daml engine would increase the attack surface and create
implicit dependencies on TLS certificate infrastructure. Raw TCP keeps the
consensus-layer primitive minimal. Higher-level protocols can be implemented
in Daml libraries or external service wrappers that speak the nonce-sign
protocol over TCP.
Why not use existing oracle patterns?
Existing oracle patterns on Canton (e.g., CIP-0079 price feeds) require:
1. A dedicated contract model per data type
2. Off-chain automation to poll and publish
3. A governance CIP to authorize each new feed
This works for a small number of high-value feeds but does not scale to the
long tail of external data integrations that application developers need. A
protocol-level primitive shifts the trust boundary from "trust the oracle
operator's automation" to "trust the oracle operator's signing key" -- a
strictly smaller trust surface.
Why limit to 64 KiB and 8 fetches per transaction?
These limits prevent abuse while covering the vast majority of use cases
(price quotes, attestation certificates, Merkle proofs). Larger or more
frequent data needs should use the existing pattern of publishing data to
dedicated contracts. The limits are protocol parameters and can be adjusted
by future CIPs as the network matures.
Alternatives considered
Callback model: The external service pushes data on-chain proactively,
and contracts read it from existing contracts. This is the status quo
(CIP-0079). It works but requires per-source infrastructure and does not
support request-response patterns where the query depends on contract state.
Trusted execution enclaves (TEE): Run the fetch inside a TEE on the
submitting participant and attest the result. This would avoid needing the
external service to implement the signing protocol but introduces hardware
dependencies and a much larger trust surface. It could be explored as a
complementary mechanism in a future CIP.
Threshold-signed fetches: Require multiple participants to independently
fetch and co-sign the response before it is pinned. This provides stronger
guarantees against a compromised submitter colluding with the external service
but adds latency and complexity. It is a natural extension of this CIP and
could be layered on top.
Backwards Compatibility
This is a hard fork change. All participants (Super Validators and
Validators) must upgrade to a Canton version that understands pinned data
nodes in the transaction format. Transactions containing `fetchExternal`
calls submitted to participants running older software will be rejected.
- Contracts that do not use `fetchExternal` are unaffected.
- The transaction format is extended with a new node type; older parsers
will fail on transactions containing pinned data nodes.
- The Daml engine must be updated to support the new built-in.
- Sequencer and mediator message formats are extended to carry pinned data.
A phased rollout is recommended:
1. Phase 1: Release Canton version with `fetchExternal` support.
Contracts using the primitive can be deployed but not yet exercised on the
Global Synchronizer.
2. Phase 2: Once 2/3 of Super Validators have upgraded and vetted the
new Daml packages, enable `fetchExternal` via an on-chain protocol
parameter change.
Reference Implementation
To be provided. The implementation will span:
- Canton protocol: New `PinnedDataNode` in the transaction tree
representation, validation logic in the mediator and confirming participants.
- Daml engine: New `fetchExternal` built-in with TCP execution during
interpretation and pinned-data replay during validation.
- Daml standard library: `DA.External` module exposing the types and
primitive.
- External service SDK: Reference implementation of the nonce-sign TCP
protocol in Python and TypeScript.
Copyright
This CIP is licensed under CC0-1.0: [Creative Commons CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/)
Changelog
* 2026-04-13: Initial draft of the proposal.