@@ -109,145 +109,157 @@ depend on each other, forming a directed graph that is almost a tree.
109109each such relation represents the transition rule of the state machine;
110110$X$ is simply a placeholder for the name of the transition rule.
111111
112- \begin{NoConway}
113- \subsection{Ledger State Transition Rules}
114- \label{sec: ledger-state-transition-rules }
115- By a \textit{ledger} we mean a structure that contains information about
116- how funds in the system are distributed accross accounts---that is, account
112+ ## Ledger State Transition Rules {#sec: ledger-state-transition-rules }
113+
114+ By a * ledger* we mean a structure that contains information about how
115+ funds in the system are distributed accross accounts—that is, account
117116balances, how such balances should be adjusted when transactions and
118- proposals are processed, the ADA currently held in the treasury reserve, a
119- list of \textit{stake pools} operating the network, and so on.
120-
121- The ledger can be updated in response to certain events, such as receiving a new
122- transaction, time passing and crossing an \textit{epoch boundary}, enacting a
123- \textit{governance proposal}, to name a few. This document defines, as part of the
124- behaior of the ledger, a set of rules that determine which events are valid and
125- exactly how the state of the ledger should be updated in response to those events.
126- The primary aim of this document is to provide a precise description of this
127- system---the ledger state, valid events and the rules for processing them.
128-
129- We will model this via a number of \textit{state transition systems} (STS) which
130- from now on we refer to as `` transition rules'' or just `` rules.''
131- These rules describe the different behaviors that determine how the whole system
132- evolves and, taken together, they comprise a full description of the ledger protocol.
133- Each transition rule consists of the following components:
134- \begin{itemize}
135- \item an \textit{environment} consisting of data, read from the ledger state
136- or the outside world, which should be considered constant for the
137- purposes of the rule;
138- \item an \textit{initial state}, consisting of the subset of the full ledger
139- state that is relevant to the rule and which the rule can update;
140- \item a \textit{signal} or \textit{event}, with associated data, that the
141- rule can receive or observe;
142- \item a set of \textit{preconditions} that must be met in order for the transition
143- to be valid;
144- \item a new state that results from the transition rule.
145- \end{itemize}
146- For example, the UTXOW transition rule defined in \cref{fig:rules: utxow } of
147- \cref{sec: witnessing } checks that, among other things, a given transaction is signed
148- by the appropriate parties.
149-
150- The transition rules can be composed in the sense that they may require other
151- transition rules to hold as part of their preconditions. For example, the UTXOW rule
152- mentioned above requires the UTXO rule, which checks that the inputs to the
153- transaction exist, that the transaction is balanced, and several other conditions.
154-
155- \begin{figure}[ h!]
156- \centering
157- \input{Diagrams/CardanoLedger}
158- \caption{State transition rules of the ledger specification, presented as a
159- directed graph; each node represents a transition rule; an arrow from rule A to
160- rule B indicates that B appears among the premises of A; a dotted arrow represents
161- a dependency in the sense that the output of the target node is an input to the
162- source node, either as part of the source state, the environment or the event
163- (\legendbox{\ConwayColor}~ rules added in Conway;
164- \legendbox{\BabbageColor}~ rules modified in Conway; dotted ellipses represent rules
165- that are not yet formalized in Agda).
166- }
167- \label{fig: latest-sts-diagram }
168- \end{figure}
169-
170- A brief description of each transition rule is provided below, with a link to
171- an Agda module and reference to a section where the rule is formally defined.
117+ proposals are processed, the ADA currently held in the treasury reserve,
118+ a list of * stake pools* operating the network, and so on.
119+
120+ The ledger can be updated in response to certain events, such as
121+ receiving a new transaction, time passing and crossing an * epoch
122+ boundary* , enacting a * governance proposal* , to name a few. This
123+ document defines, as part of the behaior of the ledger, a set of rules
124+ that determine which events are valid and exactly how the state of the
125+ ledger should be updated in response to those events. The primary aim of
126+ this document is to provide a precise description of this system—the
127+ ledger state, valid events and the rules for processing them.
128+
129+ We will model this via a number of * state transition systems* (STS)
130+ which from now on we refer to as “transition rules” or just “rules.”
131+ These rules describe the different behaviors that determine how the
132+ whole system evolves and, taken together, they comprise a full
133+ description of the ledger protocol. Each transition rule consists of the
134+ following components:
135+
136+ - an * environment* consisting of data, read from the ledger state or the
137+ outside world, which should be considered constant for the purposes of
138+ the rule;
139+
140+ - an * initial state* , consisting of the subset of the full ledger state
141+ that is relevant to the rule and which the rule can update;
142+
143+ - a * signal* or * event* , with associated data, that the rule can receive
144+ or observe;
145+
146+ - a set of * preconditions* that must be met in order for the transition
147+ to be valid;
148+
149+ - a new state that results from the transition rule.
150+
151+ For example, the UTXOW transition rule defined in
152+ [ UTXOW inference rules] ( Ledger.Conway.Utxow.md#utxow-inference-rules ) of
153+ the [ Utxow module] ( Ledger.Conway.Utxow.md#sec:witnessing ) checks that, among
154+ other things, a given transaction is signed by the appropriate parties.
155+
156+ The transition rules can be composed in the sense that they may require
157+ other transition rules to hold as part of their preconditions. For
158+ example, the UTXOW rule mentioned above requires the UTXO rule, which
159+ checks that the inputs to the transaction exist, that the transaction is
160+ balanced, and several other conditions.
161+
162+ <a id =" fig:latest-sts-diagram " >
163+
164+ !!! note "** Figure: STS Diagram** "
165+
166+ State transition rules of the ledger specification,
167+ presented as a directed graph; each node represents a transition rule;
168+ an arrow from rule A to rule B indicates that B appears among the
169+ premises of A; a dotted arrow represents a dependency in the sense that
170+ the output of the target node is an input to the source node, either as
171+ part of the source state, the environment or the event ( rules added in
172+ Conway; rules modified in Conway; dotted ellipses represent rules that
173+ are not yet formalized in Agda).
174+
175+ 
172176
173- \begin{itemize}
174- \item
175- \LedgerModText{Chain}{CHAIN} is the top level transition in response to a new
176- block that applies the NEWEPOCH transition when crossing an epoch boundary, and the
177- LEDGERS transition on the list of transactions in the body (\cref{sec: blockchain-layer }).
178- \item
179- \LedgerModText{Epoch}{NEWEPOCH} computes the new state as of the start of a new
180- epoch; includes the previous EPOCH transition (\cref{sec: epoch-boundary }).
181- \item
182- \LedgerModText{Epoch}{EPOCH} computes the new state as of the end of an epoch;
183- includes the ENACT, RATIFY, and SNAP transition rules (\cref{sec: epoch-boundary }).
184- \item
185- \LedgerModText{Ratify}{RATIFY} decides whether a pending governance action has
186- reached the thresholds it needs to be ratified (\cref{sec: ratification }).
187- \item
188- \LedgerModText{Enact}{ENACT} applies the result of a previously ratified
189- governance action, such as triggering a hard fork or updating the protocol
190- parameters (\cref{sec: enactment }).
191- \item
192- \LedgerModText{Epoch}{SNAP} computes new stake distribution snapshots (\cref{sec: epoch-boundary }).
193- \item
194- \LedgerModText{Ledger}{LEDGERS} applies LEDGER repeatedly as needed, for each
195- transaction in a list of transactions (\cref{sec: ledger }).
196- \item
197- \LedgerModText{Ledger}{LEDGER} is the full state update in response to a
198- single transaction; it includes the UTXOW, GOV, and CERTS rules (\cref{sec: ledger }).
199- \item
200- \LedgerModText{Certs}{CERTS} applies CERT repeatedly for each certificate in
201- the transaction (\cref{sec: certificates }).
202- \item
203- \LedgerModText{Certs}{CERT} combines DELEG, POOL, GOVCERT transition rules,
204- as well as some additional rules shared by all three (\cref{sec: certificates }).
205- \item
206- \LedgerModText{Certs}{DELEG} handles registering stake addresses and delegating
207- to a stake pool (\cref{sec: certificates }).
208- \item
209- \LedgerModText{Certs}{GOVCERT} handles registering and delegating to DReps (\cref{sec: certificates }).
210- \item
211- \LedgerModText{Certs}{POOL} handles registering and retiring stake pools (\cref{sec: certificates }).
212- \item
213- \LedgerModText{Gov}{GOV} handles voting and submitting governance proposals (\cref{sec: governance }).
214- \item
215- \LedgerModText{Utxow}{UTXOW} checks that a transaction is witnessed correctly
216- with the appropriate signatures, datums, and scripts; includes the UTXO transition
217- rule (\cref{sec: witnessing }).
218- \item
219- \LedgerModText{Utxo}{UTXO} checks core invariants for an individual transaction
220- to be valid, such as the transaction being balanced, fees being paid, etc; include
221- the UTXOS transition rule (\cref{sec: utxo }).
222- \item
223- \LedgerModText{Utxo}{UTXOS} checks that any relevant scripts needed by the
224- transaction evaluate to true (\cref{sec: utxo }).
225- \end{itemize}
226- \end{NoConway}
177+ </a >
227178
228- \subsection{Reflexive-transitive Closure}
179+ A brief description of each transition rule is provided below, with a
180+ link to an Agda module and reference to a section where the rule is
181+ formally defined.
229182
230- Some state transition rules need to be applied as many times as possible to arrive at
231- a final state. Since we use this pattern multiple times, we define a closure
232- operation which takes a transition rule and applies it as many times as possible .
183+ - [ CHAIN ] [ ] is the top level transition in response to a new block that applies
184+ the NEWEPOCH transition when crossing an epoch boundary, and the
185+ LEDGERS transition on the list of transactions in the body .
233186
234- The closure \RTCI{} of a relation \RTCB{} is defined in \cref{fig: rt-closure }.
235- In the remainder of the text, the closure operation is called \RTC{}.
187+ - [ NEWEPOCH] [ ] computes the new state as of the start of a new epoch; includes the
188+ previous EPOCH transition.
189+
190+ - [ EPOCH] [ ] computes the new state as of the end of an epoch; includes the ENACT,
191+ RATIFY, and SNAP transition rules.
192+
193+ - [ RATIFY] [ ] decides whether a pending governance action has reached the thresholds
194+ it needs to be ratified.
195+
196+ - [ ENACT] [ ] applies the result of a previously ratified governance action, such as
197+ triggering a hard fork or updating the protocol parameters.
198+
199+
200+ - [ SNAP] [ ] computes new stake distribution snapshots.
201+
202+ - [ LEDGERS] [ ] applies LEDGER repeatedly as needed, for each transaction in a list of
203+ transactions.
204+
205+ - [ LEDGER] [ ] is the full state update in response to a single transaction; it
206+ includes the UTXOW, GOV, and CERTS rules.
207+
208+ - [ CERTS] [ ] applies CERT repeatedly for each certificate in the transaction.
209+
210+ - [ CERT] [ ] combines DELEG, POOL, GOVCERT transition rules, as well as some
211+ additional rules shared by all three.
212+
213+ - [ DELEG] [ ] handles registering stake addresses and delegating to a stake pool.
214+
215+ - [ GOVCERT] [ ] handles registering and delegating to DReps.
216+
217+ - [ POOL] [ ] handles registering and retiring stake pools.
218+
219+ - [ GOV] [ ] handles voting and submitting governance proposals.
220+
221+ - [ UTXOW] [ ] checks that a transaction is witnessed correctly with the appropriate
222+ signatures, datums, and scripts; includes the UTXO transition rule.
223+
224+ - [ UTXO] [ ] checks core invariants for an individual transaction to be valid, such
225+ as the transaction being balanced, fees being paid, etc; include the
226+ UTXOS transition rule.
227+
228+ - [ UTXOS] [ ] checks that any relevant scripts needed by the transaction evaluate to true.
229+
230+ ## Reflexive-transitive Closure
231+
232+ Some state transition rules need to be applied as many times as possible
233+ to arrive at a final state. Since we use this pattern multiple times, we
234+ define a closure operation which takes a transition rule and applies it
235+ as many times as possible.
236+
237+ The closure ` RTCI ` {.agdaoperator} of a relation ` RTCB ` {.agdaoperator} is
238+ defined in [ Reflexive transitive closure] ( Ledger.Introduction.md#reflexive-transitive-closure ) . In the
239+ remainder of the text, the closure operation is called
240+ ` RTC ` {.agdafunction}.
241+
242+
243+ ### Reflexive transitive closure
244+
245+
246+ <div class =" agda-hidden-source " >
247+
248+ ``` agda
236249
237- \begin{figure* }[ htb]
238- \caption{Reflexive transitive closure}
239- \begin{AgdaMultiCode}
240- \begin{code}[ hide]
241250module _ (_⊢_⇀⟦_⟧_ : C → S → Sig → S → Type) where
251+ ```
252+
253+ </div >
254+ * Closure type*
255+
256+ ``` agda
242257
243- \end{code}
244- \emph{Closure type}
245- \begin{code}
246258 data _⊢_⇀⟦_⟧*_ : C → S → List Sig → S → Type where
259+ ```
260+ * Closure rules*
261+ ``` agda
247262
248- \end{code}
249- \emph{Closure rules}
250- \begin{code}
251263 RTC-base :
252264 Γ ⊢ s ⇀⟦ [] ⟧* s
253265
@@ -256,10 +268,7 @@ module _ (_⊢_⇀⟦_⟧_ : C → S → Sig → S → Type) where
256268 ∙ Γ ⊢ s' ⇀⟦ sigs ⟧* s''
257269 ───────────────────────────────────────
258270 Γ ⊢ s ⇀⟦ sig ∷ sigs ⟧* s''
259- \end{code}
260- \end{AgdaMultiCode}
261- \label{fig: rt-closure }
262- \end{figure* }
271+ ```
263272
264273\subsection{Computational}
265274
0 commit comments