Skip to content

Commit b7fb902

Browse files
authored
Merge pull request #46 from cardano-scaling/zliu41/serialize
Write about Plutus script serialization
2 parents 418465f + 36130bc commit b7fb902

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [Syntax](plutus/syntax.md)
2727
- [Builtin Types and Functions](plutus/builtin.md)
2828
- [The CEK Machine](plutus/cek.md)
29+
- [Serialization](plutus/serialization.md)
2930
- [Client interfaces](client/README.md)
3031
- [NTC](client/node-to-client/README.md)
3132
- [Handshake]()

src/plutus/serialization.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Serialization
2+
3+
## Serializing Data Objects Using the CBOR Format
4+
5+
`Data` is a Plutus Core built-in type.
6+
It is used for on-chain data interchange, such as arguments to Plutus validators.
7+
The following is the Haskell definition of `Data`:
8+
9+
```haskell
10+
data Data =
11+
Constr Integer [Data]
12+
| Map [(Data, Data)]
13+
| List [Data]
14+
| I Integer
15+
| B ByteString
16+
```
17+
18+
Because blockchains store and transmit data in binary format, a `Data` object must be serialized into bytes whenever it is included in a transaction, or stored in a UTxO.
19+
The serialization method must be deterministic, compact and stable.
20+
21+
Cardano uses CBOR extensively as a serialization format, so CBOR is also used for `Data` objects.
22+
All Cardano node implementations must agree on how `Data` objects are serialized.
23+
The serialization method used by the Haskell node is described in the Plutus Core spec, Appendix B.
24+
25+
## Serializing Plutus Scripts Using the Flat Format
26+
27+
Plutus scripts must also be serialized into a binary format so that they can be stored, transmitted and hashed.
28+
29+
Plutus scripts are serialized using the `flat` format.
30+
`flat` is much more compact and faster than CBOR for serializing programs due to avoiding unnecessary metadata, resulting in a smaller script size and faster serialization - important for on-chain storage and transaction fees.
31+
32+
The `flat`-serialized script is then serialized into CBOR, based on which script hashes are calculated.
33+
34+
All Cardano node implementations must agree on how Plutus scripts are serialized.
35+
The serialization method used by the Haskell node is described in the Plutus Core script, Appendix C.

0 commit comments

Comments
 (0)