Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
dc8d553
Init compose
MatheusFranco99 Oct 27, 2025
9219656
fix go mod module declaration
MatheusFranco99 Oct 27, 2025
3098e7f
fix go mod renaming
MatheusFranco99 Oct 27, 2025
6596525
downgrade go to 1.23.0
MatheusFranco99 Oct 27, 2025
b434865
refactor Instance.Chains from field to method
MatheusFranco99 Oct 27, 2025
af59b02
Drop unused err and ERChainID field from publisher
MatheusFranco99 Oct 27, 2025
b387094
Added features, logging, and comments:
MatheusFranco99 Oct 27, 2025
05deb09
Add logging and no limit for proof_window=0 config
MatheusFranco99 Oct 27, 2025
1f8c47a
align tests
MatheusFranco99 Oct 27, 2025
6bad137
Add proto files and reamde
MatheusFranco99 Oct 27, 2025
96f717a
Add publisher interface to scp
MatheusFranco99 Oct 28, 2025
4e6df41
Add pending dependency
MatheusFranco99 Oct 28, 2025
b67e314
Add periodID to rollback msg
MatheusFranco99 Oct 29, 2025
f16afce
Export GenerateInstanceID method
MatheusFranco99 Oct 29, 2025
b96001e
Add interface for scp sequencer
MatheusFranco99 Oct 29, 2025
7c95866
Add proto with XTRequest with chain id
MatheusFranco99 Oct 29, 2025
397ad85
Deprecate Transactions interface for XTRequest explicit structure
MatheusFranco99 Oct 29, 2025
4597cc5
Use chain id as uint64
MatheusFranco99 Oct 29, 2025
29572a9
rename scp.go to mailbox.go
MatheusFranco99 Oct 29, 2025
b384351
Add non-participant check in scp/publisher
MatheusFranco99 Nov 1, 2025
6318cbc
Rename proto file
MatheusFranco99 Nov 1, 2025
09620b4
participant check refactor
MatheusFranco99 Nov 1, 2025
d180d98
Add sbcp-v2 spec file
MatheusFranco99 Nov 7, 2025
8fefc57
Add proof pipeline logic to sbcp spec code
MatheusFranco99 Nov 7, 2025
90d7ea4
Add deprecated note to sbcp v1
MatheusFranco99 Nov 7, 2025
1480ead
Fix lock usage
MatheusFranco99 Nov 7, 2025
6ea0acb
check that proof.superblock has finished
MatheusFranco99 Nov 7, 2025
5814c6f
align unit tests
MatheusFranco99 Nov 7, 2025
2c50d7d
align scp
MatheusFranco99 Nov 8, 2025
9c26848
github action for unit tests
MatheusFranco99 Nov 8, 2025
c787c13
check for active instances in endblock call in sbcp.sequencer
MatheusFranco99 Nov 10, 2025
2c679ab
fix typo
MatheusFranco99 Nov 14, 2025
9fc99f6
fix typo
MatheusFranco99 Nov 14, 2025
ed1922e
fix plural typo
MatheusFranco99 Nov 14, 2025
28b382a
add figures
MatheusFranco99 Nov 14, 2025
03dafa1
fix grammar typos and protobuf3 label
MatheusFranco99 Nov 14, 2025
2047756
align settlement to new sbcp v2
MatheusFranco99 Nov 14, 2025
bfa4f5b
add sequencer number and period ID validation to start instance check
MatheusFranco99 Nov 14, 2025
dca0e01
add sbcp readme
MatheusFranco99 Nov 14, 2025
f59c1ff
add scp readme
MatheusFranco99 Nov 14, 2025
69cad85
refactor util code
MatheusFranco99 Nov 16, 2025
82cdcd7
add cdcp markdown
MatheusFranco99 Nov 16, 2025
b2fb540
cdcp spec minimal implementation
MatheusFranco99 Nov 16, 2025
da998f2
Merge branch 'main' into compose-lib
MatheusFranco99 Nov 16, 2025
438759c
fix bold format
MatheusFranco99 Nov 16, 2025
2370e40
mention lib in README and fix protocol version
MatheusFranco99 Nov 24, 2025
0794e98
fix namings
MatheusFranco99 Nov 24, 2025
e1166ec
apply suggestions
MatheusFranco99 Nov 24, 2025
2135f96
add pending block check to locked section
MatheusFranco99 Nov 24, 2025
7513967
fix memory cleanup
MatheusFranco99 Nov 24, 2025
66bab2e
fix instance id computation to encompass chain, tx length, and number…
MatheusFranco99 Nov 24, 2025
3b23404
put session id first in case we use it for versioning
MatheusFranco99 Nov 24, 2025
015761b
adjust readmes
MatheusFranco99 Nov 24, 2025
2a2b6e6
Merge branch 'compose-lib' into cdcp-md-and-impl
MatheusFranco99 Nov 24, 2025
3586694
drop unused function
MatheusFranco99 Nov 24, 2025
882667e
fix lock
MatheusFranco99 Nov 24, 2025
c5f08ad
fix done check
MatheusFranco99 Nov 24, 2025
1452b93
unit tests
MatheusFranco99 Nov 24, 2025
bd161d8
add error cases
MatheusFranco99 Nov 24, 2025
b08aeb5
add comments, checks, and fixed
MatheusFranco99 Nov 24, 2025
49647f2
re-order check and add unit tests
MatheusFranco99 Nov 24, 2025
4998334
add cdcp readme
MatheusFranco99 Nov 24, 2025
0a5d814
clarify hash content
MatheusFranco99 Nov 25, 2025
eafc14b
clarify hash content
MatheusFranco99 Nov 25, 2025
ef208d8
Merge branch 'compose-lib' into cdcp-md-and-impl
MatheusFranco99 Nov 25, 2025
ff18057
rename network proof to superblock proof
MatheusFranco99 Nov 25, 2025
18478c6
add target superblock to publisher constructor
MatheusFranco99 Nov 25, 2025
4833bb3
remove v1 file
MatheusFranco99 Nov 26, 2025
201c4cc
remove v2 mentions
MatheusFranco99 Nov 26, 2025
34aa6e0
add golangci lint
MatheusFranco99 Nov 26, 2025
5e6b18b
fix linter
MatheusFranco99 Nov 26, 2025
c064476
improve readability of StartPeriod
MatheusFranco99 Nov 27, 2025
d738783
Revert "improve readability of StartPeriod"
MatheusFranco99 Nov 27, 2025
7855cc0
clarify input var names
MatheusFranco99 Nov 27, 2025
84de545
Merge branch 'compose-lib' into cdcp-md-and-impl
MatheusFranco99 Nov 27, 2025
1f49e15
Merge branch 'main' into cdcp-md-and-impl
MatheusFranco99 Nov 27, 2025
89001bd
fix linter issue
MatheusFranco99 Nov 27, 2025
84d7483
delete cdcp markdown
MatheusFranco99 Nov 27, 2025
8377c9a
fix wrong spaces
MatheusFranco99 Nov 27, 2025
495acaa
apply suggestions
MatheusFranco99 Dec 12, 2025
8e58dd4
use rwlock
MatheusFranco99 Dec 12, 2025
a8fa96b
make external calls unlocked
MatheusFranco99 Dec 12, 2025
3ac7a6e
fix comments
MatheusFranco99 Dec 12, 2025
f65e0de
O(n*m) to O(n) complexity on checking sent mailbox messages
MatheusFranco99 Dec 12, 2025
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
1 change: 1 addition & 0 deletions compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This directory contains the Compose Specification library code.
- [proto](./proto/README.md): Protocol Buffers definitions for protocol messages.
- [scp](./scp/README.md): Synchronous Composability Protocol module.
- [sbcp](./sbcp/README.md): Superblock Construction Protocol module.
- [cdcp](./cdcp/README.md): Cross-Domain Composability Protocol module.

