@@ -48,16 +48,14 @@ what we use to demonstrate problems in following:
4848 * Fracada
4949 * JPG Vesting Contract
5050 * Indigo Protocol
51- * DApp project we participate , audited or otherwise know it codebase
51+ * DApp projects we participated , audited or otherwise know their codebase
5252 * Hydra Auction
5353 * POCRE
5454 * CNS
5555 * Hydra
5656* Plutonomicon patterns
5757* plutus-usecases
5858
59- @todo #3 : Add more links to specific bugs and code size blowups in existing DApps.
60-
6159## On-chain correctness
6260
6361### Known common vulnerabilities
@@ -77,27 +75,36 @@ taking that burden from developers and auditors.
7775
7876Those problems are similar to previous in that they tend to
7977arise in naive Plutus implementations,
80- if developer was did not make measures to prevent them.
78+ if developer was did not take measures to prevent them.
79+
80+ Plutus forces developers to write TxIn/TxOut constraints from scratch,
81+ leading by subtle bugs from copy-pasting logic or
82+ trying to optimize them by hand.
83+
84+ Examples:
85+
86+ * Security bug in MinSwap audit - 2.2.1.3 Unauthorized Hijacking of Pools Funds
87+ * Non-security bug in MinSwap audit - 2.2.2.2 Batcher Is Not Allowed to Apply Their Own Order
88+
89+ Such constraints naturally lead to conditions
90+ for which more performant implementation should
91+ omit some constraints always following from others.
92+ Such kind of manual SMT solving exercises are
93+ known source for security bugs and complicated code.
8194
82- Almost all transactions which require fungible tokens as input,
95+ One of important cases is maintaining invariants of token value.
96+ TODO - add explanation
97+
98+ Most of transactions which require fungible tokens as input,
8399should not depend from exact UTxO coin-change distribution.
84100
85101Failure to expect that leads to prohibition of correct transactions.
86- On other side too broad constraint might lead to
87- fund stealing.
102+ On other side too broad constraint might lead to fund stealing.
88103
89104Example of bugs:
90105
91106* https://github.com/mlabs-haskell/hydra-auction/issues/146
92107
93- Another important case is maintaining invariants
94- of token value or immutable UTxOs.
95- Such kind of constraints naturally lead to script
96- for which more performant implementation should
97- eliminate some constraint following from others.
98- Such kind of manual SMT solving exercises are
99- known source for security bugs and complicated code.
100-
101108Making Plutus contract invariant to ` TxIn ` ordering
102109and participation in multi-script scenarios lead to
103110similar kind of complications.
@@ -106,6 +113,9 @@ Examples:
106113
107114* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/issues/129
108115* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/commit/8152720c43732f8fb74181b7509de503b8371997
116+ * Non-intentionally under-specified behavior in MinSwap audit:
117+ * ` 2.2.2.1 Batchers Can Choose Batching Order `
118+ * Triggered by ` 2.2.4.1 "Reliance on Indexes Into ScriptContexts' txInputs and txOutputs" `
109119* Multiple kind of code complication was observed in CNS audit.
110120
111121### Single script safety and liveliness
@@ -169,6 +179,19 @@ Our script stages abstraction cover all those kind of problems.
169179* @todo #3 : document problems with slots in Plutus/Cardano API
170180 * https://github.com/mlabs-haskell/hydra-auction/issues/236
171181
182+ ## Matching off-chain logic
183+
184+ Problem of duplicating logic between on- and off-chain is twofold.
185+ Testing is essentially offchain, thus, you may miss that your onchain code
186+ is not actually enforcing part of Tx provided in tests.
187+
188+ CEM Script is constructing Tx for submission from same specification,
189+ which is used for onchain script. Thus it is much harder to miss constraint
190+ to be checked.
191+
192+ Examples:
193+
194+ * MinSwap audit - 2.2.1.2 LP Tokens Can Be Duplicated
172195
173196## Logic duplication and spec subtleness
174197
@@ -195,15 +218,38 @@ is much less obvious to implement,
195218and out of scope of current Catalyst project,
196219but it is very much possible feature as well.
197220
198- ### On-/Off-chain and spec code duplication
221+ Examples of diagrams in DApp specifications:
222+
223+ * ...
224+ * ...
225+ * ...
226+
227+ ### On-/Off-chain and spec logic duplication
228+
229+ Writing on-chain contracts manually encodes non-deterministic state machine,
230+ which cannot be used for off-chain transaction construction.
231+ Thus developer need to write them again in different style in off-chain code,
232+ which is tedious and error prone.
233+
234+ They should add checks for all errors possible,
235+ like coins being available and correct script states being present,
236+ to prevent cryptic errors and provide retrying strategies
237+ for possible utxo changes.
238+
239+ Our project encodes scripts in deterministic machine,
240+ containing enough information to construct transaction automatically.
241+ This also gives a way to check for potential on/off-chain logic differences
242+ semi-automatically.
243+
244+ Example:
245+ * MinSwap Audit - 2.2.4.3 Large Refactoring Opportunities
246+ * ` availableVestings ` - пример чего-то подобного для SimpleAuction
199247
200248@todo #3 : Add more off-chain code duplication examples from existing PABs.
201249 Include problems with querying coin-selection, tests, retrying and errors.
202250
203- ### Correct off-chain Tx construction logic
251+ Timing ...
204252
205- A lot of on-chain problems, like timing and coin change issues
206- have their counterpart on Tx submission side.
207253
208254### Common backend features
209255
@@ -274,12 +320,19 @@ and multiple commiters schemes (used in `hydra`).
274320
275321### Atlas
276322
277- Atlas provides (emulate-everything) and overall more humane DX
278- on top of cardano-api. But it has no feature related to goals
323+ Atlas provides more humane DX on top of cardano-api.
324+ But it has no features related to goals
279325(synced-by-construction), (secure-by-construction)
280326and (declarative-spec).
327+ (emulate-everything) is planned, but is not implemented currently.
328+
329+ Atlas includes connectors to Blockfrost and other backends,
330+ which our project lacks.
331+
332+ Also our project has slight differences in API design decisions.
333+ Our monad interfaces is meant to be slightly more modular.
334+ We use much less custom type wrappers, resorting to Plutus types where possible.
281335
282- @todo #3 : Add more specifics on Atlas to docs.
283336
284337## Testing tools
285338
0 commit comments