@@ -49,7 +49,7 @@ what we use to demonstrate problems in following:
4949 * Fracada
5050 * JPG Vesting Contract
5151 * Indigo Protocol
52- * DApp project we participate , audited or otherwise know it codebase
52+ * DApp projects we participated , audited or otherwise know their codebase
5353 * Hydra Auction
5454 * POCRE
5555 * CNS
@@ -61,8 +61,6 @@ what we use to demonstrate problems in following:
6161 * [ Game Model] ( https://github.com/IntersectMBO/plutus-apps/blob/dbafa0ffdc1babcf8e9143ca5a7adde78d021a9a/doc/plutus/tutorials/GameModel.hs )
6262* plutus-usecases
6363
64- @todo #3 : Add more links to specific bugs and code size blowups in existing DApps.
65-
6664## On-chain correctness
6765
6866### Known common vulnerabilities
@@ -82,14 +80,31 @@ taking that burden from developers and auditors.
8280
8381Those problems are similar to previous in that they tend to
8482arise in naive Plutus implementations,
85- if developer was did not make measures to prevent them.
83+ if developer was did not take measures to prevent them.
84+
85+ Plutus forces developers to write TxIn/TxOut constraints from scratch,
86+ leading by subtle bugs from copy-pasting logic or
87+ trying to optimize them by hand.
88+
89+ Examples:
90+
91+ * Security bug in MinSwap audit - 2.2.1.3 Unauthorized Hijacking of Pools Funds
92+ * Non-security bug in MinSwap audit - 2.2.2.2 Batcher Is Not Allowed to Apply Their Own Order
93+
94+ Such constraints naturally lead to conditions
95+ for which more performant implementation should
96+ omit some constraints always following from others.
97+ Such kind of manual SMT solving exercises are
98+ known source for security bugs and complicated code.
8699
87- Almost all transactions which require fungible tokens as input,
100+ One of important cases is maintaining invariants of token value.
101+ TODO - add explanation
102+
103+ Most of transactions which require fungible tokens as input,
88104should not depend from exact UTxO coin-change distribution.
89105
90106Failure to expect that leads to prohibition of correct transactions.
91- On other side too broad constraint might lead to
92- fund stealing.
107+ On other side too broad constraint might lead to fund stealing.
93108
94109Example of bugs:
95110
@@ -114,6 +129,9 @@ Examples:
114129
115130* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/issues/129
116131* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/commit/8152720c43732f8fb74181b7509de503b8371997
132+ * Non-intentionally under-specified behavior in MinSwap audit:
133+ * ` 2.2.2.1 Batchers Can Choose Batching Order `
134+ * Triggered by ` 2.2.4.1 "Reliance on Indexes Into ScriptContexts' txInputs and txOutputs" `
117135* Multiple kind of code complication was observed in CNS audit.
118136* Utilities [ from Indigo] ( https://github.com/IndigoProtocol/indigo-smart-contracts/blob/main/src/Indigo/Utils/Spooky/Helpers.hs )
119137
@@ -179,6 +197,19 @@ Our script stages abstraction cover all those kind of problems.
179197* @todo #3 : document problems with slots in Plutus/Cardano API
180198 * https://github.com/mlabs-haskell/hydra-auction/issues/236
181199
200+ ## Matching off-chain logic
201+
202+ Problem of duplicating logic between on- and off-chain is twofold.
203+ Testing is essentially offchain, thus, you may miss that your onchain code
204+ is not actually enforcing part of Tx provided in tests.
205+
206+ CEM Script is constructing Tx for submission from same specification,
207+ which is used for onchain script. Thus it is much harder to miss constraint
208+ to be checked.
209+
210+ Examples:
211+
212+ * MinSwap audit - 2.2.1.2 LP Tokens Can Be Duplicated
182213
183214## Logic duplication and spec subtleness
184215
@@ -208,6 +239,33 @@ is much less obvious to implement,
208239and out of scope of current Catalyst project,
209240but it is very much possible feature as well.
210241
242+ Examples of diagrams in DApp specifications:
243+
244+ * ...
245+ * ...
246+ * ...
247+
248+ ### On-/Off-chain and spec logic duplication
249+
250+ Writing on-chain contracts manually encodes non-deterministic state machine,
251+ which cannot be used for off-chain transaction construction.
252+ Thus developer need to write them again in different style in off-chain code,
253+ which is tedious and error prone.
254+
255+ They should add checks for all errors possible,
256+ like coins being available and correct script states being present,
257+ to prevent cryptic errors and provide retrying strategies
258+ for possible utxo changes.
259+
260+ Our project encodes scripts in deterministic machine,
261+ containing enough information to construct transaction automatically.
262+ This also gives a way to check for potential on/off-chain logic differences
263+ semi-automatically.
264+
265+ Example:
266+ * MinSwap Audit - 2.2.4.3 Large Refactoring Opportunities
267+ * ` availableVestings ` - пример чего-то подобного для SimpleAuction
268+
211269Examples of this done by hand:
212270
213271* [ State graph for Agora] ( https://github.com/Liqwid-Labs/agora/blob/staging/docs/diagrams/ProposalStateMachine.png )
@@ -241,10 +299,8 @@ Examples of boilerplate:
241299
242300* https://github.com/MELD-labs/cardano-defi-public/tree/eacaa527823031105eba1730f730e1b32f1470bc/lending-index/src/Lending/Index
243301
244- ### Correct off-chain Tx construction logic
302+ Timing ...
245303
246- A lot of on-chain problems, like timing and coin change issues
247- have their counterpart on Tx submission side.
248304
249305@todo #3 : Add more off-chain code duplication examples from existing PABs.
250306 Include problems with coin-selection, tests, retrying and errors.
@@ -302,12 +358,19 @@ and multiple commiters schemes (used in `hydra`).
302358
303359### Atlas
304360
305- Atlas provides (emulate-everything) and overall more humane DX
306- on top of cardano-api. But it has no feature related to goals
361+ Atlas provides more humane DX on top of cardano-api.
362+ But it has no features related to goals
307363(synced-by-construction), (secure-by-construction)
308364and (declarative-spec).
365+ (emulate-everything) is planned, but is not implemented currently.
366+
367+ Atlas includes connectors to Blockfrost and other backends,
368+ which our project lacks.
369+
370+ Also our project has slight differences in API design decisions.
371+ Our monad interfaces is meant to be slightly more modular.
372+ We use much less custom type wrappers, resorting to Plutus types where possible.
309373
310- @todo #3 : Add more specifics on Atlas to docs.
311374
312375## Testing tools
313376
0 commit comments