devp2p / zks Protocol
The lib/network crate integrates ZKsync OS-specific peer-to-peer traffic into the node’s
devp2p / RLPx network stack.
Its purpose is not to replace the node’s general networking. Instead, it adds a zks/<version>
subprotocol that is used for two zkSync OS-specific flows:
- replay streaming from a main node to an external node
- batch-verification request / response exchange between a main node and verifier-capable external nodes
High-level model
At runtime, each node is configured locally as either:
- a
MainNode - an
ExternalNode
That local role determines how the node behaves on each negotiated zks connection:
- the main node serves replay data and receives
VerifyBatchResult - the external node requests replay data and may optionally authenticate as a verifier
There is currently no explicit “remote role negotiation” on top of devp2p. The local node chooses
its behavior from config and then expects the remote peer to behave compatibly on the negotiated
zks connection.
Module split
service.rsOwns the network manager, registerszksprotocol handlers, consumes protocol events, tracks peer sessions, and dispatchesVerifyBatchrequests to eligible peers.protocol/Contains the RLPx subprotocol implementation itself.handler.rs: bridges reth’s protocol hooks into per-connection tasksmn.rs: main-node side of onezksconnectionen.rs: external-node side of onezksconnectionevents.rs: protocol events and live connection handleshandler_shared_state.rs: shared handler runtime state such as the active-connection limit
session.rsTracks higher-level peer session facts derived from protocol events, such as replay progress and verifier authorization state.wire/Defines thezkswire messages carried over devp2p.
Replay flow
Replay is the baseline zks protocol behavior.
- The EN negotiates a
zks/<version>capability over devp2p. - The EN sends
GetBlockReplays. - The MN streams
BlockReplays. - The EN forwards received replay records into its local pipeline.
Replay record encoding is versioned. Older protocol versions only support replay transport.
Batch verification flow
zks/3 adds verifier-related messages on top of replay streaming.
- An EN that is configured as a verifier sends
VerifierRoleRequest. - The MN replies with
VerifierChallenge. - The EN signs the challenge and sends
VerifierAuth. - The MN emits authorization events and tracks verifier eligibility for that peer session.
- When the MN wants external verification for a batch,
service.rsselects eligible peers and sendsVerifyBatchover livezks/3connections. - The EN-side verifier validates the request and sends back
VerifyBatchResult. - The MN forwards those results into the batch-verification pipeline, which validates request ids, signatures, and signer membership before counting them.
Sequence
sequenceDiagram
participant EN as External Node
participant MN as Main Node
participant VS as Verifier Service
participant BV as Batch Verification Pipeline
Note over EN,MN: devp2p negotiates zks/<version>
alt EN is verifier-capable on zks/3
EN->>MN: VerifierRoleRequest
MN->>EN: VerifierChallenge
EN->>MN: VerifierAuth
Note over MN: Peer session marked authorized if signer is accepted
end
EN->>MN: GetBlockReplays
loop replay stream
MN->>EN: BlockReplays
Note over EN: replay records forwarded into local pipeline
end
Note over MN,BV: Main node decides a batch needs external verification
BV->>MN: VerifyBatch request
MN->>EN: VerifyBatch
EN->>VS: forward request
VS-->>EN: Approved / Refused
EN->>MN: VerifyBatchResult
MN->>BV: forward result
Note over BV: request id, signature, and signer membership are validated here
Why session tracking exists
The network service needs more than “is this peer connected right now?”
For verification dispatch, it needs to know whether a peer:
- requested replay
- has been sent replay far enough to verify a given batch
- successfully authenticated as a verifier on the current connection
That derived state is kept in PeerSessionStore. Live send handles stay in the connection
registry. Dispatch joins those two views:
PeerSessionStoreanswers “who is eligible?”ConnectionRegistryanswers “how do I send to them right now?”