Today we're open-sourcing VCP Cloudflare RTA Reference — the world's first Cloudflare Workers-based implementation of cryptographically verifiable audit trails for algorithmic trading.
Repository: https://github.com/veritaschain/vcp-cloudflare-rta-reference
In this post, I'll walk through the technical architecture, explain why we chose Cloudflare Workers, and show you how the implementation works.
The Challenge: Audit Trails That Can't Be Trusted
Traditional trading system logs have a fundamental problem: they're mutable.
# Traditional log entry - stored in a database
{
"timestamp": "2026-01-10T09:30:00.000Z",
"order_id": "ORD-12345",
"action": "BUY",
"symbol": "EURUSD",
"quantity": 100000
}
What's stopping someone from:
- Changing the timestamp after the fact?
- Deleting unfavorable trades?
- Adding trades that never happened?
Nothing. Regulators and counterparties must simply trust that the logs are accurate.
The Solution: Three-Layer Cryptographic Integrity
VeritasChain Protocol (VCP) v1.1 introduces a three-layer architecture that makes tampering mathematically detectable.
Layer 1: Event Integrity
Every event gets hashed and signed:
// Simplified event structure
const event = {
eventId: crypto.randomUUID(), // UUID v7 for temporal ordering
timestamp: Date.now(),
eventType: "ORD", // SIG, ORD, EXE, REJ
payload: {
orderId: "ORD-12345",
action: "BUY",
symbol: "EURUSD",
quantity: 100000
},
policyId: "org.veritaschain.demo:silver-tier-001"
};
// SHA-256 hash of canonicalized JSON
const eventHash = await sha256(canonicalize(event));
// Ed25519 signature for non-repudiation
const signature = await sign(eventHash, privateKey);
If a single bit changes, the hash breaks. If someone denies sending the event, the signature proves otherwise.
Layer 2: Collection Integrity (Merkle Tree)
Events are batched into RFC 6962 Merkle trees:
[Merkle Root]
/ \
[Hash A-B] [Hash C-D]
/ \ / \
[Event A] [Event B] [Event C] [Event D]
This enables:
- Inclusion proofs: Prove an event exists without revealing other events
- Completeness detection: Any omitted event changes the root
- Efficient verification: O(log n) instead of O(n)
// Building a Merkle tree (RFC 6962)
function buildMerkleTree(eventHashes) {
if (eventHashes.length === 0) return null;
if (eventHashes.length === 1) return eventHashes[0];
const leaves = eventHashes.map(h => hashLeaf(h));
return computeRoot(leaves);
}
function hashLeaf(data) {
// RFC 6962: leaf nodes prefixed with 0x00
return sha256(concat([0x00], data));
}
function hashInternal(left, right) {
// RFC 6962: internal nodes prefixed with 0x01
return sha256(concat([0x01], left, right));
}
Layer 3: External Anchoring
Here's the critical difference from other solutions: external anchoring is mandatory.
// Anchor the Merkle root to an external timestamp authority
const anchor = {
anchorTarget: "RFC3161_TSA_FREETSA",
anchorTimestamp: new Date().toISOString(),
merkleRoot: currentMerkleRoot,
eventCount: batchSize,
anchorProof: await getTimestampToken(currentMerkleRoot)
};
Even if someone controls the entire system, they cannot modify the anchor stored externally. The history is frozen.
Why Cloudflare Workers?
We evaluated several deployment options. Cloudflare Workers won for three reasons:
1. Edge Latency
Trading systems are latency-sensitive. Adding 100ms for audit logging is unacceptable.
Cloudflare Workers run at 300+ edge locations worldwide. Our benchmarks show sub-10ms overhead for the complete hash-sign-store cycle.
// Cloudflare Worker entry point
export default {
async fetch(request, env, ctx) {
const startTime = Date.now();
// Process trading event
const event = await request.json();
const signedEvent = await processEvent(event, env);
// Store in Durable Objects for consistency
const auditLog = env.AUDIT_LOG.get(env.AUDIT_LOG.idFromName("main"));
await auditLog.fetch(new Request("https://internal/append", {
method: "POST",
body: JSON.stringify(signedEvent)
}));
const latency = Date.now() - startTime;
// Typical: 5-8ms
return new Response(JSON.stringify({
success: true,
eventId: signedEvent.eventId,
latencyMs: latency
}));
}
};
2. Sidecar Architecture
The audit gateway runs alongside trading systems, not inline:
┌─────────────────┐ ┌──────────────────────┐
│ Trading Engine │────▶│ Exchange / Broker │
└────────┬────────┘ └──────────────────────┘
│
│ (async copy)
▼
┌─────────────────────────────────────────────┐
│ Cloudflare Workers Edge │
│ ┌─────────────┐ ┌───────────────────┐ │
│ │ VCP Gateway │───▶│ Durable Objects │ │
│ └─────────────┘ └───────────────────┘ │
└─────────────────────────────────────────────┘
│
▼ (periodic anchor)
┌─────────────────────────────────────────────┐
│ External Timestamp Authority / Chain │
└─────────────────────────────────────────────┘
Benefits:
- No modifications to existing trading infrastructure
- Fail-safe: If audit fails, trading continues
- Decoupled scaling: Audit and trading scale independently
3. Durable Objects for Consistency
Merkle trees require strict ordering. Cloudflare Durable Objects provide:
- Single-threaded execution per object
- Transactional storage
- Global consistency
// Durable Object for maintaining hash chain state
export class AuditLogDO {
constructor(state, env) {
this.state = state;
this.env = env;
}
async fetch(request) {
if (request.url.endsWith("/append")) {
return this.appendEvent(await request.json());
}
if (request.url.endsWith("/merkle-root")) {
return this.getMerkleRoot();
}
// ... other endpoints
}
async appendEvent(event) {
// Get previous hash for chain linking
const prevHash = await this.state.storage.get("currentHash") || "GENESIS";
// Link to previous event
event.prevHash = prevHash;
// Compute new hash
const eventHash = await sha256(canonicalize(event));
// Store atomically
await this.state.storage.put({
currentHash: eventHash,
[`event:${event.eventId}`]: event
});
// Add to current Merkle batch
await this.addToMerkleBatch(eventHash);
return new Response(JSON.stringify({ success: true, hash: eventHash }));
}
}
VCP v1.1 Compliance Tiers
VCP defines three compliance tiers. This implementation targets Silver Tier:
const VCP_TIERS = {
SILVER: {
name: "Silver",
timestampPrecision: "second", // < 1 second
anchorFrequency: "daily", // Every 24 hours
targetUsers: "Retail, Prop Firms",
externalAnchor: "REQUIRED" // v1.1 change!
},
GOLD: {
name: "Gold",
timestampPrecision: "millisecond", // < 1ms
anchorFrequency: "hourly", // Every hour
targetUsers: "Institutions, Brokers",
externalAnchor: "REQUIRED"
},
PLATINUM: {
name: "Platinum",
timestampPrecision: "microsecond", // < 1μs
anchorFrequency: "10min", // Every 10 minutes
targetUsers: "HFT, Exchanges",
externalAnchor: "REQUIRED"
}
};
Key v1.1 changes:
- External anchoring now REQUIRED for all tiers (was optional for Silver)
- Policy Identification field added (mandatory)
- PrevHash field relaxed to OPTIONAL (allows parallel processing)
Event Types
VCP defines four core event types:
const EVENT_TYPES = {
SIG: "Signal/Decision", // AI/algo decision point
ORD: "Order", // Order submission
EXE: "Execution", // Trade execution/fill
REJ: "Rejection" // Order rejection
};
// Example: Complete trade lifecycle
const signalEvent = {
eventType: "SIG",
payload: {
signalId: "SIG-001",
algorithm: "mean-reversion-v2",
prediction: "BUY",
confidence: 0.87
}
};
const orderEvent = {
eventType: "ORD",
payload: {
orderId: "ORD-12345",
signalRef: "SIG-001",
symbol: "EURUSD",
side: "BUY",
quantity: 100000,
orderType: "LIMIT",
price: 1.0850
}
};
const executionEvent = {
eventType: "EXE",
payload: {
executionId: "EXE-789",
orderRef: "ORD-12345",
fillPrice: 1.0851,
fillQuantity: 100000,
venue: "ECN-A"
}
};
Verification Flow
Anyone can verify the audit trail:
async function verifyAuditTrail(events, merkleRoot, anchorProof) {
// Step 1: Verify each event's signature
for (const event of events) {
const isValid = await verifySignature(
event.signature,
event.eventHash,
event.publicKey
);
if (!isValid) {
throw new Error(`Invalid signature for event ${event.eventId}`);
}
}
// Step 2: Verify hash chain integrity
for (let i = 1; i < events.length; i++) {
if (events[i].prevHash !== events[i-1].eventHash) {
throw new Error(`Chain broken at event ${events[i].eventId}`);
}
}
// Step 3: Verify Merkle tree
const computedRoot = buildMerkleTree(events.map(e => e.eventHash));
if (computedRoot !== merkleRoot) {
throw new Error("Merkle root mismatch - events may be missing or altered");
}
// Step 4: Verify external anchor
const anchorValid = await verifyTimestampToken(merkleRoot, anchorProof);
if (!anchorValid) {
throw new Error("External anchor verification failed");
}
return { verified: true, eventCount: events.length };
}
Quick Start
# Clone the repository
git clone https://github.com/veritaschain/vcp-cloudflare-rta-reference
cd vcp-cloudflare-rta-reference
# Install dependencies
npm install
# Run locally
npm run dev
# Deploy to Cloudflare
npm run deploy
Test with curl:
# Submit a trading event
curl -X POST http://localhost:8787/api/events \
-H "Content-Type: application/json" \
-d '{
"eventType": "ORD",
"payload": {
"orderId": "ORD-TEST-001",
"symbol": "EURUSD",
"side": "BUY",
"quantity": 100000
}
}'
# Get current Merkle root
curl http://localhost:8787/api/merkle-root
# Verify an event
curl http://localhost:8787/api/verify/EVENT_ID_HERE
"World First" Verification
We don't make claims lightly. Before this release, we conducted due diligence across 300+ sources via five independent research analyses:
- Academic papers (Google Scholar, arXiv, IEEE)
- Patents (USPTO, EPO, Google Patents)
- Commercial RegTech products
- Open source projects
- Standards bodies (IETF, ISO, FIX)
Result: No prior implementation combines:
- Algorithmic trading-specific design
- Cryptographic hash chains + signatures
- Merkle tree batch verification
- Mandatory external anchoring
- Edge computing deployment
The full evidence report is published in the repository.
IETF Standardization
VCP is being standardized through the IETF as a profile of SCITT (Supply Chain Integrity, Transparency, and Trust):
Internet-Draft: https://datatracker.ietf.org/doc/draft-kamimura-scitt-vcp/
This ensures interoperability and provides a vendor-neutral foundation for industry adoption.
What's Next
- [ ] Gold and Platinum tier implementations
- [ ] Trading platform integrations (MT5, cTrader, FIX)
- [ ] Automated conformance testing suite
- [ ] Post-quantum cryptography migration
Contributing
This is open source under the MIT License. Contributions welcome:
- ⭐ Star the repo
- 🐛 Report issues
- 🔧 Submit PRs
- 💬 Join discussions
Repository: https://github.com/veritaschain/vcp-cloudflare-rta-reference
Links
- VCP Specification: https://veritaschain.org/v1-1/
- IETF Draft: https://datatracker.ietf.org/doc/draft-kamimura-scitt-vcp/
- VSO Website: https://veritaschain.org
VeritasChain Standards Organization — Verify, Don't Trust.
Top comments (0)