@@ -52,7 +52,7 @@ what we use to demonstrate problems in following:
5252 * Fracada
5353 * JPG Vesting Contract
5454 * Indigo Protocol
55- * DApp project we participate , audited or otherwise know it codebase
55+ * DApp projects we participated , audited or otherwise know their codebase
5656 * Hydra Auction
5757 * POCRE
5858 * CNS
@@ -64,8 +64,6 @@ what we use to demonstrate problems in following:
6464 * [ Game Model] ( https://github.com/IntersectMBO/plutus-apps/blob/dbafa0ffdc1babcf8e9143ca5a7adde78d021a9a/doc/plutus/tutorials/GameModel.hs )
6565* plutus-usecases
6666
67- @todo #3 : Add more links to specific bugs and code size blowups in existing DApps.
68-
6967## On-chain correctness
7068
7169### Known common vulnerabilities
@@ -85,14 +83,31 @@ taking that burden from developers and auditors.
8583
8684Those problems are similar to previous in that they tend to
8785arise in naive Plutus implementations,
88- if developer was did not make measures to prevent them.
86+ if developer was did not take measures to prevent them.
87+
88+ Plutus forces developers to write TxIn/TxOut constraints from scratch,
89+ leading by subtle bugs from copy-pasting logic or
90+ trying to optimize them by hand.
91+
92+ Examples:
93+
94+ * Security bug in MinSwap audit - 2.2.1.3 Unauthorized Hijacking of Pools Funds
95+ * Non-security bug in MinSwap audit - 2.2.2.2 Batcher Is Not Allowed to Apply Their Own Order
96+
97+ Such constraints naturally lead to conditions
98+ for which more performant implementation should
99+ omit some constraints always following from others.
100+ Such kind of manual SMT solving exercises are
101+ known source for security bugs and complicated code.
89102
90- Almost all transactions which require fungible tokens as input,
103+ One of important cases is maintaining invariants of token value.
104+ TODO - add explanation
105+
106+ Most of transactions which require fungible tokens as input,
91107should not depend from exact UTxO coin-change distribution.
92108
93109Failure to expect that leads to prohibition of correct transactions.
94- On other side too broad constraint might lead to
95- fund stealing.
110+ On other side too broad constraint might lead to fund stealing.
96111
97112Example of bugs:
98113
@@ -117,6 +132,9 @@ Examples:
117132
118133* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/issues/129
119134* Non-security bug: https://github.com/mlabs-haskell/hydra-auction/commit/8152720c43732f8fb74181b7509de503b8371997
135+ * Non-intentionally under-specified behavior in MinSwap audit:
136+ * ` 2.2.2.1 Batchers Can Choose Batching Order `
137+ * Triggered by ` 2.2.4.1 "Reliance on Indexes Into ScriptContexts' txInputs and txOutputs" `
120138* Multiple kind of code complication was observed in CNS audit.
121139* Utilities [ from Indigo] ( https://github.com/IndigoProtocol/indigo-smart-contracts/blob/main/src/Indigo/Utils/Spooky/Helpers.hs )
122140
@@ -182,6 +200,19 @@ Our script stages abstraction cover all those kind of problems.
182200* @todo #3 : document problems with slots in Plutus/Cardano API
183201 * https://github.com/mlabs-haskell/hydra-auction/issues/236
184202
203+ ## Matching off-chain logic
204+
205+ Problem of duplicating logic between on- and off-chain is twofold.
206+ Testing is essentially offchain, thus, you may miss that your onchain code
207+ is not actually enforcing part of Tx provided in tests.
208+
209+ CEM Script is constructing Tx for submission from same specification,
210+ which is used for onchain script. Thus it is much harder to miss constraint
211+ to be checked.
212+
213+ Examples:
214+
215+ * MinSwap audit - 2.2.1.2 LP Tokens Can Be Duplicated
185216
186217## Logic duplication and spec subtleness
187218
@@ -211,6 +242,33 @@ is much less obvious to implement,
211242and out of scope of current Catalyst project,
212243but it is very much possible feature as well.
213244
245+ Examples of diagrams in DApp specifications:
246+
247+ * ...
248+ * ...
249+ * ...
250+
251+ ### On-/Off-chain and spec logic duplication
252+
253+ Writing on-chain contracts manually encodes non-deterministic state machine,
254+ which cannot be used for off-chain transaction construction.
255+ Thus developer need to write them again in different style in off-chain code,
256+ which is tedious and error prone.
257+
258+ They should add checks for all errors possible,
259+ like coins being available and correct script states being present,
260+ to prevent cryptic errors and provide retrying strategies
261+ for possible utxo changes.
262+
263+ Our project encodes scripts in deterministic machine,
264+ containing enough information to construct transaction automatically.
265+ This also gives a way to check for potential on/off-chain logic differences
266+ semi-automatically.
267+
268+ Example:
269+ * MinSwap Audit - 2.2.4.3 Large Refactoring Opportunities
270+ * ` availableVestings ` - пример чего-то подобного для SimpleAuction
271+
214272Examples of this done by hand:
215273
216274* [ State graph for Agora] ( https://github.com/Liqwid-Labs/agora/blob/staging/docs/diagrams/ProposalStateMachine.png )
@@ -244,10 +302,8 @@ Examples of boilerplate:
244302
245303* https://github.com/MELD-labs/cardano-defi-public/tree/eacaa527823031105eba1730f730e1b32f1470bc/lending-index/src/Lending/Index
246304
247- ### Correct off-chain Tx construction logic
305+ Timing ...
248306
249- A lot of on-chain problems, like timing and coin change issues
250- have their counterpart on Tx submission side.
251307
252308@todo #3 : Add more off-chain code duplication examples from existing PABs.
253309 Include problems with coin-selection, tests, retrying and errors.
@@ -305,12 +361,19 @@ and multiple commiters schemes (used in `hydra`).
305361
306362### Atlas
307363
308- Atlas provides (emulate-everything) and overall more humane DX
309- on top of cardano-api. But it has no feature related to goals
364+ Atlas provides more humane DX on top of cardano-api.
365+ But it has no features related to goals
310366(synced-by-construction), (secure-by-construction)
311367and (declarative-spec).
368+ (emulate-everything) is planned, but is not implemented currently.
369+
370+ Atlas includes connectors to Blockfrost and other backends,
371+ which our project lacks.
372+
373+ Also our project has slight differences in API design decisions.
374+ Our monad interfaces is meant to be slightly more modular.
375+ We use much less custom type wrappers, resorting to Plutus types where possible.
312376
313- @todo #3 : Add more specifics on Atlas to docs.
314377
315378## Testing tools
316379
0 commit comments