Skip to content

Commit ceb87a8

Browse files
authored
update smart contract design patterns & smart contract security vulnerabilities (#1689)
* smart contract security documentation with new sections * design patterns * consistent cardano-cli commands era flags * remove duplicate link * cardano-cli era flags update * refactor testnet docs and add redirects * infrastructure docs refactor * refactor core concepts & get started * fix broken testnet links * revert secure-workflow.md to staging to avoid merge conflict with #1690 * update redirects for additional path to running cardano node docs
1 parent 6880bed commit ceb87a8

File tree

97 files changed

+2020
-2506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2020
-2506
lines changed

docs/build/integrate/overview.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ image: /img/og/og-developer-portal.png
1010
![Integrate Cardano](/img/card-integrate-cardano-title.svg)
1111

1212
## Introduction
13-
Here we show you how to integrate Cardano into existing websites and services.
13+
14+
Here we show you how to integrate Cardano into existing websites and services.
1415

1516
## Integration Components
17+
1618
- [Overview](/docs/get-started/infrastructure/node/cardano-components) of the different Cardano components.
1719
- [cardano-node](https://github.com/IntersectMBO/cardano-node) is the top level for the node and aggregates the other components from other packages: consensus, ledger and networking, with configuration, CLI, logging and monitoring.
1820
- [cardano-wallet](https://github.com/cardano-foundation/cardano-wallet) helps you manage ada. You can use it to send and receive payments on the Cardano blockchain via a http and cli interface.
19-
- [cardano-db-sync](https://github.com/IntersectMBO/cardano-db-sync) follows the Cardano chain and takes information from the chain and an internally maintained copy of ledger state. Data is then extracted from the chain and inserted into a PostgreSQL database.
21+
- [cardano-db-sync](https://github.com/IntersectMBO/cardano-db-sync) follows the Cardano chain and takes information from the chain and an internally maintained copy of ledger state. Data is then extracted from the chain and inserted into a PostgreSQL database.
2022
- [cardano-graphql](https://github.com/cardano-foundation/cardano-graphql) a cross-platform, typed, and queryable API for Cardano.
21-
- [cardano-rosetta](https://github.com/cardano-foundation/cardano-rosetta-java) a multi-platform implementation of [Rosetta](https://www.rosetta-api.org) for Cardano, targeting the version defined in the [API docs](https://cardano-foundation.github.io/cardano-rosetta-java/api).
23+
- [cardano-rosetta](https://github.com/cardano-foundation/cardano-rosetta-java) a multi-platform implementation of [Rosetta](https://www.rosetta-api.org) for Cardano, targeting the version defined in the [API docs](https://cardano-foundation.github.io/cardano-rosetta-java/api).
2224
- [cardano-addresses](https://github.com/IntersectMBO/cardano-addresses) provides mnemonic (backup phrase) creation, and conversion of a mnemonic to seed for wallet restoration, and address derivation functionalities.
2325

2426
## Tutorials
27+
2528
- [Listening for ada payments](payments/listening-for-payments/overview) - learn different approaches to detect and confirm ada payments in your applications.
26-
- [Testnet Faucet](/docs/get-started/networks/testnets/testnet-faucet) - a service that provides test ada (tAda) to users of the Cardano testnets.
29+
- [Testnet Faucet](/docs/get-started/networks/testnets) - a service that provides test ada (tAda) to users of the Cardano testnets.
2730
- [Sample queries](https://iohk.zendesk.com/hc/en-us/articles/4402395914009-Sample-cardano-rosetta-queries) for cardano-rosetta.
2831
- [Sample queries](https://iohk.zendesk.com/hc/en-us/articles/900000906566-Sample-cardano-graphql-queries) for cardano-graphql.
2932

docs/build/integrate/payments/listening-for-payments/cardano-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For a higher-level approach with less infrastructure, check out the [Point of Sa
1919
:::note
2020
This guide assumes that you have basic understanding of `cardano-cli`, how to use it and that you have installed it into your system. Otherwise we recommend reading [Installing cardano-node](/docs/get-started/infrastructure/node/installing-cardano-node), [Running cardano-node](/docs/get-started/infrastructure/node/running-cardano.md) and [Get started with Cardano CLI](/docs/get-started/infrastructure/cardano-cli/basic-operations/get-started) guides first.
2121

22-
This guide also assumes that you have `cardano-node` running in the background and connected to a [testnet network](/docs/get-started/networks/testnets/overview).
22+
This guide also assumes that you have `cardano-node` running in the background and connected to a [testnet network](/docs/get-started/networks/testnets).
2323
:::
2424

2525
## Use case

docs/build/integrate/payments/listening-for-payments/cardano-wallet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For a simpler approach without running any blockchain infrastructure, check out
2020

2121
This guide assumes that you have basic understanding of `cardano-wallet`, how to use it and that you have installed it into your system. Otherwise we recommend reading [Installing cardano-node](/docs/get-started/infrastructure/node/installing-cardano-node), [Running cardano-node](/docs/get-started/infrastructure/node/running-cardano.md), [Installing cardano-wallet](/docs/get-started/infrastructure/cardano-wallet/cardano-wallet) and [Using cardano-wallet](/docs/get-started/infrastructure/cardano-wallet/using-cardano-wallet) guides first.
2222

23-
This guide also assumes that you have `cardano-node` and `cardano-wallet` running in the background and connected to a [testnet network](/docs/get-started/networks/testnets/overview).
23+
This guide also assumes that you have `cardano-node` and `cardano-wallet` running in the background and connected to a [testnet network](/docs/get-started/networks/testnets).
2424

2525
:::
2626

@@ -203,7 +203,7 @@ var resp = await http.PostAsJsonAsync("wallets", new {
203203

204204
#### Get unused wallet address to receive some payments
205205

206-
We will get a **wallet address** to show to the customers and for them to send payments to the wallet. In this case we can use the address to request some `tAda` from the [Cardano Testnet Faucet](/docs/get-started/networks/testnets/testnet-faucet) and simulate a payment:
206+
We will get a **wallet address** to show to the customers and for them to send payments to the wallet. In this case we can use the address to request some `tAda` from the [Cardano Testnet Faucet](/docs/get-started/networks/testnets) and simulate a payment:
207207

208208
<Tabs
209209
defaultValue="js"
@@ -592,7 +592,7 @@ The code is telling us that our current wallet has received a total of `0 lovela
592592

593593
What we can do to simulate a successful payment is to send at least `1,000,000 lovelace` into the **wallet address** that we have just generated for this project. We show how you can get the **wallet address** via code in the examples above.
594594

595-
Now simply send at least `1,000,000 lovelace` to this **wallet address** or request some `test ada` funds from the [Cardano Testnet Faucet](/docs/get-started/networks/testnets/testnet-faucet). Once complete, we can now run the code again and we should see a successful result this time.
595+
Now simply send at least `1,000,000 lovelace` to this **wallet address** or request some `test ada` funds from the [Cardano Testnet Faucet](/docs/get-started/networks/testnets). Once complete, we can now run the code again and we should see a successful result this time.
596596

597597
<Tabs
598598
defaultValue="js"

docs/build/native-tokens/minting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export CARDANO_NODE_SOCKET_PATH="$HOME/TESTNET_NODE/socket/node.socket"
9898
You need to adjust the path on your setup and your socket path accordingly.
9999

100100
### Improve readability
101-
Since we've already answered all of the questions above, we will set variables on our terminal/bash to make readability a bit easier. First, we will specify a [testnet](/docs/get-started/networks/testnets/overview), either Pre-production:
101+
Since we've already answered all of the questions above, we will set variables on our terminal/bash to make readability a bit easier. First, we will specify a [testnet](/docs/get-started/networks/testnets), either Pre-production:
102102
```bash
103103
testnet="--testnet-magic 1"
104104
```
@@ -185,7 +185,7 @@ address=$(cat payment.addr)
185185
Submitting transactions always require you to pay a fee. Sending native assets also requires sending at least 1 ada.
186186
So make sure the address you are going to use as the input for the minting transaction has sufficient funds.
187187

188-
For **testnets**, you can request funds through the [Testnet Faucet](/docs/get-started/networks/testnets/testnet-faucet).
188+
For **testnets**, you can request funds through the [Testnet Faucet](/docs/get-started/networks/testnets).
189189

190190
### Export protocol parameters
191191

docs/build/smart-contracts/advanced/design-patterns/enum-redeemers.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

docs/build/smart-contracts/advanced/design-patterns/transaction-level-validation/stake-validators/merkelized-validators.md renamed to docs/build/smart-contracts/advanced/design-patterns/merkelized-validator.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
id: merkelized-validators
3-
title: Merkelized Validators
4-
sidebar_label: Merkelized Validators
5-
description: Circumvent validator script size limitations.
2+
id: merkelized-validator
3+
title: Merkelized Validator
4+
sidebar_label: Merkelized Validator
5+
description: Delegate logic to external withdrawal scripts to stay within size limits
66
---
77

88
There are very tight execution budget constraints imposed on Plutus script evaluation; this, in combination with the fact that a higher execution budget
@@ -98,6 +98,42 @@ This is useful because with reference scripts this essentially gives us the abil
9898
9999
Consider a batching architecture, with a very large `processOrders` function. Normally it would not be feasible to perform recursion unrolling / inlining optimizations with such a function since it would quickly exceed the max script size limit; however, with this design pattern we simply move `processOrders` into its own validator script which we can fill with 16kb of loop unrolling and other powerful optimizations which increase script size in order to reduce ExUnits. We provide this new script as a reference script when executing our main validator. Then in our main validator we verify that the `processOrders` validator was executed with the expected redeemer (`inputState` must match the arguments we want to pass to `processOrders`) after which have access to the result of the optimized `processOrders` function applied to our inputs.
100100
101+
## Aiken Implementation
102+
103+
Since transaction size is limited in Cardano, some validators benefit from a solution which allows them to delegate parts of their logics. This becomes more prominent in cases where such logics can greatly benefit from optimization solutions that trade computation resources for script sizes (e.g. table lookups can take up more space so that costly computations can be averted).
104+
105+
This design pattern offers an interface for off-loading such logics into an external withdrawal script, so that the size of the validator itself can stay within the limits of Cardano.
106+
101107
:::note
102-
You can find a sample implementation of a merkelized validator written in Aiken in this[repository](https://github.com/keyan-m/aiken-delegation-sample/blob/main/validators/main-contract.ak).
108+
Be aware that total size of reference scripts is currently limited to 200KiB (204800 bytes), and they also impose additional fees in an exponential manner. See [here](https://github.com/IntersectMBO/cardano-ledger/issues/3952) and [here](https://github.com/CardanoSolutions/ogmios/releases/tag/v6.5.0) for more info.
103109
:::
110+
111+
### Using the Library
112+
113+
The exposed `delegated_compute` function from `merkelized_validator` expects 4 arguments:
114+
115+
1. The arbitrary input value for the underlying computation logic
116+
2. The hash of the withdrawal validator that performs the computation
117+
3. Validation function for coercing a `Data` to the format of the input expected by the staking script's computation
118+
4. The `Pairs` of all redeemers within the current script context
119+
120+
This function expects to find the given stake validator in the `redeemers` list, such that its redeemer is of type `WithdrawRedeemerIO` (which carries the generic input argument(s) and the expected output(s)), makes sure provided input(s) match the ones given to the validator through its redeemer, and returns the output(s) (which are carried inside the withdrawal redeemer) so that you can safely use them.
121+
122+
### Withdrawal Script (Computation Logic)
123+
124+
For defining a withdrawal logic that carries out the computation, use the exposed `withdraw_io` function. It expects 2 arguments:
125+
126+
1. The computation itself. It has to take an argument of type `a`, and return a value of type `b`
127+
2. A redeemer of type `WithdrawRedeemerIO<a, b>`. Note that `a` is the type of input argument(s), and `b` is the type of output argument(s)
128+
129+
It validates that the given input(s) and output(s) match correctly with the provided computation logic.
130+
131+
There are also `WithdrawRedeemer<a>`, `withdraw` and `delegated_validation` variants which can be used for validations that don't return any outputs.
132+
133+
## Example Code
134+
135+
Full working example: [merkelized-validator.ak](https://github.com/Anastasia-Labs/aiken-design-patterns/blob/main/validators/examples/merkelized-validator.ak)
136+
137+
Library implementation: [merkelized_validator module](https://github.com/Anastasia-Labs/aiken-design-patterns/blob/main/lib/aiken-design-patterns/merkelized-validator.ak)
138+
139+
Additional sample: [aiken-delegation-sample](https://github.com/keyan-m/aiken-delegation-sample/blob/main/validators/main-contract.ak)

docs/build/smart-contracts/advanced/design-patterns/normalization-techniques/txinfomint-normalization.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)