## Generating Go Proto Files

Expand Down
221 changes: 221 additions & 0 deletions compose/cdcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
# Cross-Domain Composability Protocol (CDCP) — Minimal Spec Implementation

This package provides a minimal, testable implementation of the [CDCP](./../../cross_domain_composability_protocol.md) protocol that coordinates atomic execution between Compose native rollups and an external rollup.
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The README references a file "./../../cross_domain_composability_protocol.md" that does not exist in the repository. This broken link will cause confusion for users trying to understand the protocol. Either add the missing documentation file or update the link to point to an existing resource that describes the CDCP protocol.

Suggested change
This package provides a minimal, testable implementation of the [CDCP](./../../cross_domain_composability_protocol.md) protocol that coordinates atomic execution between Compose native rollups and an external rollup.
This package provides a minimal, testable implementation of the [CDCP](https://github.com/ComposableFi/cross-domain-composability-protocol) protocol that coordinates atomic execution between Compose native rollups and an external rollup.

Copilot uses AI. Check for mistakes.

## Publisher

The package exposes the `PublisherInstance` interface with the core logic for the CDCP publisher role.
It requires the following implementation dependency:
- `PublisherNetwork`: transports `StartInstance` to all participants,
`NativeDecided` to the WS, and final `Decided` messages to all NSs.

And provides the following methods:
- `Instance()`: returns the immutable `compose.Instance` metadata (ID, period, sequence number, chain list, request payload).
- `DecisionState()`: returns the current decision state (`Pending`, `Accepted`, `Rejected`).
- `Run()`: broadcasts the `StartInstance` message to every participant chain.
- `ProcessVote(sender, vote)`: records votes from native chains only, rejecting duplicates and ignoring non-native senders. Any `false` vote immediately decides and broadcasts rejection while `true` votes from all natives trigger `NativeDecided(true)` to the WS.
- `ProcessWSDecided(sender, decision)`: accepts exactly one decision from the ER chain. `false` finalizes the instance immediately (even if native votes are still missing); `true` is only valid after `NativeDecided(true)` has been sent and leads to acceptance.
- `Timeout()`: if still waiting for native votes, decides rejection and emits both `Decided(false)` and `NativeDecided(false)`.

The publisher validates the instance at construction time: the ER chain must belong to the instance and there must be at least one native chain.
Its state machine advances from WaitingVotes → WaitingWSDecided → Done, guarding impossible combinations (e.g. `WSDecided(true)` while still waiting for votes).

```mermaid
classDiagram
direction TB

class PublisherInstance {
+Instance() Instance
+DecisionState() DecisionState
+Run()
+ProcessVote(ChainID, bool) error
+ProcessWSDecided(ChainID, bool) error
+Timeout() error
}

class PublisherNetwork {
<<interface>>
+SendStartInstance(Instance)
+SendNativeDecided(InstanceID, bool)
+SendDecided(InstanceID, bool)
}

class PublisherState {
instance : Instance
nativeChains : map[ChainID]struct
erChainID : ChainID
state : PublisherState
decisionState : DecisionState
votes : map[ChainID]bool
wsDecision : *bool
}

PublisherInstance --> PublisherNetwork
PublisherInstance --> PublisherState
```

## Native Sequencer

Native sequencer behavior in CDCP is identical to the SCP sequencer role.
`NewNativeSequencerInstance` simply proxies to `scp.NewSequencerInstance`, so implementers can reuse the same execution engine, network adapter, and VM snapshot logic described in [`scp`](./../scp/README.md).

## Wrapped Sequencer

Wrapped sequencer (WS) logic is provided through the `WrappedSequencerInstance` interface.
It orchestrates mailbox-aware simulations of the external rollup transactions, waits for the native decision, and interacts with the external rollup client to submit the canonical transaction.
It requires the following implementation dependencies:
- `WSExecutionEngine`: performs mailbox-aware simulations of `safe_execute`, returning read/write misses plus the produced mailbox messages.
- `WSNetwork`: sends mailbox messages to native chains and reports `WSDecided` results back to the publisher.
- `ERClient`: submits `safe_execute` on the external rollup once the native decision allows it.

Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The README refers to "safe_execute" as both a "solidity function" (line 39) and in the WSExecutionEngine description (line 67), but doesn't clearly document what this function is or where it's defined. Since this is a core concept of the CDCP protocol, the README should include a brief explanation or reference to where safe_execute is defined, especially for readers unfamiliar with the broader system architecture.

Suggested change
> **Note:** `safe_execute` is a Solidity function defined in the external rollup's smart contract. It is responsible for atomically executing cross-domain transactions according to the CDCP protocol. For details on its interface and behavior, see the [CDCP protocol specification](./../../cross_domain_composability_protocol.md) or the external rollup's contract source code.

Copilot uses AI. Check for mistakes.
And provides the following methods:
- `DecisionState()`: returns the WS decision state.
- `Run()`: calls simulations against the VM snapshot:
- Success: caches written mailbox messages, transitions to `WaitingNativeDecided`, and waits for publisher's `NativeDecided` message.
- Error: transitions to `Done` and reports the error.
- `ProcessMailboxMessage(msg)`: buffers incoming mailbox messages for simulation; when a pending read is satisfied it moves the message into `PutInboxMessages` and re-runs the simulation.
- `ProcessNativeDecidedMessage(decided)`: deduplicates the publisher’s native decision and, if `true`, triggers the external rollup submission; `false` cancels execution.
- `Timeout()`: while not already waiting for the ER response, aborts and reports `WSDecided(false)`.

```mermaid
classDiagram
direction TB

class WrappedSequencerInstance {
+DecisionState() DecisionState
+Run() error
+ProcessMailboxMessage(MailboxMessage) error
+ProcessNativeDecidedMessage(bool) error
+Timeout()
}

class WSExecutionEngine {
<<interface>>
+ChainID() ChainID
+Simulate(WSSimulationRequest) WSSimulationResponse
}

class ERClient {
<<interface>>
+SubmitTransaction(SafeExecuteArguments) error
}

class WSNetwork {
<<interface>>
+SendMailboxMessage(ChainID, MailboxMessage)
+SendWSDecidedMessage(bool)
}

class SafeExecuteArguments {
PutInboxMessages : []MailboxMessage
PutOutboxMessages : []MailboxMessage
Transactions : [][]byte
}

class WSSimulationRequest {
SafeExecuteArguments
Snapshot : StateRoot
}

class WSSimulationResponse {
ReadMiss : *MailboxMessageHeader
WriteMiss : *MailboxMessage
WrittenMessages : []MailboxMessage
Err : error
}

class WSStateData {
state : WSState
decisionState : DecisionState
nativeDecided : *bool
txs : [][]byte
expectedReadRequests : []MailboxMessageHeader
pendingMessages : []MailboxMessage
putInboxMessages : []MailboxMessage
writePrePopulationMessages : []MailboxMessage
writtenMessagesCache : []MailboxMessage
vmSnapshot : StateRoot
}

WrappedSequencerInstance --> WSExecutionEngine
WrappedSequencerInstance --> WSNetwork
WrappedSequencerInstance --> ERClient
WrappedSequencerInstance --> WSStateData
WSSimulationRequest --> SafeExecuteArguments
WSSimulationResponse --> MailboxMessage
```

## Tests

To run the unit tests, use:

```bash
go test ./...
```

## Auxiliary Sequence Flows

### 1. Instance start, native votes, and WS decision

```mermaid
sequenceDiagram
autonumber
participant SP as Publisher
participant NS as Native Sequencer
participant WS as Wrapped Sequencer

SP->>NS: StartInstance(id, period, seq, XTRequest)
SP->>WS: StartInstance(id, period, seq, XTRequest)
NS->>SP: Vote(true/false)
alt vote == false
SP->>SP: Decide(false)
SP-->>NS: Decided(false)
SP-->>WS: NativeDecided(false)
else all votes true
SP-->>WS: NativeDecided(true)
WS->>SP: WSDecided(true/false)
SP-->>NS: Decided(decision)
end
```

### 2. WS simulation, mailbox exchange, and re-run

```mermaid
sequenceDiagram
autonumber
participant WS as Wrapped Sequencer
participant EE as WSExecutionEngine
participant NS as Native Sequencer

WS->>EE: Simulate({putInbox, putOutbox, txs, snapshot})
EE-->>WS: ReadMiss(header)
WS->>WS: Store expected read
NS-->>WS: MailboxMessage(header, data)
WS->>WS: consumeReceivedMailboxMessages
WS->>EE: Simulate({putInbox+msg, putOutbox, txs, snapshot})
EE-->>WS: (success + writtenMessages)
WS->>NS: SendMailboxMessage(dest, msg)
```

### 3. Native decision, ER submission, and finalization

```mermaid
sequenceDiagram
autonumber
participant WS as Wrapped Sequencer
participant ER as ERClient
participant SP as Publisher

WS->>SP: (waiting) NativeDecided?
SP-->>WS: NativeDecided(true)
WS->>ER: SubmitTransaction({putInbox, putOutbox, txs})
alt success
ER-->>WS: ok
WS->>SP: WSDecided(true)
SP-->>NSs: Decided(true)
else failure or timeout
ER-->>WS: error
WS->>SP: WSDecided(false)
SP-->>NSs: Decided(false)
end
```
Loading
Loading